Example #1
0
        static void Main(string[] args)
        {
            //Card c1, c2;

            Application.Run(new WarGUI());

            Game game = new Game();

            Deck p1 = new Deck();
            Deck p2 = new Deck();

            p1.PrintDeck();
            p2.PrintDeck();

            //Console.WriteLine(p1.Length());

            ConsoleKeyInfo key = Console.ReadKey();

            bool gameover = false;

            //while (key.Key == ConsoleKey.Y && !gameover)
            //{
            //    game.Turn(ref p1, ref p2);
            //    if (p1.IsEmpty() || p2.IsEmpty())
            //    {
            //        game.GameOver(ref gameover);
            //    }

            //    key = Console.ReadKey();
            //}
        }
Example #2
0
        public void Turn(ref Deck p1, ref Deck p2, Card p1Card, Card p2Card, out bool war)
        {
            war = false;
            //P1 wins
            if (p1Card > p2Card)
            {
                Console.WriteLine("Player one wins!");

                WinAdjust(ref p1, ref p2, p1Card, p2Card);
            }

            //P2 wins
            else if (p1Card < p2Card)
            {
                Console.WriteLine("Player two wins! ");

                WinAdjust(ref p2, ref p1, p2Card, p1Card);
            }



            //War -- same number on draw
            else
            {
                war = true;
                Console.WriteLine("**WAR!**");
                Console.WriteLine("");
                //Current cards on board
                p1wardeck = new List <Card>();
                p2wardeck = new List <Card>();

                //add current card to war deck
                p1wardeck.Add(p1Card);
                p2wardeck.Add(p2Card);

                p1.RemoveCard(p1Card);
                p2.RemoveCard(p2Card);

                //End loop when cards are not equal or a deck is empty
                while (p1Card == p2Card && !(p2.IsEmpty() || p1.IsEmpty()))
                {
                    //Flip next three cards, compare last one
                    for (int i = 0; i < 3; i++)
                    {
                        //If list has card, add to war deck and remove from normal deck
                        if (!p1.IsEmpty())
                        {
                            p1Card = p1.DrawCard();
                            p1wardeck.Add(p1Card);
                            p1.RemoveCard(p1Card);
                        }

                        if (!p2.IsEmpty())
                        {
                            p2Card = p2.DrawCard();
                            p2wardeck.Add(p2Card);
                            p2.RemoveCard(p2Card);
                        }
                    }
                }

                Console.WriteLine("Player one's war deck: ");
                for (int i = 0; i < p1wardeck.Count; i++)
                {
                    Console.WriteLine(p1wardeck[i]);
                }

                Console.WriteLine("");

                Console.WriteLine("Player two's war deck: ");
                for (int i = 0; i < p2wardeck.Count; i++)
                {
                    Console.WriteLine(p2wardeck[i]);
                }

                Console.WriteLine("");

                //p1 wins war
                if (p1Card > p2Card)
                {
                    Console.WriteLine("Player one wins!");
                    //get own cards back
                    for (int i = 0; i < p1wardeck.Count; i++)
                    {
                        p1.AddCard(p1wardeck[i]);
                    }

                    //take p2's cards
                    for (int i = 0; i < p2wardeck.Count; i++)
                    {
                        p1.AddCard(p2wardeck[i]);
                    }
                }

                //p2 wins war
                else
                {
                    Console.WriteLine("Player two wins!");
                    //get own cards back
                    for (int i = 0; i < p2wardeck.Count; i++)
                    {
                        p2.AddCard(p2wardeck[i]);
                    }

                    //take p1's cards
                    for (int i = 0; i < p1wardeck.Count; i++)
                    {
                        p2.AddCard(p1wardeck[i]);
                    }
                }
            }

            p1.PrintDeck();
            p2.PrintDeck();
        }