Skip to content

standCard() #2

Description

@SteinCode
public void standCard() {
        if (this.deck.getDeckSize() == 0) {
            this.deck = new Deck();
            this.deck.shuffle();
        }

        this.hand = new Hand();
        this.currentCard = this.deck.dealCard();
        ++this.dealerHandCount;
        ImageView dealerCard = this.getDealerCardByIndex(this.dealerHandCount);
        dealerCard.setImage(this.currentCard.getImage());
        dealerCard.setVisible(true);
        int currentCardFaceValue = this.hand.extractFaceValue(this.currentCard.toString(), this.dealerScore);
        if (this.dealerHandCount == 2) {
            this.hiddenCardValue = currentCardFaceValue;
        } else if (this.dealerHandCount == 3) {
            currentCardFaceValue += this.hiddenCardValue;
            this.dealerScore = this.hand.calculateScore(this.dealerScore, currentCardFaceValue);
        } else {
            this.dealerScore = this.hand.calculateScore(this.dealerScore, currentCardFaceValue);
        }

        this.displayDealerFaceValue.setText(String.valueOf(this.dealerScore));
        this.hand.setDealerHandCardCount(this.dealerHandCount);
        this.hand.setDealerScoreCount(this.dealerScore);
        this.cardsInDeck.setText(Integer.toString(this.deck.getDeckSize()));
        if (this.checkIfMaxScore(this.dealerScore + this.hiddenCardValue) && this.dealerHandCount == 2) {
            this.winsText.setVisible(true);
            this.winsText.setText("Dealer wins (dealer got 21)");
            this.playAgainButton.setVisible(true);
            this.toggleButtons(false);
            this.dealerCard2.setImage(this.previousCard.getImage());
            if (this.checkIfGameOver(this.playerMoneyAmount)) {
                this.showGameOverScreen();
            }
        } else if (this.dealerHandCount > 2) {
            if (this.checkIfBust(this.dealerScore)) {
                this.winsText.setVisible(true);
                this.winsText.setText("Player wins (dealer busted)");
                this.playAgainButton.setVisible(true);
                this.playerMoneyAmount += this.playerBetAmount * 2;
                this.playerMoney.setText(Integer.toString(this.playerMoneyAmount));
                this.toggleButtons(false);
            } else if (this.dealerScore <= 20 && this.checkIfDealerHitNext(this.dealerScore)) {
                this.standCard();
            } else if (this.checkIfMaxScore(this.dealerScore)) {
                this.winsText.setVisible(true);
                this.winsText.setText("Dealer wins (dealer got 21)");
                this.playAgainButton.setVisible(true);
                this.toggleButtons(false);
                if (this.checkIfGameOver(this.playerMoneyAmount)) {
                    this.showGameOverScreen();
                }
            } else if (this.compareScores(this.playerScore, this.dealerScore)) {
                this.winsText.setVisible(true);
                this.winsText.setText("Player wins (player score is bigger)");
                this.playAgainButton.setVisible(true);
                this.playerMoneyAmount += this.playerBetAmount * 2;
                this.playerMoney.setText(Integer.toString(this.playerMoneyAmount));
                this.toggleButtons(false);
            } else if (this.checkIfPush(this.playerScore, this.dealerScore)) {
                this.winsText.setVisible(true);
                this.winsText.setText("Push!");
                this.playAgainButton.setVisible(true);
                this.playerMoneyAmount += this.playerBetAmount;
                this.playerMoney.setText(Integer.toString(this.playerMoneyAmount));
                this.toggleButtons(false);
            } else {
                this.winsText.setVisible(true);
                this.winsText.setText("Dealer wins (dealer score is bigger)");
                this.playAgainButton.setVisible(true);
                this.toggleButtons(false);
                if (this.checkIfGameOver(this.playerMoneyAmount)) {
                    this.showGameOverScreen();
                }
            }
        }

    }

Metadata

Metadata

Assignees

Labels

help wantedExtra attention is needed

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions