Exemple #1
0
        static void Main(string[] args)
        {
            Console.SetWindowSize(80, 20);

            Console.WriteLine("================================================================================" +
                              "||                     Welcome to the game of War!                            ||" +
                              "||                                                                            ||" +
                              "|| HOW TO PLAY:                                                               ||" +
                              "|| + Each of the two players is dealt one half of a shuffled deck of cards.   ||" +
                              "|| + Each turn, each player draws one card from their decks.                  ||" +
                              "|| + The player that drew the card with higher value gets both cards.         ||" +
                              "|| + Winning cards return to the winner's deck and get reshuffled.            ||" +
                              "|| + If there is a draw, the cards are thrown away.                           ||" +
                              "||                                                                            ||" +
                              "|| HOW TO WIN:                                                                ||" +
                              "|| + The player that is runs out of cards first, wins.                        ||" +
                              "||                                                                            ||" +
                              "|| CONTROLS:                                                                  ||" +
                              "|| + Press enter in order to draw a new card.                                 ||" +
                              "||                                                                            ||" +
                              "||                              Have fun!                                     ||" +
                              "================================================================================");

            // Game loop
            while (true)
            {
                int totalMoves = 0;

                // Generate deck
                WarDeck mainDeck = new WarDeck();
                mainDeck.generateDeck();
                //mainDeck.shuffleDeck ();

                // Split deck into 2 (1 for each player)
                WarDeck playerDeck   = new WarDeck();
                WarDeck computerDeck = new WarDeck();

                bool toggle = false;

                foreach (WarCard card in mainDeck.stack)
                {
                    if (toggle)
                    {
                        playerDeck.stack.Add(card);
                    }
                    else
                    {
                        computerDeck.stack.Add(card);
                    }
                    toggle = !toggle;
                }

                // Draw loop
                while (!playerDeck.isEmpty() && !computerDeck.isEmpty())
                {
                    Console.ReadLine();

                    // Each player draws a card
                    WarCard playerDraw   = (WarCard)playerDeck.drawCard();
                    WarCard computerDraw = (WarCard)computerDeck.drawCard();
                    totalMoves++;

                    Console.WriteLine("Player has drawn: {0} of {1}.\n", playerDraw.face, playerDraw.suite);
                    Console.WriteLine("Computer has drawn: {0} of {1}.\n\n", computerDraw.face, computerDraw.suite);

                    if ((int)playerDraw.face > (int)computerDraw.face)
                    {
                        Console.WriteLine("The Player has won the cards.\nThe cards have been placed in your deck.\n\n");
                        playerDeck.placeInDeck(playerDraw, computerDraw);
                    }
                    else if ((int)playerDraw.face < (int)computerDraw.face)
                    {
                        Console.WriteLine("The Computer has won the cards.\nThe cards have been placed in the computer's deck.\n\n");
                        computerDeck.placeInDeck(playerDraw, computerDraw);
                    }
                    else
                    {
                        Console.WriteLine("It's a draw!\n\n");
                    }

                    Console.WriteLine("================================================================================" +
                                      "================================================================================");
                }

                if (playerDeck.isEmpty())
                {
                    Console.WriteLine("After a total of {0} moves, the player has won!\n\n", totalMoves);
                }
                else
                {
                    Console.WriteLine("After a total of {0} moves, the computer has won!\n\n", totalMoves);
                }

                string line;
                do
                {
                    Console.WriteLine("Would you like to play again?\nIf yes, type 'y'. If not, type 'n'.\n");
                    line = Console.ReadLine();
                } while (line != "n" && line != "y");

                if (line == "n")
                {
                    break;
                }
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to the Big Bellies War Game!");
            Console.WriteLine("HOW TO PLAY:");
            Console.WriteLine("Each of the two players is dealt one half of a shuffled deck of cards.");
            Console.WriteLine("Each turn, each player draws one card from their decks. ");
            Console.WriteLine("The player that drew the card with higher value gets both cards.");
            Console.WriteLine("If there is a draw, they place another 3 cards and compare the 4th card.  If a draw happens again, the cards are put back into each players deck.");
            Console.WriteLine("HOW TO WIN:");
            Console.WriteLine("The player that gets all of cards first, wins.");
            Console.WriteLine("Press enter in order to draw a new card.");
            string name1;
            string name2;

            Console.WriteLine("Player1, Enter your name: ");
            name1 = Console.ReadLine();
            Console.WriteLine("Player2, Enter your name: ");
            name2 = Console.ReadLine();
            Console.WriteLine("Press enter, to begin the game!");

            Player player1 = new Player(name1);
            Player player2 = new Player(name2);

            // Game loop
            while (true)
            {
                int totalMoves = 0;

                // Generate deck
                WarDeck mainDeck = new WarDeck();
                mainDeck.generateDeck();
                //mainDeck.shuffleDeck ();

                // Split deck into 2 (1 for each player)
                WarDeck player1Deck = new WarDeck();
                WarDeck player2Deck = new WarDeck();

                bool toggle = false;

                foreach (WarCard card in mainDeck.stack)
                {
                    if (toggle)
                    {
                        player1Deck.stack.Add(card);
                    }
                    else
                    {
                        player2Deck.stack.Add(card);
                    }
                    toggle = !toggle;
                }

                // Draw loop
                while (!player1Deck.isEmpty() && !player2Deck.isEmpty())
                {
                    Console.ReadLine();

                    // Each player draws a card
                    WarCard player1Draw = (WarCard)player1Deck.drawCard();
                    WarCard player2Draw = (WarCard)player2Deck.drawCard();
                    totalMoves++;

                    Console.WriteLine(player1.name + " has drawn: {0} of {1}.\n", player1Draw.face, player1Draw.suite);
                    Console.WriteLine(player2.name + " has drawn: {0} of {1}.\n\n", player2Draw.face, player2Draw.suite);

                    if ((int)player1Draw.face > (int)player2Draw.face)
                    {
                        Console.WriteLine("The " + player1.name + " has won the cards.\nThe cards have been placed in your deck.\n\n");
                        player1Deck.placeInDeck(player1Draw, player2Draw);
                    }
                    else if ((int)player1Draw.face < (int)player2Draw.face)
                    {
                        Console.WriteLine("The " + player2.name + " has won the cards.\nThe cards have been placed in the player2's deck.\n\n");
                        player2Deck.placeInDeck(player1Draw, player2Draw);
                    }
                    else
                    {
                        Console.WriteLine("It's a draw!\nLet's play War. You need to place 3 cards at one time and compare the 4th card.");
                        WarCard player1Draw1 = (WarCard)player1Deck.drawCard();
                        WarCard player1Draw2 = (WarCard)player1Deck.drawCard();
                        WarCard player1Draw3 = (WarCard)player1Deck.drawCard();
                        WarCard player1Draw4 = (WarCard)player1Deck.drawCard();
                        WarCard player2Draw1 = (WarCard)player2Deck.drawCard();
                        WarCard player2Draw2 = (WarCard)player2Deck.drawCard();
                        WarCard player2Draw3 = (WarCard)player2Deck.drawCard();
                        WarCard player2Draw4 = (WarCard)player2Deck.drawCard();
                        if ((int)player1Draw4.face > (int)player2Draw4.face)
                        {
                            Console.WriteLine("The " + player1.name + " has won the cards.\nThe 8 cards have been placed in your deck.\n\n");
                            player1Deck.place8InDeck(player1Draw4, player1Draw2, player1Draw3, player1Draw4, player2Draw4, player2Draw2, player2Draw3, player2Draw4);
                        }
                        else if ((int)player1Draw4.face < (int)player2Draw4.face)
                        {
                            Console.WriteLine("The " + player2.name + " has won the cards.\nThe 8 cards have been placed in your deck.\n\n");
                            player2Deck.place8InDeck(player1Draw4, player1Draw2, player1Draw3, player1Draw4, player2Draw4, player2Draw2, player2Draw3, player2Draw4);
                        }
                        else
                        {
                            Console.WriteLine("It's a draw again!\nLet's throw the cards and restart ");
                        }
                    }

                    Console.WriteLine("================================================================================" +
                                      "================================================================================");
                }

                if (player1Deck.isEmpty())
                {
                    Console.WriteLine("After a total of {0} moves, the " + player2.name + " has won!\n\n", totalMoves);
                }
                else
                {
                    Console.WriteLine("After a total of {0} moves, the " + player1.name + " won!\n\n", totalMoves);
                }

                string line;
                do
                {
                    Console.WriteLine("Would you like to play again?\nIf yes, type 'y'. If not, type 'n'.\n");
                    line = Console.ReadLine();
                } while (line != "n" && line != "y");

                if (line == "n")
                {
                    break;
                }
            }
        }