Exemplo n.º 1
0
void buySellOrHold(int currentPrice) {

    char decision;
    
    if (currentPrice > 100) {
        decision = 's';
    } else if (currentPrice > 50 && currentPrice <= 100) {
        decision = 'h';
    } else  {
        decision = 'b';
    }
    
    // display the decision to the user
    
    finalDecision(decision);
}
void BlackJack::handOver()
{
    qDebug() << "Player's hand is now " << playerHand->getValue();
    qDebug() << "dealer's hand is now " << dealerHand->getValue();

    ui->actionHit_Me->setDisabled(true);
    ui->actionStay->setDisabled(true);

    // if dealer gets 21, dealer wins automatically
    if(dealerHand->getValue() == 21) {
        finalDecision("Dealer gets blackjack. Dealer wins!", ui->sb_dealerScore);
        return;
    }

    // if player exceeds 21, gets busted and loose
    if(playerHand->getValue() > 21) {
        finalDecision("You exceeded 21 thus have lost!", ui->sb_dealerScore);
        return;
    }

    // if player gets 21, hits blackjack and wins
    if(playerHand->getValue() == 21) {
        finalDecision("BlackJack! :D", ui->sb_playerScore);
        return;
    }

    // if dealer exceeds 21, gets busted and loose
    if(dealerHand->getValue() > 21) {
        finalDecision("Dealer exceeds 21. You win!", ui->sb_playerScore);
        return;
    }

    // if player draws 5 cards, wins
    if(playerHand->count() >= 5) {
        finalDecision("5 cards?? You win!", ui->sb_playerScore);
        return;
    }

    // if dealer >= player, dealer wins
    if(dealerHand->getValue() >= playerHand->getValue()) {
        finalDecision("Dealer hand equal or exceeds player hand. Dealer Wins!",
                       ui->sb_dealerScore);
    } else {
        // if player > dealer, player wins
        finalDecision("Player hand exceeds dealer. Player wins!",
                       ui->sb_playerScore);
    }
}