文档库 最新最全的文档下载
当前位置:文档库 › 发牌洗牌

发牌洗牌

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package cards;
import java.util.Random;
/**
*
* @author Administrator
*/
class card{
public String face;
public String suit;
public String joker;
public card(String f,String s){
this.face=f;
this.suit=s;
}

@Override
public String toString(){
String x=suit+": "+face+" ";
return x;
}
}
class DeckofCards{
card zj[];
public DeckofCards(){
zj=new card[54];
String number[]={"A","1","2","3","4","5","6","7","8","9","10","J","Q","K", };

String huase[]={"heart","spades","diamonds","clubs"};
for(int i=0;i<52;i++)
{
// zj[i].suit=number[i%13];
// zj[i].face=huase[i%4];
zj[i]=new card(number[i%13],huase[i/13]);
// System.out.print(zj[i]);

}
}
public void shuffle(){
// zj=new card[54];
Random r=new Random();
for(int i=0;i<54;i++){
int j=r.nextInt(54);
card temp=zj[j];
zj[j]=zj[i];
zj[i]=temp;
}
}
public void dealCard(){
// zj=new card[52];
for(int i=0;i<54;i++)
{
if(i%4==0)
System.out.println("\n");
System.out.print(zj[i]);
}
}
}
public class Cards {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
DeckofCards d=new DeckofCards();
d.shuffle();

d.dealCard();
}

}

相关文档