public void createDeck() {
k=0;
cards=new Card[52];
for (i=0;i<4;i++) {
for (j=0;j<13;j++){
cards[k]=new Card(i,j);
k++;
}
}
}
public void shuffleDeck(int m){
Random random = new Random();
Card cardTemp;
for(i=0;i<m;i++){
k=random.nextInt(52);
cardTemp=cards[i%52];
cards[i%52]=cards[(i+k)%52];
cards[(i+k)%52]=cardTemp;
}
}
你好。我想把 i 和 j 放在
cards[k]=new Card(i,j);
因为我想通过使用这个 i 和 j 来显示西装的等级:
public Card(int suit,int rank){
this.rank=rank;
this.suit=suit;
}
private final static String[] suits = { "Hearts", "Spades", "Diamonds", "Clubs" };
private final static String[] ranks = { "Ace", "2", "3", "4", "5", "6",
"7", "8", "9", "10", "Jack", "Queen", "King" };
在另一个班级,
deck=new Deck();
deck.createDeck();
deck.shuffleDeck(111);
我应该使用另一个数组吗?我真的很困惑。我想给屏幕,例如洗牌后的王牌红心。