private void DealHands() { if (CardsInDeck < 10) { DealHandsButtonVisible = false; ShuffleDeckButtonVisible = true; MessageBoard = "There are not enough cards\n" + "in the deck to play the hand."; } else { PlayerHand.clearHand(); DealerHand.clearHand(); PlayerHand.AddCard(MyDeck.pick()); PlayerHand.AddCard(MyDeck.pick()); DealerHand.AddCard(MyDeck.pick()); DealerHand.AddCard(MyDeck.pick()); HitButtonVisible = true; StayButtonVisible = true; ShuffleDeckButtonVisible = false; DealHandsButtonVisible = false; CardsInDeck = MyDeck.CardsLeft(); DealerHandValue = 0; PlayerHandValue = 0; MessageBoard = ""; } }
public void Stay() { round_replay.PushAction(0, Player.Hand.GetHighValue(), DealerHand.Cards[1].NumValue); while (DealerShouldHit()) { DealerHand.AddCard(Deck.DrawCard()); } if (DealerHand.HasBlackJack() && !Player.Hand.HasBlackJack()) { EndRound(false); } else if (DealerHand.GetHighValue() > 21) { EndRound(true); } else if (Player.Hand.GetHighValue() >= DealerHand.GetHighValue()) { EndRound(true); } else { EndRound(false); } }
/// <summary> /// Dealer Play /// </summary> /// <returns>The result </returns> public static List <Result> DealerPlay() { List <Result> result = new List <Result>(); bool drawCard = true; // Check if player gone Bust or not if (PlayerHands[0].Score > 21) { drawCard = false; } if (PlayerHands[0].HasSurrendered) // player surrender { result.Add(Result.Surrendered); // player get half the bet PlayerFunds += PlayerHands[0].Bet / 2; } // Draw Card for Dealer if (!PlayerHands[0].HasSurrendered && drawCard) { while (DealerHand.Score < 17) { DealerHand.AddCard(_deck.DealOneCard()); } } // Check Player Result for (int x = 0; x < PlayerHands.Count && !PlayerHands[0].HasSurrendered; x++) { if (DealerHand.Score > 21 || (PlayerHands[x].Score > DealerHand.Score && PlayerHands[x].Score <= 21))// player win { result.Add(Result.Won); // player gain twice their bet PlayerFunds += PlayerHands[x].Bet * 2; } else if (PlayerHands[x].Score > 21) // player bust { result.Add(Result.Bust); } else if (PlayerHands[x].Score == DealerHand.Score) // player Push { result.Add(Result.Push); // player get their bet back PlayerFunds += PlayerHands[x].Bet; } else if (PlayerHands[x].Score < DealerHand.Score) // player lost { result.Add(Result.Lost); } } return(result); }
private void Stay() { PlayerHandValue = PlayerHand.handValue(); DealerHandValue = DealerHand.handValue(); bool dealerHas5CardsWithValueSmallerThan21 = false; int count = DealerHand.CardsInHand.Count; while (!dealerHas5CardsWithValueSmallerThan21 && DealerHandValue < 18) { DealerHand.AddCard(MyDeck.pick()); DealerHandValue = DealerHand.handValue(); count++; if (count == 5 && DealerHandValue <= 21) { dealerHas5CardsWithValueSmallerThan21 = true; } } string winner = (dealerHas5CardsWithValueSmallerThan21 || (DealerHandValue >= PlayerHandValue && DealerHandValue <= 21)) ? "Dealer wins!" : "Player wins!"; if (DealerHandValue == PlayerHandValue && !dealerHas5CardsWithValueSmallerThan21) { winner = "It's a draw."; } MessageBoard = $"{winner}"; if (winner == "Dealer wins!") { DealerScore++; } if (winner == "Player wins!") { PlayerScore++; } HitButtonVisible = false; StayButtonVisible = false; ShuffleDeckButtonVisible = true; DealHandsButtonVisible = true; CardsInDeck = MyDeck.CardsLeft(); }