private void drawButton_Click(object sender, EventArgs e) { Card cardDrawn = deck.Draw(); if ((int)cardDrawn.Value >= 10) { playerScore += 10; } else if (cardDrawn.Value == Enums.Value.Ace) { using (AceDialogue aceDialogue = new AceDialogue(playerScore)) { if (aceDialogue.ShowDialog() == DialogResult.OK) { playerScore += aceDialogue.ChosenValue; } } } else { playerScore += (int)cardDrawn.Value; } PlayerHand.Add(cardDrawn); scoreLabel.Text = playerScore.ToString(); PrintHand(PlayerHand, PlayerPics); checkScore(); }
private void dealButton_Click(object sender, EventArgs e) { deck.Shuffle(4); //dealing dealer's hand for (int i = 0; i < 2; i++) { DealerHand.Add(deck.Draw()); if ((int)DealerHand[i].Value >= 10) { dealerScore += 10; } else if (DealerHand[i].Value == Enums.Value.Ace) { dealerCheck(); } else { dealerScore += (int)DealerHand[i].Value; } } PrintHand(DealerHand, DealerPics, true); //if the dealer has 21, they win before the player's hand is checked if (dealerScore == 21) { dealt21 = true; PrintHand(DealerHand, DealerPics); DialogResult dialogResult = MessageBox.Show("The dealer scored 21! Would you like to play again?", "Loss", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { resetGame(); } } //dealing player's hand if the dealer doesnt get a 21 on their first turn if (!dealt21) { for (int i = 0; i < 2; i++) { PlayerHand.Add(deck.Draw()); if ((int)PlayerHand[i].Value >= 10) { playerScore += 10; } else if (PlayerHand[i].Value == Enums.Value.Ace) { using (AceDialogue aceDialogue = new AceDialogue(playerScore)) { if (aceDialogue.ShowDialog() == DialogResult.OK) { playerScore += aceDialogue.ChosenValue; } } } else { playerScore += (int)PlayerHand[i].Value; } } PrintHand(PlayerHand, PlayerPics); scoreLabel.Text = playerScore.ToString(); dealButton.Enabled = false; drawButton.Enabled = true; keepButton.Enabled = true; } }