Advertisement
Stephen_MS

03. Primitive Data Types and Varible; 16: Basket Battle

Nov 3rd, 2015
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.95 KB | None | 0 0
  1. using System;
  2.  
  3. class BasketBattle
  4. {
  5.     static void Main()
  6.     {
  7.         // basket Battle
  8.  
  9.         //initializing variables and basic settings
  10.         Console.WriteLine("Enter a name of the player that starts shooting first in first round");
  11.         Console.Write("\"Simeon\" or \"Nakov\": ");
  12.         string F = Console.ReadLine();  // F -> who shoot first round
  13.         F = F.ToLower();
  14.         Console.Write("\nNumber of rounds in the game: [1...20] ");
  15.         int N = int.Parse(Console.ReadLine());    // N -> number of rounds
  16.         Console.WriteLine();
  17.         int roundCurrent = 0;
  18.         double roundHalf = 0.0;
  19.         int playerTurn;  // 1 - Simeon, 2 - Nakov
  20.         if (F == "simeon")
  21.         {
  22.             playerTurn = 1;
  23.         }
  24.         else
  25.         {
  26.             playerTurn = 2;
  27.         }
  28.         int P;      // amounts of pts every player tries to score
  29.         string I;   // success or fail
  30.         int player1Simeon = 0;    // Simeon's actual pts
  31.         int player2Nakov = 0;     // Nakov's actual pts
  32.  
  33.         // real game
  34.         do
  35.         {
  36.             Console.Write("Round {0}: ", roundCurrent+1);
  37.             if (playerTurn == 1)
  38.             {
  39.                 Console.WriteLine("Simeon's turn");
  40.             }
  41.             else
  42.             {
  43.                 Console.WriteLine("Nakov's turn");
  44.             }
  45.             Console.Write("how many points: [1...500] ");
  46.             P = int.Parse(Console.ReadLine());
  47.             Console.Write("\nsuccess or fail: ");
  48.             I = Console.ReadLine();
  49.             Console.WriteLine();
  50.             if (I == "success")
  51.             {
  52.                 if (playerTurn == 1)
  53.                 {
  54.                     player1Simeon += P;
  55.                     if (player1Simeon > 500)
  56.                     {
  57.                         player1Simeon -= P;
  58.                     }
  59.                 }
  60.                 else
  61.                 {
  62.                     player2Nakov += P;
  63.                     if (player2Nakov > 500)
  64.                     {
  65.                         player2Nakov -= P;
  66.                     }
  67.                 }
  68.             }
  69.  
  70.             roundHalf += 0.5;
  71.             if (roundHalf == Math.Round(roundHalf))
  72.             {
  73.                 roundCurrent++;
  74.                
  75.             }
  76.             else
  77.             {
  78.                 playerTurn = 3 - playerTurn;
  79.             }
  80.            
  81.         }
  82.         while ((roundCurrent < N) && (player1Simeon != 500) && (player2Nakov != 500));
  83.  
  84.         //printing the results: final score
  85.         if (roundCurrent < N)  // there is a winner
  86.         {
  87.             if (player1Simeon == 500)
  88.             {
  89.                 Console.WriteLine("The winner is Simeon");
  90.                 Console.WriteLine("player won the game in {0} rounds", roundCurrent);
  91.                 Console.WriteLine("Nakov lost with {0} pts", player2Nakov);
  92.             }
  93.             else
  94.             {
  95.                 Console.WriteLine("The winner is Nakov");
  96.                 Console.WriteLine("player won the game in {0} round", roundCurrent);
  97.                 Console.WriteLine("Simeon lost with {0} pts", player1Simeon);
  98.             }
  99.         }
  100.  
  101.         if ((roundCurrent == N) && (player1Simeon == player2Nakov))
  102.         {
  103.             Console.WriteLine("DRAW");
  104.             Console.WriteLine("players have {0} pts", player1Simeon);
  105.         }
  106.         else
  107.         {
  108.             if (roundCurrent == N)
  109.             {
  110.                 if (player1Simeon > player2Nakov)
  111.                 {
  112.                     Console.WriteLine("Simeon have more pts");
  113.                     Console.WriteLine("the difference between players is: {0} pts", player1Simeon - player2Nakov);
  114.                 }
  115.                 else
  116.                 {
  117.                     Console.WriteLine("Nakov have more pts");
  118.                     Console.WriteLine("the difference between players is: {0} pts", player2Nakov - player1Simeon);
  119.                 }
  120.             }
  121.         }
  122.     }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement