Esempio n. 1
0
        public static void Main()
        {
            var countPlayers = 2;
            var game         = new GameDurak(countPlayers);
            var players      = new List <Player>(countPlayers);

            for (int i = 1; i <= countPlayers; i++)
            {
                players.Add(new Player(i.ToString()));
                if (i >= 2)
                {
                    players[i - 1].IsBot = true;
                }
            }
            var table = new ConsoleTable(game, players);
        }
Esempio n. 2
0
        public void Take()
        {
            GameDurak.PlayersThrowOutCards();
            Game.counter++;

            foreach (var pairCards in Game.CardsPairsOnTable)
            {
                if (!(pairCards.LessCard is null))
                {
                    Hand.Add(pairCards.LessCard);
                }
                if (!(pairCards.LargerCard is null))
                {
                    Hand.Add(pairCards.LargerCard);
                }
            }

            Game.CardsPairsOnTable.Clear();
        }
Esempio n. 3
0
        public static void HandOutCards()
        {
            var flag = false; //нужен для того, чтобы дать последнему игроку, если это возможно, удалиться. (и получить ничью)

            while (true)
            {
                var number = 1;
                foreach (var player in Players)
                {
                    flag = true;
                    player.QueueNumber = number;
                    number++;

                    if (Deck.Cards.Count <= 0 && player.Hand.Count == 0)
                    {
                        GameDurak.AllowGoNextInQueue(player);
                        Players.Remove(player);
                        flag = false;
                        break;
                    }

                    while (player.Hand.Count < LimiterHandOutCards && Deck.Cards.Count > 0)
                    {
                        player.Hand.Add(Deck.Cards.Pop());
                    }
                }

                if (number == Players.Count + 1 && flag)
                {
                    if (Players.Count == 0)
                    {
                        IsDraw = true;
                    }
                    if (Players.Count == 1)
                    {
                        IsFool = true;
                    }
                    return;
                }
            }
        }
Esempio n. 4
0
        public ConsoleTable(GameDurak game, List <Player> players)
        {
            this.game = game;
            foreach (var player in players)
            {
                Game.TryConnect(player);
            }

            Game.StartGame();
            Console.WriteLine("\t\t\t The card game \"Durak\" has begun. Good Luck!");

            while (true)
            {
                if (Game.IsFool)
                {
                    break;
                }
                if (Game.IsDraw)
                {
                    break;
                }
                ShowPlayerCards();
                game.MakeMove();
                game.СhangeWhoseTurn();
            }

            Console.Clear();
            if (Game.IsDraw)
            {
                Console.WriteLine("Congratulations, you have a draw");
            }
            if (Game.IsFool)
            {
                Console.WriteLine($"Plaer {Game.Players[0].Name} is Fool");
            }
            Console.WriteLine("If you want to continue click ENTER");
            Console.ReadKey();
            Game.IsDraw = false;
            Game.IsFool = false;
            Program.Main();
        }