Ejemplo n.º 1
0
 private void ForcePlayerBust(int i, Game game)
 {
     game.Players[i].Hand.Cards = new List<Card>
         {
             new Card(CardValue.King),
             new Card(CardValue.King),
             new Card(CardValue.Two)
         };
 }
Ejemplo n.º 2
0
 private void ForceDealerBust(Game game)
 {
     game.Dealer.Hand.Cards = new List<Card>
         {
             new Card(CardValue.King),
             new Card(CardValue.King),
             new Card(CardValue.Two)
         };
 }
Ejemplo n.º 3
0
 public void PlayerBustIfOver21()
 {
     var game = new Game();
     GameController.InitializeGame(game);
     GameController.Deal(game);
     ForcePlayerBust(0, game);
     GameController.CheckWinLossStatus(game);
     Assert.AreEqual(Status.Bust, game.Players[0].Status);
 }
Ejemplo n.º 4
0
 public void AllBustedPlayersStillLoseIfDealerBust()
 {
     var game = new Game();
     GameController.InitializeGame(game);
     GameController.Deal(game);
     ForceDealerBust(game);
     ForcePlayerBust(0,game);
     GameController.CheckWinLossStatus(game);
     Assert.AreEqual(Status.Bust, game.Players[0].Status);
 }
Ejemplo n.º 5
0
 public void AllNonBustedPlayersWinIfDealerBust()
 {
     var game = new Game();
     GameController.InitializeGame(game);
     GameController.Deal(game);
     ForceDealerBust(game);
     GameController.CheckWinLossStatus(game);
     foreach (var player in game.Players.Where(player => player.Status != Status.Bust))
     {//all non-busted players should Win
         Assert.AreEqual(Status.Win, player.Status);
     }
 }
        public void OnNewDealEachPlayerShouldHaveTwoCards()
        {
            var game = new Game();

            GameController = new GameController();
            GameController.InitializeGame(game);
            GameController.Deal(game);
            foreach (var player in game.Players)
            {
                Assert.AreEqual(2, player.Hand.Cards.Count);
            }
        }
Ejemplo n.º 7
0
 private static void Deal(Game game)
 {
     Console.WriteLine("");
     _gameController.Deal(game);
     _gameController.CheckWinLossStatus(game);
     ShowUpdatedStatus(game);
     Console.WriteLine("");
     while (game.Status != GameStatus.AllPlayersComplete && game.Status!=GameStatus.Complete)
     {
         WaitForPlayerAction(game);
         ShowUpdatedStatus(game);
     }
     ShowUpdatedStatus(game);
 }
