Advertisement
Guest User

Untitled

a guest
Dec 29th, 2013
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.44 KB | None | 0 0
  1.         public string playerChoice()
  2.         {
  3.             Console.WriteLine("Do you want to Attack or Defend?");
  4.             string playerchoice = Console.ReadLine();
  5.             return playerchoice;
  6.         }
  7.  
  8.         public void MonsterEncouter()
  9.         {
  10.             Random random = new Random();
  11.             int randomNumber = random.Next(1, 101);
  12.             int playerHealth = random.Next(50, 101);
  13.             int playerAttack = random.Next(10, 31);
  14.             string userInput = "";
  15.            
  16.  
  17.  
  18.             if (randomNumber >= 1 && randomNumber <= 24)
  19.             {
  20.                 Console.WriteLine("You've run into a goblin, an easy enemy");
  21.                 Console.WriteLine("Its HP is: " + randomNumber);
  22.                 Console.WriteLine("Your HP is: " + playerHealth);
  23.                 Console.WriteLine("Let the battle begin!");
  24.                 Console.ReadLine();
  25.             }
  26.             else if (randomNumber >= 25 && randomNumber <= 49)
  27.             {
  28.                 Console.WriteLine("You've run into a dire wolf, a bit tough enemy");
  29.                 Console.WriteLine("It's HP is: " + randomNumber);
  30.                 Console.WriteLine("Your HP is: " + playerHealth);
  31.                 Console.WriteLine("Let the battle begin!");
  32.                 Console.ReadLine();
  33.             }
  34.             else if (randomNumber >= 50 && randomNumber <= 74)
  35.             {
  36.                 Console.WriteLine("You've run into an orc, a hard enemy");
  37.                 Console.WriteLine("It's HP is: " + randomNumber);
  38.                 Console.WriteLine("Your HP is: " + playerHealth);
  39.                 Console.WriteLine("Let the battle begin!");
  40.                 Console.ReadLine();
  41.             }
  42.             else
  43.             {
  44.                 Console.WriteLine("You've run into a giant, a very hard enemy");
  45.                 Console.WriteLine("It's HP is: " + randomNumber);
  46.                 Console.WriteLine("Your HP is: " + playerHealth);
  47.                 Console.WriteLine("Let the battle begin!");
  48.                 Console.ReadLine();
  49.             }
  50.            
  51.             {
  52.                 userInput = playerChoice();
  53.                 if (userInput == "Attack")
  54.                 {
  55.                     while (userInput == "Attack" && playerHealth > 0 && randomNumber > 0)
  56.                     {
  57.                         Console.WriteLine("You attacked the beast!");
  58.                         Console.WriteLine("You've dealt " + playerAttack + " damage");
  59.                         randomNumber -= playerAttack;
  60.                         Console.WriteLine("It's HP is: " + randomNumber);
  61.                         Console.WriteLine();
  62.                         {
  63.                             Console.ReadLine();
  64.                             Console.WriteLine("It fought back! It dealt " + playerAttack);
  65.                             playerHealth -= playerAttack;
  66.                             Console.WriteLine("You have " + playerHealth + " HP left");
  67.                             Console.WriteLine();
  68.                             userInput = playerChoice();
  69.                         }
  70.                     }
  71.                     if (randomNumber <= 0)
  72.                     {
  73.                         Console.WriteLine();
  74.                         Console.WriteLine("The monster has been slain!");
  75.                         Console.WriteLine("Congratulations!");
  76.                         Console.ReadLine();
  77.                     }
  78.                     if (playerHealth <= 0)
  79.                     {
  80.                         Console.WriteLine();
  81.                         Console.WriteLine("You have been slain!");
  82.                         Console.WriteLine("You lose");
  83.                         Console.ReadLine();
  84.                     }
  85.                 }
  86.                 else if (userInput == "Defend")
  87.                 {
  88.                     while (userInput == "Defend" && playerHealth > 0 && randomNumber > 0)
  89.                     {
  90.                         Console.WriteLine("You are ready to defend!");
  91.                         Console.WriteLine("The monster attacked!");
  92.                         playerHealth -= 1;
  93.                         Console.WriteLine("You blocked it's attacked and only lost 1 HP");
  94.                         Console.WriteLine("You now have: " + playerHealth + " HP");
  95.                         Console.WriteLine();
  96.                         userInput = playerChoice();
  97.                         Console.ReadLine();
  98.                     }
  99.                 }
  100.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement