Ejemplo n.º 1
0
        public static void GameStart(GameManagement game)
        {
            //List<Card> playerCards = new List<Card>();
            Hand playerHand = new Hand();
            Hand dealerHand = new Hand();

            bool       start = true;
            ConsoleKey answer;


            //GameLogic();
            Console.WriteLine("Dealer Limit is 18\nYour 2 cards are: ");
            playerHand.AddCard(game.GetCard());
            playerHand.AddCard(game.GetCard());

            //color for the foreground to match the card types and printing it
            Console.ForegroundColor = GetForeColor(playerHand.GetCard(0));
            Console.WriteLine($"Value : {playerHand.GetCard(0).GetCardValue().PadRight(10)} Suit: {playerHand.GetCard(0).GetSuit().PadRight(10)}");

            Console.ForegroundColor = GetForeColor(playerHand.GetCard(1));
            Console.WriteLine($"Value : {playerHand.GetCard(1).GetCardValue().PadRight(10)} Suit: {playerHand.GetCard(1).GetSuit().PadRight(10)}");

            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine($"Hand value: {GetValue(playerHand.GetHand())}");

            //DEALER TEST
            Console.WriteLine("Dealer Has: ");
            dealerHand.AddCard(game.GetCard());

            //color for the foreground to match the card types and printing it
            Console.ForegroundColor = GetForeColor(dealerHand.GetCard(0));
            Console.WriteLine($"Value : {dealerHand.GetCard(0).GetCardValue().PadRight(10)} Suit: {dealerHand.GetCard(0).GetSuit().PadRight(10)}");

            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine($"Dealer Hand value: {GetValue(dealerHand.GetHand())}");

            Console.WriteLine("Do you want more cards? \nH for hit, S to stop, Esc to end");

            //game loop
            while (start)
            {
                do
                {
                    answer = Console.ReadKey(true).Key; //to not show the key in the console
                } while (!answer.Equals(ConsoleKey.H) && !answer.Equals(ConsoleKey.Escape) && !answer.Equals(ConsoleKey.S));

                //conditional for the Hit key and the respective values
                if (answer.Equals(ConsoleKey.H))
                {
                    playerHand.AddCard(game.GetCard());

                    Console.ForegroundColor = GetForeColor(playerHand.GetCard(playerHand.GetHandSize() - 1));

                    Console.WriteLine($"Value : {playerHand.GetCard(playerHand.GetHandSize() - 1).GetCardValue().PadRight(10)}" +
                                      $" Suit: {playerHand.GetCard(playerHand.GetHandSize() - 1).GetSuit().PadRight(10)}");



                    Console.ForegroundColor = ConsoleColor.White;
                    if (GetValue(playerHand.GetHand()) < 21)
                    {
                        Console.WriteLine($"Hand value: {GetValue(playerHand.GetHand())}");
                    }
                    else if (GetValue(playerHand.GetHand()) == 21 && playerHand.GetHandSize() > 2)
                    {
                        Console.Write("Hand value is 21! Maximum Value!");
                    }
                    else if (GetValue(playerHand.GetHand()) == 21 && playerHand.GetHandSize() == 2)
                    {
                        Console.Write("Hand value is 21! Blackjack!");
                    }
                    else
                    {
                        Console.WriteLine($"You blew up with: {GetValue(playerHand.GetHand())}");
                        start = false;
                    }
                }
                else if (answer.Equals(ConsoleKey.S)) //player turn ended, activate dealer turn
                {
                    Console.WriteLine("Dealer turn.");
                }
                else if (answer.Equals(ConsoleKey.Escape)) //gameEnd
                {
                    Console.WriteLine("Thank you for not playing!");
                    start = false;
                }
            }
        }