Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ProgrammingAssignment5
- {
- class Program
- {
- static void Main(string[] args)
- {
- // Create variables
- Random rand = new Random();
- char choice = 'y';
- Console.WriteLine("Welcome to WAR!\n");
- while (choice != 'N')
- {
- int playerOneWins = 0;
- int playerTwoWins = 0;
- string winner = null;
- // 21 battles
- for (int i = 0; i < 21; i++)
- {
- string result = "BATTLE:";
- int playerOne = rand.Next(14);
- int playerTwo = rand.Next(14);
- if (playerOne > playerTwo)
- {
- winner = "P1 Wins!";
- playerOneWins += 1;
- }
- else if (playerOne < playerTwo)
- {
- winner = "P2 Wins!";
- playerTwoWins += 1;
- }
- else
- {
- result = " WAR:";
- winner = null;
- playerOneWins += 1;
- playerTwoWins += 1;
- }
- Console.WriteLine(result + "\tP1:" + playerOne + "\tP2:" + playerTwo + "\t" + winner);
- }
- if (playerOneWins > playerTwoWins)
- {
- Console.WriteLine("\nP1 is the overall winner with " + playerOneWins + " battles!\n");
- }
- else if (playerOneWins < playerTwoWins)
- {
- Console.WriteLine("\nP2 is the overall winner with " + playerTwoWins + " battles!\n");
- }
- else
- {
- Console.WriteLine("\nA draw at WAR! in " + playerOneWins + " battles!\n");
- }
- Console.Write("Would you like to play a again (y/n): ");
- choice = char.Parse(Console.ReadLine().ToUpper());
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement