Exemple #1
0
        static void Main(string[] args)
        {
            Deck d = new Deck();

            while (true)
            {
                Clear();

                Hand hand = new Hand();
                Dealer dealer = new Dealer();
 
                hand.startHand = d.DrawTwoFromDeck();
                
                bool Bust = false;
                bool Stick = false;
                bool BlackJack = false;

                WriteLine(d.TwoCardHandToString(hand.startHand));
                WriteLine(d.CheckBlackJack(hand.startHand));
                WriteLine();
                WriteLine("H to hit, S to stick.");
                for (int i = 0; i < 3; i++)
                {
                    WriteLine();
                    switch (ReadKey().Key)
                    {
                        case ConsoleKey.H:
                            Write("it");
                            WriteLine();
                            Card newCard = d.DrawFromDeck();
                            hand.extraCards[i] = newCard;
                            WriteLine($"{newCard},   {d.handCount(hand.startHand, hand.extraCards)}");
                            if(d.handCount(hand.startHand, hand.extraCards) > 21) Bust = true;
                            if (d.handCount(hand.startHand, hand.extraCards) == 21) BlackJack = true;
                            break;
                        case ConsoleKey.S:
                            Write("tick.");
                            WriteLine();
                            Stick = true;
                            break;
                        default:
                            Write(" is an Invalid key.");
                            WriteLine();
                            break;
                    }

                    if (d.CardsInDeck == 0)
                    {
                        //no more cards.
                    }

                    if (Bust)
                    {
                        WriteLine("Bust.");
                        ReadKey();
                        break;
                    }

                    if (Stick || BlackJack || i == 2)
                    {
                        WriteLine();
                        WriteLine("DEALER.");
                        dealer.DealerstartHand = d.DrawTwoFromDeck();
                        WriteLine(d.TwoCardHandToString(dealer.DealerstartHand));
                        WriteLine(d.CheckBlackJack(dealer.DealerstartHand));
                        for (int o = 0; o < 3; o++)
                        {
                            if (d.handCount(dealer.DealerstartHand, dealer.DealerextraCards) > 21)
                            {
                                WriteLine("Bust.");
                                break;
                            }
                            if (d.handCount(dealer.DealerstartHand, dealer.DealerextraCards) == 21)
                            {
                                WriteLine("Stick.");
                                break;
                            }
                            if (dealer.ShouldDraw(d.handCount(dealer.DealerstartHand, dealer.DealerextraCards)))
                            {
                                Card newCard = d.DrawFromDeck();
                                dealer.DealerextraCards[o] = newCard;
                                WriteLine($"{newCard},   {d.handCount(dealer.DealerstartHand, dealer.DealerextraCards)}");
                            }
                            else
                            {
                                WriteLine("Stick.");
                                break;
                            }
                            if (o == 2)
                            {
                                WriteLine("Stick.");
                            }
                        }

                        WriteLine();
                        WriteLine(d.Winner(hand, dealer));

                        ReadKey();
                        break;
                    }
                    
            }

        }
        }