public class PuKe
{
public class Card
{
static int HongTao = 1;
static int FangKuai = 2;
static int CaoHua = 3;
static int HeiTao = 4;
int point;
int type;
public Card()
{
point = 1;
type = HongTao;
}
public Card(int point, int type)
{
this.point = point;
this.type = type;
}
int getType(){
return type;
}
int getPoint(){
return point;
}
public void show(){
if(type==HongTao) System.out.print("红桃");
if(type==FangKuai) System.out.print("方块");
if(type==CaoHua) System.out.print("草话");
if(type==HeiTao) System.out.print("黑桃");
System.out.println(point);
}
}
Card[] cards;
public PuKe()
{
cards = new Card[52]; // 没有创建Card, 只是创建了数组
for(int i=0; i<13; i++){
cards[i] = new Card(i+1, Card.HeiTao);
}
for(int i=0; i<13; i++){
cards[i+13] = new Card(i+1, Card.HongTao);
}
for(int i=0; i<13; i++){
cards[i+13*2] = new Card(i+1, Card.CaoHua);
}
for(int i=0; i<13; i++){
cards[i+13*3] = new Card(i+1, Card.FangKuai);
}
}
public void xiPai()
{
for(int i=0; i<1000; i++){
int m = Math.random() ;
int n = Math.random() ;
Card t = cards[m];
cards[m] = cards[n];
cards[n] = t;
}
}
public void faPai(PuKe.Card[] t1, PuKe.Card[] t2, PuKe.Card[] t3, PuKe.Card[] t4)
{
for(int i=0; i<13; i++){
t1[i] = cards[i];
}
for(int i=0; i<13; i++){
t2[i] = cards[i+13];
}
for(int i=0; i<13; i++){
t3[i] = cards[i+13*2];
}
for(int i=0; i<13; i++){
t4[i] = cards[i+13*3];
}
}
public static void main(String[] args)
{
PuKe a = new PuKe();
a.xiPai();
PuKe.Card[] t1 = new PuKe.Card[13];
PuKe.Card[] t2 = new PuKe.Card[13];
PuKe.Card[] t3 = new PuKe.Card[13];
PuKe.Card[] t4 = new PuKe.Card[13];
a.faPai(t1, t2, t3, t4);
for(int i=0; i<t2.length; i++){
t2[i].show();
}
}
}
我想要13张不重复的牌
这是哪错了 |