Ejemplo n.º 1
0
        public static Hand dealerHand = new Hand();                                                 //Creating dealers hand
        static void Main(string[] args)
        {
            Console.WriteLine("*****BLACKJACK*****");
            bool play = true;                                                                       //Preparing game properties

            do
            {
                AddingCardsToDeck();                                                                //Adding cards to deck
                PlayerStartingHand();                                                               //Adding players starting cards
                DealerStartingHand();                                                               //Adding dealers starting cards

                Console.WriteLine($"Your cards: {playerHand.CardsInHand()}");
                Console.WriteLine($"Total Value: {playerHand.HandValue()}");
                Console.WriteLine($"Your account balance: {balance}$");
                int betValue = AddingBet();                                                         //Accepting players bet

                bool game = true;                                                                   //Main game logic loop
                while (game == true)
                {
                    bool validInput = false;
                    while (validInput == false)                                                     //Checking if user input is valid. If user unput is invalid, the loop will continue until it's valid
                    {
                        Console.WriteLine($"Your cards: {playerHand.CardsInHand()}");               //Presenting cards in players hand
                        Console.WriteLine($"Total Value: {playerHand.HandValue()}");                //Presenting players hand value
                        NewLine();
                        Console.WriteLine($"Dealers cards: {dealerHand.CardsInHand()}");            //Presenting cards in dealers hand
                        Console.WriteLine($"Total Value: {dealerHand.HandValue()}");                //Presenting dealers hand value
                        NewLine();
                        Console.WriteLine($"Your bet: {betValue}$");                                //Players current bet
                        Console.WriteLine($"Your account balance: {balance-betValue}$");            //Players current balance

                        Menu();                                                                     //Print game Menu with possible choices
                        string decision = Console.ReadLine().Trim().ToLower();                      //getting user input
                        Console.Clear();

                        switch (decision)                                                           //Makes action, depending on users choice
                        {
                        //Hit
                        case "h":
                            validInput = true;
                            playerHand.hand.Add(deck.GetCard());                                    //Adding card to players deck
                            Console.WriteLine($"You got: {playerHand.LastCardInHand().Name}");      //Presenting players new card
                            if (playerHand.BustCheck() == true)                                     //Checking for Bust
                            {
                                Console.WriteLine($"You Busted!\nYou lost {betValue}$");
                                PrintResults();
                                balance -= betValue;
                                game     = false;
                                break;
                            }
                            break;

                        //Stay
                        case "s":
                            validInput = true;
                            game       = false;                                                     //Stoping game logic loop, because game ends after player decides to stay with his hand
                            DealerPlay();                                                           //Simulating Dealers "logic"
                            if (dealerHand.BustCheck() == true)                                     //Checking for dealers Bust
                            {
                                Console.WriteLine($"Dealer Busted!\nYou won {2*betValue}$");
                                balance += 2 * betValue;
                                PrintResults();
                                break;
                            }
                            ResultCheck(betValue);                                                  //Checking game result and comparing hands
                            break;
                        }
                    }
                }

                play = PlayAgain();                                                                 //Asking user for next deal
                Console.Clear();
            }while (play == true);
        }