Skip to content

hitCard() #1

Description

@Dudzius
public void hitCard() {
        if (deck.getDeckSize() == 0) {
            deck = new Deck();
            deck.shuffle();
        }
        hand = new Hand();
        currentCard = deck.dealCard();
        int currentCardFaceValue;
        playerHandCount++;

        ImageView playerCard = getPlayerCardImageView(playerHandCount);
        playerCard.setImage(currentCard.getImage());
        playerCard.setVisible(true);

        currentCardFaceValue = hand.extractFaceValue(currentCard.toString(), playerScore);
        playerScore = hand.calculateScore(playerScore, currentCardFaceValue);
        displayPlayerFaceValue.setText(String.valueOf(playerScore));
        cardsInDeck.setText(Integer.toString(deck.getDeckSize()));

        if (checkIfBust(playerScore) && playerHandCount > 2) {
            winsText.setVisible(true);
            winsText.setText("Dealer wins (player busted)");
            playAgainButton.setVisible(true);
            playerLostFlag = true;
            toggleButtons(false);
            if (checkIfGameOver(playerMoneyAmount)) {
                showGameOverScreen();
            }
        } else if (checkIfMaxScore(playerScore) && playerHandCount >= 2) {
            winsText.setVisible(true);
            winsText.setText("Player wins (player got 21)");
            playAgainButton.setVisible(true);
            playerMoneyAmount = playerMoneyAmount + playerBetAmount * 2;
            playerMoney.setText(Integer.toString(playerMoneyAmount));
            playerLostFlag = false;
            toggleButtons(false);
        }
        hand.setPlayerHandCardCount(playerHandCount);
        hand.setPlayerScoreCount(playerScore);
    }

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions