到目前为止,这就是我所拥有的
import java.util.Random;
public class DeckOfCards
{
public static final int DECK_SIZE = 52;
//Instance Variables
private boolean[] deck; //An implicit set of 52 Playing-Cards
private int cardsInDeck;//Number of cards currently in the deck
private Random dealer; //Used to rendomly select a card to be dealt
//Constructor
public DeckOfCards()
{
deck = new boolean[52];
for (int j = 0; j<deck.length ; j ++)
deck [j] = false;
我的方向正确吗?...之后我该怎么办?我对 boolean 数组不太熟悉
最佳答案
我自己,我会使用 Card 对象数组作为我的牌组变量,而不是 boolean 数组。原始 boolean 变量只能处于 true 或 false 两种状态之一,而卡片必须同时具有花色(4 种状态中的 1 种)和等级(13 种状态中的 1 种)。
关于java - 如何创建一副纸牌构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10592817/