public void NewGame() { EndVisible = false; _hold = false; DealerHand.Clear(); PlayerHand.Clear(); DealerHand.Add(PullCard()); PlayerHand.Add(PullCard()); UpdateScores(); }
// dealer hit public List <Card> Hit(Card card) { DealerHand.Add(card); if (DealerHand.Count == 1) { dealerNotify(card, true); } else { dealerNotify(card, false); } return(DealerHand); }
/// <summary> /// Dealer hits when player holds /// </summary> private void DealerHit() { while (DealerScore <= PlayerScore && DealerScore < 21) { var task = Task.Run(() => { Thread.Sleep(1000); }); task.ConfigureAwait(true) .GetAwaiter() .OnCompleted(() => { DealerHand.Add(PullCard()); UpdateScores(); }); } DeclareWinner(); }
private void Dealer17() { if (!DealerHand.Where(dc => dc.Value == 11).Any()) { return; } var c = DealCard(); DealerHand.Add(c); DisplayCard(dealersCards, c); dealerShown += c.Value; if (dealerShown > 21) { DealerHand.Where(dc => dc.Value == 11).First().Value = 1; dealerShown -= 10; UpdateDealerShown(); Thread.Sleep(1000); } }
void DealersTurn() { ShowFaceDown(); Thread.Sleep(1500); if (dealerShown == 17) { Dealer17(); } while (dealerShown < 17) { var c = DealCard(); DealerHand.Add(c); DisplayCard(dealersCards, c); dealerShown += c.Value; if (dealerShown == 17) { Dealer17(); } UpdateDealerShown(); Thread.Sleep(1000); } if (dealerShown > 21) { MessageBox.Show("Dealer Bust", "Player Wins"); AddWin(); gameOver = true; return; } if (dealerShown <= 21 && playerShown < dealerShown) { MessageBox.Show("Dealer Wins"); gameOver = true; return; } if (dealerShown == playerShown) { MessageBox.Show("No Winner", "Push"); gameOver = true; return; } if (playerShown <= 21 && playerShown > dealerShown) { MessageBox.Show("Player Wins"); AddWin(); gameOver = true; return; } }
private void DealHands() { PlayerHand.Add(DealCard()); DisplayCard(playersCards, PlayerHand.Last()); DealerHand.Add(DealCard()); DisplayCard(dealersCards, DealerHand.Last()); PlayerHand.Add(DealCard()); DisplayCard(playersCards, PlayerHand.Last()); DealerHand.Add(DealCard()); Dispatcher.Invoke(() => dealersCards.Children.Add(new TextEdit() { Name = "FaceDown" })); DealCheck(); if (!gameOver) { Dispatcher.Invoke(() => { btnHit.IsEnabled = true; btnStand.IsEnabled = true; }); } }
/// <summary> /// Returns a random card and places it in the dealer's hand /// </summary> public void PullDealerCard() { Card tempCard; int randNum; int newValue = 0; Random random = new Random(); if (_deck.Count == 0) { GameMode = Results.Shuffle; Shuffle(); } else { randNum = random.Next(0, _deck.Count()); tempCard = _deck[randNum]; _deck.Remove(_deck[randNum]); DealerHand.Add(tempCard); //Update dealer score if (tempCard.Rank == 1) { _dealerAces++; newValue += 11; } else if (tempCard.Rank < 11) { newValue += tempCard.Rank; } else if (tempCard.Rank >= 11) { newValue += 10; } //Hold the value of the first card a secret if (DealerHand.Count == 1) { _hiddenDealerCard = +newValue; } else { DealerScore += newValue; } //Changes Aces from 11 to 1 if hand is over 21 if (_dealerAces > 0) { int count = 0; while (DealerScore > 21 && count < _dealerAces) { DealerScore -= 10; count++; _dealerAces--; } } } }