Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用面向对象的Java 21点游戏_Java_Oop_Blackjack - Fatal编程技术网

使用面向对象的Java 21点游戏

使用面向对象的Java 21点游戏,java,oop,blackjack,Java,Oop,Blackjack,这是我的甲板课: import java.util.Random; public class Deck { private Card[] myCards; private int numCards; // This constructor builds a deck of 52 cards. public Deck() { int c = 0; this.numCards = 52; this.myCards = new Card[th

这是我的甲板课:

    import java.util.Random;

    public class Deck
    {
private Card[] myCards;
private int numCards;

    // This constructor builds a deck of 52 cards.
public Deck()
{
    int c = 0;
    this.numCards = 52;
    this.myCards = new Card[this.numCards];

    for(int i = 0; i < 4; i++){
        for(int j = 1; j <= 13; j++){
            this.myCards[c] = new Card (i, j);
            c++;
        }
    }
  }

public Card deal()
{
    Card top = this.myCards[0];

        for (int c=1; c<this.numCards; c++){
            this.myCards[c-1]=this.myCards[c];
        }
        this.myCards[this.numCards-1]=null;
        this.numCards--;
        return top;
}

public boolean isEmpty()
{
    if (numCards == 0 ){
        return true;
    } else {
        return false;
    }
}

public void shuffle(){

    Random rng = new Random();

    Card temp;

    int j;
    for(int i = 0; i < this.numCards; i++){
        j = rng.nextInt(this.numCards);
        temp = this.myCards[i]; 
        this.myCards[i]= this.myCards[j];
        this.myCards[j] = temp;
    }
}

public void printDeck(int numToPrint){
    for (int c = 0; c<numToPrint; c++){
            System.out.printf("% 3d/%d %s \n",      c+1 ,this.numCards, this.myCards[c].toString());
        }

        System.out.printf("\t\t[%d other]", this.numCards- numToPrint);
}
    }
import java.util.Random;
公务舱甲板
{
私人卡[]我的卡;
私人国际货币基金组织;
//这个构造器构建了一副52张卡片。
公共甲板()
{
int c=0;
this.numCards=52;
this.myCards=新卡[this.numCards];
对于(int i=0;i<4;i++){

对于(int j=1;j这些是我的笔记,直到我放弃为止。我放弃了,因为糟糕的格式正在破坏我阅读代码的努力

此外,在我看来,格式较差的区域也是包含最荒谬代码的区域,因此我开始怀疑有什么可疑之处,比如可能涉及到两个程序员,一个不懂Shuck,另一个可能懂几件事


我建议使用
ArrayList
而不是
Card[]
,但是如果您的任务要求使用数组,那么最好还是使用数组

我建议你停止一直使用
这个。
,但是如果你的教授要求你这么做,那么你能做什么呢

您的整个
isEmpty()
方法可以被编码为
{return numCards==0;}
,但您所拥有的并没有错,只是很愚蠢

你的套装和脸应该是
enum
s,而不是大量的常量。这不是一个错误,但是你的脸常量从1开始而不是从0开始这一事实可能会导致问题

您的
suiteString()
实际上应该使用
switch
语句来实现。(不是错误。)

您的Card.mySuit和Card.cardwalue成员毫无意义,而且它们似乎也不会被使用

Card.mySuit似乎属于
Suit
类型。那么,最后,您是否有
Suit
枚举?您是否对我们隐瞒了什么

printHand()
中,您确实应该使用
StringBuilder
。但不是错误

遇到错误时,不要
系统.err.printf()
退出()
。而是引发异常。但不要引发错误

以下代码毫无意义:

private int face;

public int getFace()
{
    this.face = face;
    return face;
}
一个球员拥有一张脸是没有任何意义的。 幸运的是,它从未被使用过。扔掉它

让你知道,这是:

Player a;
a = new Player(playerName, startingBalance);
player[i] = a;
简化为:

Player a = new Player(playerName, startingBalance);
player[i] = a;
player[i] = new Player(playerName, startingBalance);
简化为:

Player a = new Player(playerName, startingBalance);
player[i] = a;
player[i] = new Player(playerName, startingBalance);
请不要浪费我们的时间,强迫我们阅读无意识的代码行

main()
中,您声明了一些
double[]playersBank
,但是每个玩家都有自己的
资金,这对我来说没有任何意义。我可能错了,但我认为其中一个需要退出。我建议取消
playersBank
。这可能是个错误

是的,当然该程序不是在玩家的余额中扣除或添加赌注,您还没有编写代码来完成这一操作。但对于已经编写了这么多代码的人来说,这应该是微不足道的。您是否有机会从其他人那里复制了此代码,而不知道它是如何工作的,以及它试图做什么

无论如何,near
bets[i]=currentBet;
当然你需要从玩家的余额中减去
currentBet
。这是一个错误

另外,我建议丢失
bets[]
数组,并将
currentBet
移动到
Player
类中。但这不是错误



至于分手功能,您可能需要添加一张
卡[]splitHand
玩家的成员
,如果该成员不为空,则表示该玩家已分手。您需要编写请求该玩家分手的代码,并执行该操作。我们在此查找用户代码的问题,并提出解决方案,我们通常不编写用户代码。

请浏览并阅读帮助中心以了解h如何使用堆栈溢出。我忘了提到我在编程方面是一个完全的新手。不,你提到过,但我把它删掉了。这无关紧要。请参观一下并阅读帮助中心了解原因。我在合并分手功能方面遇到了困难。我尝试调用玩家卡阵列中的卡,并将它们与每个ot进行比较她。请解释一下什么是“裂手特征”意思是说。我们来自世界各地,不仅来自玩黑杰克的地方。而且,我们是程序员,我们不是赌徒。谢谢你的帮助。一些对象和构造函数在课堂上被介绍过,所以在教授允许的情况下,学生们复制了代码。我对编码有一个非常基本的理解。事情变得一团糟当错误不断出现时,我尝试了廉价的修复程序,以使程序出现某种工作错误。我认为,无论结果如何,我已经证明我不理解这一点,需要再次上课。感谢您的帮助,尽管非常感谢。
player[i] = new Player(playerName, startingBalance);