Ejemplo n.º 8
0
 private static void WaitForPlayerAction(Game game)
 {
     int playerId = 0;
     Player player = game.Players[playerId];
     Console.WriteLine("");
     Console.WriteLine("Player: (S)tand or (H)it?");
     ConsoleKeyInfo key = Console.ReadKey();
     if (key.Key == ConsoleKey.H)
     {
         _gameController.Hit(playerId, game);
     }
     if (key.Key == ConsoleKey.S)
     {
         _gameController.Stand(playerId, game);
     }
 }
        public Game Deal(Game game)
        {
            Reset(game);

            if (game.Shoe.Cards.Count < 0.25*game.Shoe.InitialDeckCount)
            {
                game.Shoe.Replenish();
            }
            for (int i = 0; i < 2; i++)
            {
                foreach (Player player in game.Players)
                {
                    GiveCard(player, game);
                }
                GiveCard(game.Dealer, game);
            }
            return game;
        }
        public void CheckWinLossStatus(Game game)
        {
            if (game.Dealer.Hand.Evaluate() == 21)
            {
                game.Dealer.Status = Status.Win;
                game.Status = GameStatus.Complete;
            }
            else if (game.Dealer.Hand.Evaluate() > 21)
            {
                game.Dealer.Status = Status.Bust;
                game.Status = GameStatus.Complete;
            }
            foreach (Player player in game.Players.Where(p => p.Status == Status.Undetermined))
            {
                if (player.Hand.Evaluate() == 21)
                {
                    //player has blackjack (or a push if game is complete)
                    player.Status = (game.Status == GameStatus.Complete) ? Status.Win : Status.Push;
                }
                else if (player.Hand.Evaluate() > 21)
                {
                    player.Status = Status.Bust;
                }
                else if (game.Dealer.Status == Status.Bust)
                {
                    player.Status = Status.Win;
                }
                else if (game.Dealer.Status == Status.Win)
                {
                    player.Status = Status.Lose;
                }
            }
            if (
                game.Players.All(
                    player => (player.Hand.LastAction == Hand.HandAction.Stand || player.Status != Status.Undetermined)))
            {
                game.Status = GameStatus.AllPlayersComplete;
            }
            if (game.Status == GameStatus.AllPlayersComplete)
            {
                DealerPlay(game);

                if (game.Dealer.Hand.Evaluate() > 21)
                {
                    game.Dealer.Status = Status.Bust;
                    foreach (Player player in game.Players.Where(player => player.Status == Status.Undetermined))
                    {
                        player.Status = Status.Win;
                    }
                }
                else
                {
                    foreach (Player player in game.Players.Where(player => player.Status == Status.Undetermined))
                    {
                        if (game.Dealer.Hand.Evaluate() > player.Hand.Evaluate())
                        {
                            player.Status = Status.Lose;
                        }
                        else if (game.Dealer.Hand.Evaluate() == player.Hand.Evaluate())
                        {
                            player.Status = Status.Push;
                        }
                        else
                        {
                            player.Status = Status.Win;
                        }
                    }
                    if (game.Players.Any(player => player.Status == Status.Win))
                    {
                        game.Dealer.Status = game.Dealer.Hand.Evaluate() == 21 ? Status.Push : Status.Lose;
                    }
                    else
                    {
                        game.Dealer.Status = Status.Win;
                    }
                }
                game.Status = GameStatus.Complete;
            }
        }
 private void InitializePlayers(Game game)
 {
     game.Players = new List<Player>();
     for (int i = 0; i < NumPlayers; i++)
     {
         game.Players.Add(new Player());
     }
     game.Dealer = new Dealer();
 }
 private void DealerPlay(Game game)
 {
     while (game.Dealer.Hand.Evaluate() < 16)
     {
         GiveCard(game.Dealer, game);
     }
 }
 private static void Reset(Game game)
 {
     game.Status = GameStatus.NotStarted;
     game.Dealer.Hand = new Hand();
     game.Dealer.Status = Status.Undetermined;
     foreach (Player player in game.Players)
     {
         player.Hand = new Hand();
         player.Status = Status.Undetermined;
     }
 }
 public Game InitializeGame(Game game)
 {
     game.Status = GameStatus.NotStarted;
     InitializePlayers(game);
     game.Shoe = new Deck();
     game.Shoe.Shuffle();
     return game;
 }
 public Game Hit(int playerId, Game game)
 {
     Player player = game.Players[playerId];
     player.Hand.LastAction = Hand.HandAction.Hit;
     GiveCard(player, game);
     CheckWinLossStatus(game);
     return game;
 }
 public void GiveCard(Player player, Game game)
 {
     player.Hand.Cards.Add(game.Shoe.DealNextCard());
 }
Ejemplo n.º 17
0
 private static void ShowUpdatedStatus(Game game)
 {
     Console.Clear();
     Console.WriteLine("Game Status: " + game.Status);
     PrintHandDetail(game.Dealer,game.Status.Equals(GameStatus.Complete));
     int playerId = 0;
     Player player = game.Players[playerId];
     PrintHandDetail(player, game.Status.Equals(GameStatus.Complete));
 }
 public Game Stand(int playerId, Game game)
 {
     Player player = game.Players[playerId];
     player.Hand.LastAction = Hand.HandAction.Stand;
     CheckWinLossStatus(game);
     return game;
 }