Advertisement
silvana1303

game number wars

Apr 25th, 2020
895
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.93 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Loops
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string namePlayer1 = Console.ReadLine();
  10.             string namePlayer2 = Console.ReadLine();
  11.  
  12.             string command = Console.ReadLine();
  13.             int playerCard1 = 0;
  14.             int playerCard2 = 0;
  15.  
  16.             int player1points = 0;
  17.             int player2points = 0;
  18.  
  19.             while (command != "End of game")
  20.             {
  21.                
  22.                 playerCard1 = int.Parse(command);
  23.                 playerCard2 = int.Parse(Console.ReadLine());
  24.  
  25.                 if (playerCard1 > playerCard2)
  26.                 {
  27.                     player1points += playerCard1 - playerCard2;
  28.                    
  29.                 }
  30.                 else if (playerCard2 > playerCard1)
  31.                 {
  32.                     player2points += playerCard2 - playerCard1;
  33.                    
  34.                 }
  35.                 else
  36.                 {
  37.                     Console.WriteLine("Number wars!");
  38.  
  39.                     int newCard1 = int.Parse(Console.ReadLine());
  40.                     int newCard2 = int.Parse(Console.ReadLine());
  41.  
  42.                     if (newCard1 > newCard2)
  43.                     {
  44.                         Console.WriteLine($"{namePlayer1} is winner with {player1points} points");
  45.                     }
  46.                     else
  47.                     {
  48.                         Console.WriteLine($"{namePlayer2} is winner with {player2points} points");
  49.                     }
  50.  
  51.                     break;
  52.                 }
  53.  
  54.                 command = Console.ReadLine();
  55.  
  56.                 if (command == "End of game")
  57.                 {
  58.                     Console.WriteLine($"{namePlayer1} has {player1points} points");
  59.                     Console.WriteLine($"{namePlayer2} has {player2points} points");
  60.                     break;
  61.                 }
  62.             }
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement