예제 #1
0
        static void Main(string[] args)
        {
            var humanPlayer = new Player();
            var aiDealer    = new Player();

            var game = new Game(humanPlayer, aiDealer);

            Console.WriteLine("Hello, Welcome to the casino!");
            NextAction nextAction;

            do
            {
                Console.WriteLine($"You currently at {game.GetPlayerHandValue()}");
                //TODO: Add some logic to show if it's a soft hand
                Console.WriteLine($"with the hand {game.GetPlayerHandAsString()}");
                Console.WriteLine("Hit or stay? (Hit = 1, Stay = 0)");
                nextAction = GetNextAction();
                if (nextAction == NextAction.Hit)
                {
                    game.Hit();
                }
            } while (!game.HumanPlayerIsBlackjack() && !game.HumanPlayerIsBust() && nextAction != NextAction.Stay);

            if (game.HumanPlayerIsBlackjack())
            {
                Console.WriteLine("Blackjack!");
                Console.WriteLine($"with the hand {game.GetPlayerHandAsString()}");
            }

            if (game.HumanPlayerIsBust())
            {
                Console.WriteLine("Bust!");
                Console.WriteLine($"with the hand {game.GetPlayerHandAsString()}");
            }
        }
예제 #2
0
        public static void Main(string[] args)
        {
            // Game setup
            // A game has a dealer, players and a shuffled deck
            // The dealer and all players have a hand
            var dealer = new Dealer()
            {
                name  = "Dealer",
                hands = new List <Hand>()
                {
                    new Hand()
                }
            };

            var players = new List <Player>()
            {
                new Player()
                {
                    name = "Player", hands = new List <Hand>()
                    {
                        new Hand()
                    }
                }
            };

            var game = new Game(players, dealer, 1);

            // Deal from top of deck to all players
            game.Deal();

            // Show the cards and current scores
            ShowCurrentGameState(game, false);

            // Wait for user input
            ConsoleKeyInfo userKey;

            do
            {
                userKey = Console.ReadKey(true);

                // Hit
                if (userKey.Key == ConsoleKey.H)
                {
                    game.Hit(players[0].hands[0]);
                    ShowCurrentGameState(game, false);
                }
                // Stand
                else if (userKey.Key == ConsoleKey.S)
                {
                    game.Stand(dealer.hands[0]);
                    RevealDealerCards(dealer);
                    ShowCurrentGameState(game, true);
                    Environment.Exit(0);
                }
            } while (userKey.Key != ConsoleKey.Escape);
        }
예제 #3
0
        static void Main(string[] args)
        {
            var game = new Game(new Deck());

            while (true)
            {
                Console.WriteLine("Hello");
                string cards = string.Empty;
                foreach (Card card in game.playerCards)
                {
                    cards += "[" + card.ToString() + "] ";
                }
                Console.WriteLine("Your cards are: " + cards);
                Console.WriteLine("Select either 'hit' or 'stand'");
                var input = Console.ReadLine();
                if (input == "hit")
                {
                    bool result = game.Hit(game.playerCards);
                    if (!result)
                    {
                        Console.WriteLine("You busted, and thus you suck. GG");
                        break;
                    }
                }
                else if (input == "stand")
                {
                    bool result = game.Stand();
                    if (result)
                    {
                        Console.WriteLine("You actually won. Wow, I guess you're not bad.");
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Well, the dealer busted. GG");
                        break;
                    }
                }
            }
            while (true)
            {
                System.Console.ReadKey();
            }
            ;
        }
예제 #4
0
        private void HitButton_Click(object sender, EventArgs e)
        {
            // очищаем label с тузом
            labelHasA.Text = "";

            blackjack.Hit(Game.PlayerCardsList);

            if (blackjack.PlayerHasA())         //если в картах игрока имеется туз
            {
                labelHasA.Text = "A(1 или 11)"; //выводим соотв текст
            }

            if (buttonSplit.Visible == true)
            {
                buttonSplit.Visible = false;
            }

            if (blackjack.IsOverflow()) //если перебор у игрока
            {
                // присуждаем победу дилеру, заканчиваем игру
                //dealersWinsText.Text = Statistic.GetDealerWins().ToString();
                info.Text           = "Победа дилера! Перебор у игрока";
                HitButton.Visible   = false;
                StandButton.Visible = false;
                //Проводим операции над картами дилера
                DealerCardsRemoveAndBackToStartPosition();
                DealerCardDraw();
                dealerScore.Text = blackjack.GetTotalDealer().ToString();
            }
            // записываем новую карту
            playerScore.Text = blackjack.GetTotalPlayer().ToString();

            textboxPlayerCards.Text = blackjack.PlayerCards;
            if (blackjack.GetTotalPlayer() == 21)
            {
                HitButton.Visible = false;
            }

            // При хите отрисововаем карты
            PlayerCardsRemoveAndBackToStartPosition(); //Очишаем лист с картами игрка !!Востанавливаем позицию появления карт игрока
            PlayerCardDraw();                          // Рисуем
        }