Ejemplo n.º 1
0
 public void NextGame()
 {
     if (active_game.GetScore() > 21)
     {
         active_game.status = Game.Statuses.TooMuch;
     }
     else
     {
         active_game.status = Game.Statuses.Quit;
     }
     if (active_game_num + 1 == games.Count)
     {
         hasActiveGames = false;
     }
     else
     {
         active_game_num++;
         active_game = games[active_game_num];
     }
 }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.OutputEncoding = System.Text.Encoding.UTF8;
            Console.WriteLine("Нажмите любую кнопку, чтобы начать игру");
            Console.ReadKey();

            Player player = new Player(1000);

            while (true)
            {
                Queue <Card> deck   = new Queue <Card>(Card.RandomDeck());
                Dealer       dealer = new Dealer(new List <Card>()
                {
                    deck.Dequeue(), deck.Dequeue()
                }, player, deck);
                Console.Clear();
                Console.WriteLine("Ваша ставка(денег на счету: " + player.money + "): ");
                int bet;
                while (true)
                {
                    if (int.TryParse(Console.ReadLine(), out bet) && bet > 0)
                    {
                        if (bet > player.money)
                        {
                            Console.WriteLine("У вас не хватает денег для такой ставки, попробуйте еще раз");
                        }
                        else
                        {
                            break;
                        }
                    }
                    else
                    {
                        Console.WriteLine("Вы ввели некорректное число");
                    }
                }

                player.money -= bet;
                player.NewGame(new Game(bet, new List <Card> {
                    deck.Dequeue(), deck.Dequeue()
                }));
                while (player.HasActiveGames())
                {
                    Game game = player.active_game;
                    PrintUserInformation(player);
                    PrintDealerInformation(dealer);
                    Actions action = GetAction(player, game);
                    if (action == Actions.Hit)
                    {
                        game.AddCart(deck.Dequeue());
                        PrintUserInformation(player);
                        if (game.status == Game.Statuses.TooMuch)
                        {
                            player.NextGame();
                        }
                    }
                    if (action == Actions.Quit)
                    {
                        player.NextGame();
                    }
                    if (action == Actions.Double)
                    {
                        player.money -= game.bet;
                        game.bet     *= 2;
                        game.AddCart(deck.Dequeue());
                        player.NextGame();
                    }
                    if (action == Actions.Split)
                    {
                        player.NewGame(new Game(new List <Card> {
                            game.cards[1]
                        }));
                        game.cards.RemoveAt(1);
                    }
                }
                dealer.Play();
                PrintUserInformation(player);
                PrintDealerInformation(dealer);
                Console.WriteLine("Итог раунда:");
                for (int i = 0; i < player.games.Count; i++)
                {
                    Game game = player.games[i];
                    int  score = game.GetScore(), dealerScore = dealer.GetScore();
                    Console.WriteLine("Рука #" + (i + 1) + ":");
                    if (game.status == Game.Statuses.Quit && dealer.status != Game.Statuses.TooMuch)
                    {
                        if (score > dealerScore)
                        {
                            Console.WriteLine("У вас больше, вы выиграли!");
                            player.money += game.bet * 2;
                        }
                        else if (score < dealerScore)
                        {
                            Console.WriteLine("У вас меньше, вы проиграли!");
                        }
                        else
                        {
                            Console.WriteLine("Ничья!");
                            player.money += game.bet;
                        }
                    }
                    if (game.status == Game.Statuses.Quit && dealer.status == Game.Statuses.TooMuch)
                    {
                        Console.WriteLine("У дилера перебор, вы выиграли!");
                        player.money += game.bet * 2;
                    }
                    if (game.status == Game.Statuses.TooMuch && dealer.status == Game.Statuses.Quit)
                    {
                        Console.WriteLine("У вас перебор!");
                    }
                    if (game.status == Game.Statuses.TooMuch && dealer.status == Game.Statuses.TooMuch)
                    {
                        Console.WriteLine("У вас и у дилера перебор, ничья!");
                        player.money += game.bet;
                    }
                }
                player.games = new List <Game>();
                Console.ReadKey();
            }
        }