如何创建一副卡片构造函数 [英] how to create a deck of cards constructor

查看:107
本文介绍了如何创建一副卡片构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止这就是我所拥有的

so far this is what I have

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;

我是否朝着正确的方向前进?...我在此之后该怎么办?我对布尔数组不是很熟悉

Am I heading the right direction?... What do I do after this? I am not very familiar with boolean arrays

推荐答案

我自己,我会为我的牌组变量使用一组Card对象,而不是一系列布尔。原始布尔变量只能处于两种状态之一,即真或假,而卡必须同时具有套装(4种状态中的1种)和1种状态(13种状态中的1种)。

Myself, I'd use an array of Card objects for my deck variable, not an array of booleans. The primitive boolean variable can only be in one of two states, true or false, whereas a Card must have both a suit (1 of 4 states) and a rank (1 of 13 states).

这篇关于如何创建一副卡片构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