/// <summary> /// Displays the Users hand Value and updates the players hand image /// </summary> private void DisplayHandValue(int player) { if (player == PLAYER) { lblPlayersHandValue.Text = TwentyOne.HandValue(PLAYER).ToString(); DisplayGuiHand(TwentyOne.GetHand(PLAYER), playerTableLayoutPanel); } else { lblDealersHandvalue.Text = TwentyOne.HandValue(DEALER).ToString(); DisplayGuiHand(TwentyOne.GetHand(DEALER), dealerTableLayoutPanel); } }
/// <summary> /// Adds a card to a Users Hand and then checks if they have gone bust or not /// Pre: They must not have 21 already and have hit the hit button /// Post: Deals a card to the player /// </summary> private void btnHit_Click(object sender, EventArgs e) { TwentyOne.AddCard(PLAYER); DisplayGuiHand(TwentyOne.GetHand(PLAYER), playerTableLayoutPanel); CheckHandForAce(); lblPlayersHandValue.Text = TwentyOne.HandValue(PLAYER).ToString(); if (TwentyOne.HandValue(PLAYER) > TwentyOne.MAXVALUE) { TwentyOne.DetermineWinner(); PlayerHasBusted.Visible = true; DisplayGamesWon(); DisableButtons(); } }
/// <summary> /// Sets up the game of 21 /// </summary> private void btnDealCards_Click(object sender, EventArgs e) { TwentyOne.SetUpGame(); DisplayGuiHand(TwentyOne.GetHand(DEALER), dealerTableLayoutPanel); DisplayGuiHand(TwentyOne.GetHand(PLAYER), playerTableLayoutPanel); TwentyOne.DisplayHand(DEALER); TwentyOne.DisplayHand(PLAYER); DisplayHandValue(PLAYER); DisplayHandValue(DEALER); lblValue.Text = TwentyOne.GetNumOfUserAcesWithValueOne().ToString(); DealerHasBusted.Visible = false; PlayerHasBusted.Visible = false; btnDealCards.Enabled = false; btnHit.Enabled = true; btnStand.Enabled = true; CheckHandForAce(); CheckHandForAce(); }