예제 #1
0
        public void Test_Turn()
        {
            var players = GetPlayers(
                new Card[]
            {
                new Card(CardSuit.Diamonds, 0),
                new Card(CardSuit.Diamonds, 2)
            },
                new Card[]
            {
                new Card(CardSuit.Diamonds, 1),
                new Card(CardSuit.Diamonds, 5),
                new Card(CardSuit.Clubs, 5)
            }
                );

            DurakGame game = new DurakGame(players, deck: null, CardSuit.Clubs);

            Assert.Throws <GameException>(() => game.Turn(0, new Card(CardSuit.Clubs, 0)));
            Assert.DoesNotThrow(() => game.Turn(0, new Card(CardSuit.Diamonds, 2)));
            Assert.That(game.Players[0].Hand.Count == 1);

            Assert.Throws <GameException>(() => game.Turn(0, new Card(CardSuit.Diamonds, 0)));
            Assert.Throws <GameException>(() => game.Turn(1, new Card(CardSuit.Diamonds, 1)));
            Assert.DoesNotThrow(() => game.Turn(1, new Card(CardSuit.Clubs, 5)));
        }
예제 #2
0
        static void MainLoop()
        {
            while (true)
            {
                Console.WriteLine("========================================================");
                SortHands();
                PrintHands();
                PrintAttacks();

                Console.WriteLine($"\nTrump: ---{game.Trump}---");
                Console.WriteLine($"Deck: {game.Deck.Count}");
                Console.WriteLine($"Defender: Player{game.DefenderIndex}\n");

                if (previousDefender != game.DefenderIndex)
                {
                    Console.WriteLine("--- NEW DEFENDER ---");
                    Console.WriteLine("--- NEW DEFENDER ---");
                    Console.WriteLine("--- NEW DEFENDER ---");
                    previousDefender = game.DefenderIndex;
                }

                int        playerId;
                PlayerRole role;
                do
                {
                    playerId = ReadInt("Select player", game.Players.Count);
                    role     = game.GetPlayerRole(playerId);
                }while (role == PlayerRole.None);

                Player player = game.Players[playerId];
                Console.WriteLine($"\nRole: {role}");
                Console.WriteLine($"Your hand:");
                PrintHand(playerId);

                int cardIndex = ReadInt("Card index", player.Hand.Count);

                Card card = player.Hand[cardIndex];
                IReadOnlyList <Card> unbeaten = game.Attacks.Unbeaten();

                if (role == PlayerRole.Attacker || unbeaten.Count < 2)
                {
                    Try(() => game.Turn(playerId, card));
                }
                else
                {
                    Console.WriteLine("Unbeaten cards:");

                    for (int i = 0; i < unbeaten.Count; i++)
                    {
                        Console.WriteLine($"{i}. {unbeaten[i]}");
                    }

                    int  targetIndex = ReadInt($"Select target", unbeaten.Count);
                    Card target      = unbeaten[targetIndex];

                    Try(() => game.Turn(playerId, card, target));
                }

                Console.WriteLine();
            }
        }
예제 #3
0
 public void Turn(int playerId, Card card, Card target)
 {
     _game.Turn(playerId, card, target);
 }