Example #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("\n-------WELCOME TO WAR GAME-----------");

            Console.WriteLine("Enter Username: "******"\nName: {p1.name} Wins: {p1.wins} Losses: {p1.losses} Balance: {p1.balance}\n");

            DeckOfCards gameDeck = new DeckOfCards();

            Boolean keepPlaying = true;

            int handcount = 0;

            do
            {
                HandOfCards gameHand = new HandOfCards(5, gameDeck);
                handcount++;

                Boolean didwin = getCardsFromHand(gameHand);

                if (didwin == true)
                {
                    p1.wins    = p1.wins + 1;
                    p1.balance = p1.balance + 10;
                }
                else
                {
                    p1.losses  = p1.losses + 1;
                    p1.balance = p1.balance - 10;
                }

                // Update the players info after the battle

                updatePlayerFile(p1.name, p1.wins, p1.losses, p1.balance);

                Console.WriteLine("Updated:\nName: {0} Wins: {1} Losses: {2} Balance: {3}\n", p1.name, p1.wins, p1.losses, p1.balance);


                // Once theres 10 hands you need to create a new shuffled deck

                if (handcount == 10)
                {
                    gameDeck = new DeckOfCards();
                    gameDeck.shuffleDeck();
                    handcount = 0;
                }

                Console.WriteLine("-------Do you want to keep playing? [Y/N] ");
                String answer = Console.ReadLine();

                // if player answers no then stop the game

                if (answer == "N" || answer == "n")
                {
                    keepPlaying = false;
                }
            } while (keepPlaying == true && p1.balance > 0);

            // When the players balance = 0 end the game

            if (p1.balance <= 0)
            {
                Console.WriteLine("You are broke. YOU LOSE :((((((");
            }
        }