Пример #1
0
    private void StartGame()
    {
        Cards    deck     = new Cards();    // Creating new deck
        Croupier croupier = new Croupier(); // initalizing croupier
        Player   player   = new Player();   //initializing player

        // Croupiter starting round
        croupier.TakeCard(deck.AllCards); // Croupier is taking one card

        //Player round
        for (int i = 1; i <= 2; i++)  // player starts with 2 cards
        {
            player.TakeCard(deck.AllCards);
        }

        int  option = 1;
        bool guard  = true;

        while (guard)
        {
            Console.Clear();
            Console.WriteLine("Croupier Hand:");
            croupier.DrawCroupierHand();
            croupier.WriteHandPoints();
            Console.WriteLine("Player Hand:");
            player.DrawHand();
            player.WriteHandPoints();
            PlayerRound(ref option, player, deck.AllCards, ref guard);
        }
        // croupiers ends his round
        Console.Clear();
        Console.WriteLine("----Croupier Round----");
        croupier.TakeCards(deck.AllCards);

        //summary
        Console.Clear();

        Console.WriteLine("---Croupier Hand---");
        croupier.DrawHand();
        croupier.WriteHandPoints();
        Console.WriteLine("Player Hand:");
        player.DrawHand();
        player.WriteHandPoints();

        Console.WriteLine("----------Summary----------");
        Console.WriteLine($"Croupier Points: {croupier.Points}");
        Console.WriteLine("------");
        Console.WriteLine($"Player Points: {player.Points}");
        Console.WriteLine("--------------------------");
        Console.Write("The winner is... ");

        Thread.Sleep(500);
        if (CheckWinner(croupier, player) == 0)
        {
            Console.BackgroundColor = ConsoleColor.DarkRed;
            Console.WriteLine("Croupier!");
        }
        else if (CheckWinner(croupier, player) == 1)
        {
            Console.BackgroundColor = ConsoleColor.DarkGreen;
            Console.WriteLine("Player! You won!");
        }
        else
        {
            Console.BackgroundColor = ConsoleColor.DarkYellow;
            Console.WriteLine("No one! Draw!");
        }

        Console.BackgroundColor = ConsoleColor.Blue;
        Console.ForegroundColor = ConsoleColor.White;
        if (CheckBJ(croupier))
        {
            Console.WriteLine("Croupier has Black Jack! Congratulations!");
        }
        else if (CheckBJ(player))
        {
            Console.WriteLine("Player has Black Jack! Congratulations!");
        }
        Console.ResetColor();
        Console.WriteLine("Press any key to return to menu...");
    }