Example #1
0
        static void Main(string[] args)
        {
            bool Game = true;

            Console.Out.WriteLine("Tell me your name");
            string Name = Console.ReadLine();

            while (Game)
            {
                Game game = new Game(Name);
                game.StartGame();


                if (game.player.CheckHand() == 21 || game.bot.CheckHand() == 21)
                {
                    game.gameState = false;
                }

                while (game.gameState)
                {
                    Console.Clear();
                    game.CheckHands();
                    if (game.Player)
                    {
                        Console.Out.WriteLine("Wilt u nog een kaart?");
                        ConsoleKeyInfo card = Console.ReadKey();

                        if (card.KeyChar == 'y')
                        {
                            game.Draw(game.player);
                            game.Bot = game.DrawOnChance(game.bot);
                        }
                        else
                        {
                            game.Player = false;
                            game.Bot    = game.DrawOnChance(game.bot);
                        }
                    }
                    else if (game.Bot)
                    {
                        game.Bot = game.DrawOnChance(game.bot);
                    }
                    else
                    {
                        game.gameState = false;
                    }

                    if (game.player.CheckHand() == 21 || game.bot.CheckHand() == 21 || game.player.CheckHand() > 21 || game.bot.CheckHand() > 21)
                    {
                        break;
                    }
                }

                Console.Clear();

                game.Winner();

                Console.Out.WriteLine("Do you wanna play another game?");
                ConsoleKeyInfo again = Console.ReadKey();

                if (again.KeyChar == 'n')
                {
                    Game = false;
                }
            }
        }
Example #2
0
        private static void DrawCard(Game game, bool isPlayer)
        {
            if (isPlayer)
            {
                game.Draw(game.Player);
                Console.Clear();
                Console.WriteLine("Dealer cards:" + Console.Out.NewLine);
                PrintCards(game.Dealer, true, game.GameSettings.TargetScore, 0);
                Console.WriteLine("Player cards:" + Console.Out.NewLine);
                PrintCards(game.Player, false, game.GameSettings.TargetScore);
                DisplayPlayerOptions(game);
                return;
            }
            else
            {
                if (game.Dealer.GetValue(game.GameSettings.TargetScore) >= game.GameSettings.DealerStandValue)
                {
                    Console.WriteLine(Console.Out.NewLine + "Dealer cards:" + Console.Out.NewLine);
                    PrintCards(game.Dealer, false, game.GameSettings.TargetScore);
                }

                var isFirstDealerDraw = true;

                while (game.Dealer.GetValue(game.GameSettings.TargetScore) < game.GameSettings.DealerStandValue)
                {
                    if (isFirstDealerDraw)
                    {
                        Thread.Sleep(1000);
                        isFirstDealerDraw = false;
                    }
                    else
                    {
                        game.Draw(game.Dealer);
                    }

                    Console.Clear();
                    Console.WriteLine("Dealer cards:" + Console.Out.NewLine);
                    PrintCards(game.Dealer, false, game.GameSettings.TargetScore);
                    Thread.Sleep(1000);

                    if (game.Dealer.GetValue(game.GameSettings.TargetScore) >= game.GameSettings.DealerStandValue)
                    {
                        Console.WriteLine("Player cards:" + Console.Out.NewLine);
                        PrintCards(game.Player, false, game.GameSettings.TargetScore, 0);
                    }
                }

                if (game.Player.GetValue(game.GameSettings.TargetScore) >
                    game.Dealer.GetValue(game.GameSettings.TargetScore) && !game.Player.IsBust ||
                    game.Player.GetValue(game.GameSettings.TargetScore) <
                    game.Dealer.GetValue(game.GameSettings.TargetScore) && game.Dealer.IsBust
                    )
                {
                    Console.WriteLine("You win!");
                }
                else
                {
                    Console.WriteLine("You lose!");
                }

                return;
            }
        }