Example #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Game of War Started");

            var deck   = new Deck();
            var rounds = 0;

            var player1 = new Player()
            {
                Hand = new List <Card>()
            };
            var player2 = new Player()
            {
                Hand = new List <Card>()
            };

            deck.Deal(player1, player2);

            while (player1.Hand.Count > 0 && player2.Hand.Count > 0)
            {
                var cardPot = new List <Card>(); //the pot holds the cards that go to the winner

                DetermineWinner(player1, player2, cardPot);

                Console.WriteLine($"   Game State: P1: {player1.Hand.Count} P2: {player2.Hand.Count} after {++rounds} rounds");

                if (rounds % 26 == 0)
                {
                    //Shuffle hands every 26 turns to prevent a rare situation where card order causes no winner
                    player1.Shuffle();
                    player2.Shuffle();
                }
            }

            if (player1.Hand.Count == player2.Hand.Count && player1.Hand.Count == 0)
            {
                Console.WriteLine("IT'S A DRAW!!"); //this only happens in rare cases when a war goes long enough that both players run out of cards
            }
            else if (player2.Hand.Count == 0)
            {
                Console.WriteLine($"Player 1 WINS!!");
            }
            else if (player1.Hand.Count == 0)
            {
                Console.WriteLine($"Player 2 WINS!!");
            }

            Console.ReadLine();
        }