madeofglass

Untitled

Feb 18th, 2020
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.11 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _04.GameNumberWars
  4. {
  5.     class GameNumberWars
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string playerOne = Console.ReadLine();
  10.             string playerTwo = Console.ReadLine();
  11.  
  12.             string cardFirstPlayer = Console.ReadLine();
  13.             string cardSecondPlayer = "";
  14.  
  15.             int pointsOne = 0;
  16.             int pointsTwo = 0;
  17.  
  18.             int result = 0;
  19.  
  20.             string warCard1 = "";
  21.             string warCard2 = "";
  22.  
  23.             while (cardFirstPlayer != "End of game")
  24.             {
  25.                 cardSecondPlayer = Console.ReadLine();
  26.  
  27.                 int one = Convert.ToInt32(cardFirstPlayer);
  28.                 int two = Convert.ToInt32(cardSecondPlayer);
  29.  
  30.                 if (one > two)
  31.                 {
  32.                     result = one - two;
  33.                     pointsOne += result;
  34.                 }
  35.                 else if (one < two)
  36.                 {
  37.                     result = two - one;
  38.                     pointsTwo += result;
  39.                 }
  40.                 else if (one == two)
  41.                 {
  42.                     Console.WriteLine("Number wars!");
  43.                     warCard1 = Console.ReadLine();
  44.                     warCard2 = Console.ReadLine();
  45.  
  46.                     int war1 = Convert.ToInt32(warCard1);
  47.                     int war2 = Convert.ToInt32(warCard2);
  48.                     if (war1 > war2)
  49.                     {
  50.                         Console.WriteLine($"{playerOne} is winner with {pointsOne} points");
  51.                         break;
  52.                     }
  53.                     else
  54.                     {
  55.                         Console.WriteLine($"{playerTwo} is winner with {pointsTwo} points");
  56.                         break;
  57.                     }
  58.                 }
  59.                 cardFirstPlayer = Console.ReadLine();
  60.             }
  61.  
  62.             if (cardFirstPlayer == "End of game")
  63.             {
  64.                 Console.WriteLine($"{playerOne} has {pointsOne} points");
  65.                 Console.WriteLine($"{playerTwo} has {pointsTwo} points");
  66.             }
  67.         }
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment