Create a console-based computerized game of War named WarCardGameConsole in the Final Project Part 1 folder. This is C#
1. Use an array of 52 integers to store unique values for each card.
2. Write a method named FillDeck() that places 52 unique values into this array.
3. Write another method named SelectCard() that you call twice on each deal to randomly
select a unique card for each player, with no repetition of cards in 26 deals.
4. To pause the play between each dealt hand, use a call to ReadLine().
5. At the end of a play of the game of the 26 deals:
a. display the Computer’s and Player’s final scores
b. display who won the game
c. record the results in a text file (see step 6)
d. give the player the choice of stopping or playing again.
6. Record the results of each game in a text file:
a. The text file should be saved as FirstNameLastName Results.txt in your project
folder. The file will automatically save in WarCardGameConsole\bin\Debug folder.
b. At the beginning of your program you should check to see if your file exists;
 If not, your program will create it
 If it does exist, you program will open it.
c. At the of a play of the game you will record the results
d. When the player indicates they want to stop playing, the program should close the
file.
7. Your program must have meaningful comments, including your name.

Answers

Answer 1

Answer:

Here is a console-based C# program for the card game War:

Explanation:

using System;

using System.IO;

namespace WarCardGameConsole

{

   class WarCardGame

   {

       // Array to hold 52 cards

       int[] deck = new int[52];

       // Player and computer scores

       int playerScore;

       int computerScore;

       // File to record results

       StreamWriter results;

       // Fill deck with cards

       void FillDeck()

       {

           // Add cards to deck

           for (int i = 0; i < deck.Length; i++)

           {

               deck[i] = i;

           }

       }

       // Select random card

       int SelectCard()

       {

           // Generate random index

           Random rand = new Random();

           int index = rand.Next(deck.Length);

           // Remove selected card from deck

           int card = deck[index];

           deck[index] = deck[deck.Length - 1];

           Array.Resize(ref deck, deck.Length - 1);

           // Return selected card

           return card;

       }

       // Play one round of war

       void PlayRound()

       {

           // Select cards for player and computer

           int playerCard = SelectCard();

           int computerCard = SelectCard();

           // Display cards

           Console.WriteLine($"Player card: {playerCard}  Computer card: {computerCard}");

           // Check who has higher card

           if (playerCard > computerCard)

           {

               playerScore++;

               Console.WriteLine("Player wins this round!");

           }

           else if (computerCard > playerCard)

           {

               computerScore++;

               Console.WriteLine("Computer wins this round!");

           }

           else

           {

               Console.WriteLine("Tie! No points awarded.");

           }

           // Pause before next round

           Console.WriteLine("Press any key to continue...");

           Console.ReadKey();

       }

       void PlayGame()

       {

           // Fill deck with cards

           FillDeck();

           // Play 26 rounds

           for (int i = 0; i < 26; i++)

           {

               PlayRound();

           }

           // Display final scores

           Console.WriteLine($"Player final score: {playerScore}");

           Console.WriteLine($"Computer final score: {computerScore}");

           // Determine winner

           if (playerScore > computerScore)

           {

               Console.WriteLine("Player wins the game!");

           }

           else if (computerScore > playerScore)

           {

               Console.WriteLine("Computer wins the game!");

           }

           else

           {

               Console.WriteLine("Tie game!");

           }

           // Record results in file

           results.WriteLine($"{DateTime.Now} - {playerScore} to {computerScore}");

           // Play again?

           Console.Write("Play again? (Y/N) ");

           string input = Console.ReadLine();

           if (input.ToUpper() == "Y")

           {

               // Restart game

               playerScore = 0;

               computerScore = 0;

               PlayGame();

           }

           else

           {

               // Close file and exit

               results.Close();

               Environment.Exit(0);

           }

       }

       static void Main(string[] args)

       {

           // Create game object

           WarCardGame game = new WarCardGame();

           // Check if results file exists

           if (!File.Exists("JohnDoe Results.txt"))

           {

               // Create file

               game.results = File.CreateText("JohnDoe Results.txt");

           }

           else

           {

               // Open existing file

               game.results = File.AppendText("JohnDoe Results.txt");

           }

           // Play game

           game.PlayGame();

       }

   }

}


Related Questions

Other Questions
A physicist's right eye is presbyopic (i.e., farsighted). This eye can see clearly only beyond a distance of 88 cm, which makes it difficult for the physicist to read books and journals. Find the focal length and power of a lens that will correct this presbyopia for a reading distance of 25 cm, when worn 2 cm in front of the eye. The official unemployment rate reported by the government may tend to understate the amount of unemployment because it: includes discouraged workers. excludes teenagers. includes people over 65 who aren't retired. excludes discouraged workers. Throughout the play, Brutus and Cassius have been foils (contrasting characters). What are the issues that cause them to quarrel in their dialogue, or conversation in Scene Three You are fighting to get Congress and the Supreme Court to agree that there is a right to travel. Which part of the constitution would be your best support The anxiety that people often experience when they move from a familiar culture to one that is entirely different is known as Describe two differences between the epididymis and the seminiferous tubules. One functional difference between the two, and one histological difference. Piaget's conservation-of-liquid task demonstrates that preoperational children's thinking is characterized by __________ in that they focus on one aspect of a situation, neglecting other important features. By how many hertz is the frequency of the sound produced by the lower note lower than the frequency of the combined sound Over time, observations in atmospheric carbon dioxide concentrations demonstrate seasonal variations. The seasonal variations in levels of CO2 are caused by CDB stock is currently priced at $74. The company will pay a dividend of $4.33 next year and investors require a return of 10.5 percent on similar stocks. What is the dividend growth rate on this stock QUESTION 2: The Dlamini household uses a prepaid electricity system where they have to buy electricity and type in a code to load the units. When they bought the electricity they started with 165,43 kWh and after typing in the code they had 532,56 kWh. Remember that 1 kWh = 1 unit "They live in a house that has a value of R 750 000 so therefor do not have a fixed monthly charge. Use the following table and answer the questions that follow: ELECTRICITY TARIFFS FOR DOMESTIC TARIFF (Properties worth > R 400 000 & < R1 000 000) BLOCKS ELECTRICITY RATE (c/kWh) 229,00 c/kWh 278,46 c/kWh BLOCK 1 0-600 kWh BLOCK 2 > 600 kWh a) How many units of electricity did the Dlamini household buy? b) Write an equation to calculate the cost of purchasing between 0-600 kWh of units. c) Use this equation and calculate how they paid for the amount of units calculated in a). The symmetric-key encryption method: Multiple Choice uses the same key for both senders and receivers for encryption and decryption. solves problems in key distribution and key management. is not appropriate for encrypting large data sets. is slow. which of the following is not a pythagorean triple? a. (6,8,10)b.(4,6,7)c.(5,12,13)d.(9,12,15) Hannah owns a house, a car, furniture, and a few valuable art pieces that she acquired while traveling in Europe. However, she also has a mortgage, a car loan, and student loan debt. Using her personal balance sheet, she determines that the total value of her personal assets is $350,000 and the total value of her unpaid debts is $200,000. Based on these numbers, what is her personal net worth Pharoah Airlines is considering two alternatives for the financing of a purchase of a fleet of airplanes. These two alternatives are: An electromagnetic wave in vacuum has an electric field amplitude of 365 V/m. Calculate the amplitude of the corresponding magnetic field. Kellan wants to shop at Express for the new school year, but because all of his friends shop at Pacific Sun, Kellan does as well. Kellan's behavior is an example of: sociology Mechanical energy is conserved when a system is _______. Select all that apply. isolated in equilibrium an inertial reference frame nondissipative Mechanical energy is never conserved If a gain of $11500 is incurred in selling (for cash) office equipment having a book value of $100000, the total amount reported in the cash flows from investing activities section of the statement of cash flows is In the course of the experiment, three seedlings begin to grow in the paper cups. What caused the seedlings to sprout out of the bean, grain, and daisy seed