Esempio n. 1
0
        public bool Turn()
        {
            Dealer.ColumnPosition = 0;
            Console.SetCursorPosition(Dealer.ColumnPosition, 1);
            Console.Write(Dealer.Name);
            Player.ColumnPosition = 20;
            Console.SetCursorPosition(Player.ColumnPosition, 1);
            Console.Write(Player.Name);
            Player.PlayerBet();
            int  blackjack  = DealerInitialTurn();
            bool playerturn = true;

            if (blackjack == 21)
            {
                playerturn = false;
            }
            int playersum = PlayerTurn(playerturn);

            Console.SetCursorPosition(Dealer.ColumnPosition, 3);
            Console.ForegroundColor = Dealer.Hidden;
            Console.BackgroundColor = ConsoleColor.White;
            Console.Write(HiddenString);
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.BackgroundColor = ConsoleColor.Black;
            int dealersum = DealerTurn();

            ScreenOperations.ClearGameLine(0, 20, 34);
            Console.Write("{1}'s Card Sum is: {0}", playersum, Player.Name);
            ScreenOperations.ClearGameLine(0, 21, 34);
            Console.Write("{1}'s Card Sum is: {0}", dealersum, Dealer.Name);
            if ((dealersum > playersum && !dealerbust) || playerbust)
            {
                Player.Lost();
                if (playerbust)
                {
                    Console.WriteLine("You busted!");
                }
                Console.WriteLine();
            }
            else if (dealersum < playersum || dealerbust)
            {
                Player.Win();
            }
            else
            {
                Player.Tie();
            }
            Dealer.Sum             = 0;
            Player.Sum             = 0;
            Player.HighAce         = false;
            Dealer.HighAce         = false;
            dealerbust             = false;
            playerbust             = false;
            Dealer.CardRowPosition = 0;
            Player.CardRowPosition = 0;
            Deck.CardsNoLongerInPlay();
            bool correctinput     = false;
            int  choice           = 1;
            bool choiceNotSkipped = true;

            if (Player.Funds <= 0)
            {
                choice           = Player.LostTheGame();
                choiceNotSkipped = false;
            }
            else
            {
                ScreenOperations.ClearGameLine(0, 17, 48);
                Console.WriteLine("Continue playing? 1. Yes 2. No 3. NOOOOOO!!!");
                ScreenOperations.DebugView(player.ToString());
                while (!correctinput)
                {
                    try
                    {
                        ScreenOperations.ClearGameLine(0, 18, 31);
                        choice       = Int32.Parse(Console.ReadLine());
                        correctinput = true;
                    }
                    catch (FormatException)
                    {
                        ScreenOperations.ClearGameLine(0, 19, 34);
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("I asked for a number!");
                        Console.ForegroundColor = ConsoleColor.Gray;
                    }
                }
            }
            if (choiceNotSkipped)
            {
                ScreenOperations.ClearGameScreen();
            }
            switch (choice)
            {
            case 1:
                return(true);

            case 2:
                return(false);

            case 3:
                Console.WriteLine("Don't let it get to you...");
                return(false);

            default:
                Console.WriteLine("Provided Invalid Choice. Terminating...");
                return(false);
            }
        }
Esempio n. 2
0
        public int PlayerTurn(bool playerplay)
        {
            string s = Player.GetInitialCards(deck);

            Console.SetCursorPosition(Player.ColumnPosition, 3);
            Console.Write(s);
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.BackgroundColor = ConsoleColor.Black;
            int choice = 2;

            while (playerplay)
            {
                ScreenOperations.ClearGameLine(0, 15, 33);
                Console.WriteLine("Your current sum: {0}", player.Sum);
                Console.Write("1. Hit 2. Stay ");
                bool canDouble      = false;
                int  doubledBet     = player.Bet * 2;
                int  fundsBeforeBet = player.Bet + player.Funds;
                if (doubledBet <= fundsBeforeBet)
                {
                    Console.Write("3. Double");
                    canDouble = true;
                }
                Console.Write("               ");
                Console.SetCursorPosition(0, 17);
                bool choicenotmade = false;
                while (!choicenotmade)
                {
                    try
                    {
                        choice = Int32.Parse(Console.ReadLine());
                        if (choice == 3 && canDouble == false)
                        {
                            choicenotmade = false;
                        }
                        else
                        {
                            choicenotmade = true;
                        }
                    }
                    catch (FormatException)
                    {
                        ScreenOperations.ClearGameLine(0, 18, 33);
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.Write("Not digit 1, 2, or 3...");
                        Console.ForegroundColor = ConsoleColor.Gray;
                        ScreenOperations.ClearGameLine(0, 17, 28);
                    }
                }
                switch (choice)
                {
                case 1:
                    player.GetCard(deck);
                    if (Player.Sum > 21)
                    {
                        playerplay = false;
                        playerbust = true;
                    }
                    break;

                case 2:
                    playerplay = false;
                    break;

                case 3:
                    player.Funds -= player.Bet;
                    player.Bet   *= 2;
                    ScreenOperations.DebugView(player.ToString());
                    player.GetCard(deck);
                    playerplay = false;
                    if (Player.Sum > 21)
                    {
                        playerbust = true;
                    }
                    break;
                }
                ScreenOperations.DebugView(player.ToString());
                ScreenOperations.ClearGameLine(0, 18, 29);
            }
            return(Player.Sum);
        }
Esempio n. 3
0
        public void PlayerBet()
        {
            ScreenOperations.ClearGameLine(0, 15, 43);
            string betText = ($"You have ${Funds}. Bet: ");

            Console.Write(betText, Funds);
            OriginalFunds = Funds; // For debugging
            int  cursorPosition  = betText.Length;
            bool possibleBet     = false;
            bool formatexception = false;

            while (!possibleBet)
            {
                try
                {
                    Bet             = Int32.Parse(Console.ReadLine());
                    formatexception = false;
                }
                catch (FormatException)
                {
                    formatexception = true;
                    ScreenOperations.ClearGameLine(0, 16, 45);
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Write("You can only bet with digits!");
                    Console.ForegroundColor = ConsoleColor.Gray;
                    ScreenOperations.ClearGameLine(cursorPosition, 15, 23);
                }
                catch (OverflowException)
                {
                    formatexception = true;
                    ScreenOperations.ClearGameLine(0, 16, 45);
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Write("This bet is too large (and you don't have those funds anyhow)!");
                    Console.ForegroundColor = ConsoleColor.Gray;
                    ScreenOperations.ClearGameLine(cursorPosition, 15, 23);
                }
                if (Bet > Funds && !formatexception)
                {
                    Console.SetCursorPosition(0, 16);
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("You can't spend money you don't have!");
                    Console.ForegroundColor = ConsoleColor.Gray;
                    ScreenOperations.ClearGameLine(cursorPosition, 15, 11);
                }
                else if (Bet < 0)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("You can't bet a negative amount!");
                    Console.ForegroundColor = ConsoleColor.Gray;
                    ScreenOperations.ClearGameLine(cursorPosition, 15, 25);
                }
                else if (!formatexception)
                {
                    Console.SetCursorPosition(0, 16);
                    Console.WriteLine("                                     ");
                    possibleBet = true;
                }
            }
            OriginalBet = Bet; // For Debugging
            Funds      -= Bet;
            ScreenOperations.DebugView(ToString());
        }