Example #1
0
        private BlackJackGameModel ToModel(BlackJackGame game)
        {
            var result = new BlackJackGameModel();

            result.Id     = game.Id;
            result.Dealer = ToModel(game.Dealer);
            result.Player = ToModel(game.Player);
            result.Winner = game.GetWinnerName();
            return(result);
        }
Example #2
0
        private BlackJackGameModel ToModel(BlackJackGame game)
        {
            var result = new BlackJackGameModel
            {
                Id     = game.Id,
                Dealer = ToModel(game.Dealer),
                Player = ToModel(game.Player),
                Winner = game.GetWinnerName()
            };

            return(result);
        }
Example #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Black Jack");
            Console.WriteLine();
            var deck   = new Deck(new RandomNumberGenerator());
            var player = new BlackJackPlayer("Stefan");
            var dealer = new BlackJackDealer();
            var game   = new BlackJackGame(Guid.NewGuid(), deck, dealer, player);

            Console.WriteLine("Do you want to play Black Jack? (y/n):");

            while (Console.ReadLine() == "y")
            {
                game.StartNewGame();

                DisplayPlayerInfo(game.Player);
                DisplayPlayerInfo(game.Dealer);

                Console.WriteLine($"{game.Player.Name}, do you want a hit?");

                while (!game.Player.IsBust && Console.ReadLine() == "y")
                {
                    game.PlayerHits();

                    DisplayPlayerInfo(game.Player);
                }

                if (!game.Player.IsBust)
                {
                    game.PlayerSticks();
                }

                DisplayPlayerInfo(game.Dealer);

                Console.WriteLine($"...and the winner is: {game.GetWinnerName()}");

                Console.WriteLine("You want to play again? (y/n)");
            }
        }