importjava.util.Random;
publicclassPokerDemo{
ArrayList
Player[]players;
intn=4;
String[]name={"Wang","Zhang","Li","Yuan"};
publicPokerDemo(){
players=newPlayer[n];
for(inti=0;i
for(inti=0;i<4;i++)
for(intj=0;j<13;j++)
poker.add(newCard(i,j));
System.out.println("洗牌前:"+poker);
xipai();
System.out.println("洗牌后:"+poker);
fapai();
System.out.println("发牌后:");
for(inti=0;i
}
publicvoidxipai(){
Randomr=newRandom();
ArrayList
while(!poker.isEmpty()){
intindex=r.nextInt(poker.size());
Cardcard=poker.get(index);
tmp.add(card);
poker.remove(index);
}
poker=newArrayList
}
publicvoidfapai(){
intp=0;
while(!poker.isEmpty()){
Cardcard=poker.get(0);
players[p].add(card);
p=(p+1)%n;
poker.remove(0);
}
}
publicstaticvoidmain(String[]args){
newPokerDemo();
}
}
classCard{
intval,sty;
finalString[]value={"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
finalString[]style={"黑桃","红心","梅花","方块"};
publicCard(ints,intv){
sty=s;
val=v;
}
publicStringtoString(){
returnstyle[sty]+""+value[val];
}
}
classPlayer{
ArrayList
Stringname;
publicPlayer(Stringn){
name=n;
}
publicvoidadd(Cardcard){
cards.add(card);
}
publicStringtoString(){
returnname+":\t"+cards;
}
}