Advertisement
Guest User

WAR!

a guest
Oct 17th, 2013
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.26 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ProgrammingAssignment5
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             // Create variables
  13.             Random rand = new Random();
  14.             char choice = 'y';
  15.  
  16.             Console.WriteLine("Welcome to WAR!\n");
  17.  
  18.             while (choice != 'N')
  19.             {
  20.                 int playerOneWins = 0;
  21.                 int playerTwoWins = 0;
  22.                 string winner = null;
  23.  
  24.                 // 21 battles
  25.                 for (int i = 0; i < 21; i++)
  26.                 {
  27.                     string result = "BATTLE:";
  28.                     int playerOne = rand.Next(14);
  29.                     int playerTwo = rand.Next(14);
  30.  
  31.                     if (playerOne > playerTwo)
  32.                     {
  33.                         winner = "P1 Wins!";
  34.                         playerOneWins += 1;
  35.                     }
  36.                     else if (playerOne < playerTwo)
  37.                     {
  38.                         winner = "P2 Wins!";
  39.                         playerTwoWins += 1;
  40.                     }
  41.                     else
  42.                     {
  43.                         result = "   WAR:";
  44.                         winner = null;
  45.                         playerOneWins += 1;
  46.                         playerTwoWins += 1;
  47.                     }
  48.                     Console.WriteLine(result + "\tP1:" + playerOne + "\tP2:" + playerTwo + "\t" + winner);
  49.                 }
  50.  
  51.                 if (playerOneWins > playerTwoWins)
  52.                 {
  53.                     Console.WriteLine("\nP1 is the overall winner with " + playerOneWins + " battles!\n");
  54.                 }
  55.                 else if (playerOneWins < playerTwoWins)
  56.                 {
  57.                     Console.WriteLine("\nP2 is the overall winner with " + playerTwoWins + " battles!\n");
  58.                 }
  59.                 else
  60.                 {
  61.                     Console.WriteLine("\nA draw at WAR! in " + playerOneWins + " battles!\n");
  62.                 }
  63.  
  64.                 Console.Write("Would you like to play a again (y/n): ");
  65.                 choice = char.Parse(Console.ReadLine().ToUpper());
  66.                 Console.WriteLine();
  67.             }
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement