600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > java程序设计蜘蛛纸牌_JAVA蜘蛛纸牌

java程序设计蜘蛛纸牌_JAVA蜘蛛纸牌

时间:2021-10-18 06:03:45

相关推荐

java程序设计蜘蛛纸牌_JAVA蜘蛛纸牌

展开全部

我们做作业,做了个扑克牌的游戏,不过不是蜘蛛牌,没有添加出牌规32313133353236313431303231363533e58685e5aeb931333236383562则算法的。发给你,你自己看看。。纸牌要自己下,把名字改成0--51的数字,背面名字改成rear,横向背面改成rearheng.jpg

package com;

import java.awt.Color;

import java.awt.Container;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.MouseEvent;

import java.awt.event.MouseListener;

import java.util.HashSet;

import java.util.Iterator;

import java.util.Set;

import javax.swing.ImageIcon;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

public class puke implements MouseListener,ActionListener{

public JFrame frame=new JFrame("扑克牌发牌");

public JButton button=new JButton("Start");

public JPanel pbutton=new JPanel();

public JPanel north=new JPanel();

public JPanel west=new JPanel();

public JPanel south=new JPanel();

public JPanel east=new JPanel();

public JPanel middle=new JPanel();

public Container container=frame.getContentPane();

public static JLabel[] l=new JLabel[52];

public static JLabel[] ll =new JLabel[52];

@SuppressWarnings("unchecked")

public static Set set=new HashSet();

public static JLabel[] l1=new JLabel[13];

public static JLabel[] l2 =new JLabel[13];

public static JLabel[] l3 =new JLabel[13];

public static JLabel[] l4 =new JLabel[13];

public static JLabel[] ll1 =new JLabel[13];

public static JLabel[] ll2 =new JLabel[13];

public static JLabel[] ll3 =new JLabel[13];

public static JLabel[] ll4=new JLabel[13];

boolean gstar=false;

int nn=ll.length;

int n=l.length;

int s=0;

int x=0,y=0;

@SuppressWarnings("unchecked")

public puke(){

frame.setBounds(0, 0, 1000, 750);

container.setLayout(null);

north.setLayout(null);

west.setLayout(null);

south.setLayout(null);

east.setLayout(null);

north.setBounds(200, 0, 600, 200);

north.setBackground(Color.GREEN);

west.setBounds(0,200,200,350);

west.setBackground(Color.RED);

south.setBounds(200,550,600,200);

south.setBackground(Color.PINK);

east.setBounds(800, 200, 200, 350);

east.setBackground(Color.BLUE);

pbutton.setBounds(420, 420,100, 40);

middle.setBounds(200, 200, 600, 400);

middle.setBackground(Color.YELLOW);

for(int i=0;i

l[i]=new JLabel(new ImageIcon("src/com/rear.jpg"));

l[i].setBounds(350+x,270,71,96);

container.add(l[i]);

x+=5;

}

for(int i=0;i

ll[i]=new JLabel(new ImageIcon("src/com/"+i+".jpg"));

set.add(ll[i]);

}

button.addActionListener(this);

pbutton.add(button);

container.add(north);

container.add(west);

container.add(south);

container.add(east);

container.add(pbutton);

frame.setVisible(true);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

compare();

}

@SuppressWarnings({ "unchecked", "unchecked" })

public void play()//分发正面52张牌

{

Iterator it = set.iterator();

while(it.hasNext()){

for(int i=0;i<13;i++){

if(nn%4==0){

ll1[i]=(JLabel) it.next();

nn--;}

if(nn%4==3){

ll2[i]=(JLabel) it.next();

nn--;}

if(nn%4==2){

ll3[i]=(JLabel) it.next();

nn--;}

if(nn%4==1){

ll4[i]=(JLabel) it.next();

nn--;}

}

}

}

public void move()//完成发牌,每位玩家得到13张牌

{

play();

int i;

while(n!=0){

for(i=0;i<13;i++){

if(s<52){

if(n%4==0){

l1[i]=l[s];

l1[i].setBounds(-120+x, 70, 71, 96);

north.add(l1[i]);

try {

Thread.sleep(3);

} catch (InterruptedException e) {

e.printStackTrace();

}

x+=10;

s++;

n--;

continue;

}

if(n%4==3){

l[s].setIcon(new ImageIcon("src/com/rearheng.jpg"));

l2[i]=l[s];

l2[i].setBounds(70, 20+y,96,71);

west.add(l2[i]);

try {

Thread.sleep(3);

} catch (InterruptedException e) {

e.printStackTrace();

}

y+=10;

s++;

n--;

continue;

}

if(n%4==2){

l[s].setIcon(null);

l3[i]=ll3[i];

l3[i].setBounds(640-x, 30, 71, 96);

l3[i].addMouseListener(this);

south.add(l3[i]);

try {

Thread.sleep(3);

} catch (InterruptedException e) {

e.printStackTrace();

}

x+=10;

s++;

n--;

continue;

}

if(n%4==1){

l[s].setIcon(new ImageIcon("src/com/rearheng.jpg"));

l4[i]=l[s];

l4[i].setBounds(30,260-y,96,71);

east.add(l4[i]);

try {

Thread.sleep(3);

} catch (InterruptedException e) {

e.printStackTrace();

}

y+=10;

s++;

n--;

continue;

}

}

}

}

button.setVisible(false);

pbutton.remove(button);

container.remove(pbutton);

container.add(middle);

frame.repaint();

}

public void mouseClicked(MouseEvent e)//点击鼠标出牌

{

for(int i=0;i<13;i++){

if(gstar){

middle.remove(l3[i]);

middle.remove(ll1[i]);

middle.remove(ll2[i]);

middle.remove(ll4[i]);

if(e.getSource()==l3[i]){

north.remove(l1[i]);

west.remove(l2[i]);

east.remove(l4[i]);

south.remove(l3[i]);

middle.add(l3[i]);

middle.add(ll1[i]);

middle.add(ll2[i]);

middle.add(ll4[i]);

l3[i].setBounds(l3[i].getBounds().x, 200, 71, 100);

ll1[i].setBounds(250, 50, 71, 96);

ll2[i].setBounds(150, 150, 71, 96);

ll3[i].setBounds(250, 200, 71, 96);

ll4[i].setBounds(350, 150, 71, 96);

frame.repaint();

}

}

}

}

public void mouseEntered(MouseEvent e) //选择要出的牌

{

for(int i=0;i<13;i++){

if(gstar){

if(e.getSource()==l3[i]){

l3[i].setBounds(l3[i].getBounds().x, l3[i].getBounds().y-20, 71, 96);

}

}

}

}

public void mouseExited(MouseEvent e) {

for(int i=0;i<13;i++){

if(gstar){

if(e.getSource()==l3[i]){

l3[i].setBounds(l3[i].getBounds().x,l3[i].getBounds().y+20, 71, 96);

}}}

}

public puke getthis(){

return this;

}

public void mousePressed(MouseEvent e) {

}

public void mouseReleased(MouseEvent e) {

}

public static void main(String[]args){

new puke();

}

public class TestThread extends Thread{

private puke g=null;

public TestThread(puke g){

this.g=g;

}

public void run() {

while(true){

g.move();

try {

Thread.sleep(1000);

} catch (InterruptedException e) {

e.printStackTrace();

}

}

}

}

public void actionPerformed(ActionEvent e) //点击按钮事件

{

if(e.getSource()==button){

gstar=true;

TestThread t= new TestThread(this);

t.start();

}

}

@SuppressWarnings("unchecked")

public int compare(){

JLabel[] lab=new JLabel[ll.length];

String[] str=new String[ll.length];

set.toArray(lab);

for(int l=0;l

str[l]=lab[l].getIcon().toString();

System.out.println(str[l]);

}

return n;

}

}

本回答由提问者推荐

已赞过

已踩过<

你对这个回答的评价是?

评论

收起

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。