public void Match() { _dealer.Shuffle(); if (!_dealer.PeekAtDeck()) { throw new Exception("No Cards in Deck"); } var lastCard = _dealer.Deal(); var cards = new List <Card>() { lastCard }; while (_dealer.PeekAtDeck()) { var card = _dealer.Deal(); cards.Add(card); if (_matchCondition.IsMatch(lastCard, card)) { if (_rdm.Next(2) == 1) { _player1.GiveCards(cards); } else { _player2.GiveCards(cards); } if (!_dealer.PeekAtDeck()) { break; } lastCard = _dealer.Deal(); cards = new List <Card>() { lastCard }; } else { lastCard = card; } } }
/// <summary> /// Play next game round. Game Status change to GameOver when there are no more rounds to play. /// </summary> public void PlayRound() { if (!this.CanPlayRound()) { return; } var shuffledDeck = _dealer.Shuffle(_deck); _dealer.Deal(shuffledDeck, Players, 2); var score = _dealer.ScorePlayers(Players); Rounds.Add(new Round(Rounds.Count + 1, score)); Status = Rounds.Count == NumberOfRounds ? GameStatus.GameOver : GameStatus.InProgress; if (Status == GameStatus.GameOver) { GameOver(); } }
public static void TheDealerDealsXCards(IDealer dealer, Deck deck, IList <Player> players, int cards) { dealer.Deal(deck, players, cards); }
private void PlayerPlayHand(Player player, Hand hand, int handIndex, int handsCount) { // Flag to keep track of blackjacks, busts and stays. var playing = true; while (playing) { var opts = PlayerOptions.DetermineOps(player, hand); var option = string.Empty; while (!console.TryAskLine($"playing your hand {handIndex + 1}/{handsCount}, what will you do? " + $"({string.Join(", ", opts)})", out option, s => opts.Contains(s))) { console.WriteWarning("invalid operation!"); } switch (option) { case PlayerOptions.OptStay: // Nothing else to do, end turn. console.WriteDealerInfo("staying, your turn is over"); playing = false; break; case PlayerOptions.OptHit: // Deal one card and reveal the hand to player. console.WriteDealerInfo("dealing one card..."); dealer.Deal(hand); RevealPlayerCards(player, hand); if (BlackjackRules.IsBlackjack(hand)) { // Handle blackjack. console.WriteDealerInfo("blackjack! your turn is over"); playing = false; } else if (BlackjackRules.IsBusted(hand)) { // Handle bust. console.WriteDealerInfo("busted! sorry, your hand is out"); playing = false; } break; case PlayerOptions.OptDouble: var bet = bets[player].First(); // Do not allow doubling if the player has not enough balance. if (player.Wallet.Balance < bet.Amount) { console.WriteDealerInfo("sorry, you do not have enough balance to double"); } else { // Do the actual doubling. console.WriteDealerInfo("doubling your hand..."); // Deal single card as of doubling. dealer.Deal(hand); // Take double amount from wallet. player.Wallet.Take(bet.Amount); // Create new bet in place of the current one, we can // always assume there is only one bet in play when // the player is doubling because casino does not allow // doubling split hands. var newBet = new PlayerBet(hand, bet.Amount * 2u); bets[player] = new List <PlayerBet> { newBet }; console.WriteDealerInfo($"your total bet is now {newBet.Amount}e " + $"and your total balance is now {player.Wallet.Balance}e"); RevealPlayerCards(player, hand); playing = false; } break; default: console.WriteWarning("sorry i could not understand you so i assume you are staying..."); playing = false; break; } clock.Delay(DelayTime); } }
public void PlayRound(List <IPlayer> players, ushort numberOfShuffles, ushort handSize) { _dealer.Shuffle(numberOfShuffles); _dealer.Deal(players, handSize); }