编程求助
时间:2008-08-27 12:01:40
来源:论坛整理 作者: 编辑:chinaitzhe
本人所作的部分代码如下,希望对高人更好的指点有所帮助:
import java.awt.*;
import javax.swing.*;
public class card extends JLabel
{
private String name; //牌名称
public card(String name)
{
super();
this.name = name;
this.setIcon(new ImageIcon("images/rear.gif"));
this.setSize(71, 96);
setVisible(true);
}
public void turnFront()
{
this.setIcon(new ImageIcon("images/" name ".gif"));
}
public int getCardValue() //返回牌的值
{
return Integer.parseInt(name.substring(2));
}
public String getName()
{
return name;
}
}
public class initCard
{
private card [] allCards, lastCards;
private card playerCards[][]=new card[3][20];
private int[] cardsNo={17, 17, 17};
public void initCards()//初始化牌数
{
allCards=new card [54];
for(int i=1;i <=4;i )
{
for(int j=3;j <=15;j )
{
allCards[(i-1)*13 j-1]=new card(i "-" j);
}
}
allCards[52] = new card("g-16");//设置大小王
allCards[53] = new card("g-17");
randomCards();
}
public void randomCards()//打乱原来初始化的牌!
{
card temp;
for(int i=0;i <54;i )
{
int x = (int) (Math.random() * 54);
int y = (int) (Math.random() * 54);
temp = allCards[x];
allCards[x] = allCards[y];
allCards[y] = temp;
}
}
public void dealCards()//给每位玩家发牌,前三张牌预留,后面要调用线程客户端发牌
{
randomCards();
lastCards = new card[3];
for(int i = 0; i < 3; i )
lastCards[i] = allCards[i];
for(int i = 0; i < 3; i )
{
for(int j = 0; j < 17; j )
{
playerCards[i][j] = allCards[i * 17 j 3];
}
}
}
}
本人考虑使用对象流,程序分为两个客户端,一个服务器。服务器既要参与打牌,又要负责发牌。不知这样设计是否合理?而且其中涉及到的线程很多,不知该如何设计?
网友回复:设计应该没有问题啊。
1,服务器 发牌应该通过单独的线程处理。
2,服务器和客户端大排都要通过单独的线程处理。
总的一条就是要保证不要阻塞主线程。而影响窗体的 重绘。
关键字:
下一篇:下面没有链接了











文章评论
共有 0 位网友发表了评论 此处只显示部分留言 点击查看完整评论页面