Advertisement
Guest User

Mu online

a guest
Mar 2nd, 2020
2,063
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.53 KB | None | 0 0
  1. using System;
  2.  
  3. namespace MidExam
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string[] rooms = Console.ReadLine().Split('|');
  10.  
  11.  
  12.             int health = 100;
  13.             int bitcoins = 0;
  14.  
  15.             int currHealth = 0;
  16.             int tempHealth = 0;
  17.             bool notDead = true;
  18.             for (int i = 0; i < rooms.Length; i++)
  19.             {
  20.                 int currBitcoins = 0;
  21.                 string command = rooms[i];
  22.                 string[] splitted = command.Split();
  23.                 if (splitted[0] == "potion")
  24.                 {
  25.                     currHealth = health;
  26.                     tempHealth = health;
  27.                     currHealth += int.Parse(splitted[1]);
  28.                     if (currHealth <= 100)
  29.                     {
  30.                         health += int.Parse(splitted[1]);
  31.                         Console.WriteLine($"You healed for {splitted[1]} hp.");
  32.                         Console.WriteLine($"Current health: {health} hp.");
  33.                     }
  34.  
  35.                     else if (currHealth > 100)
  36.                     {
  37.                         int diff = 100 - tempHealth;
  38.                         health = 100;
  39.                         Console.WriteLine($"You healed for {diff} hp.");
  40.                         Console.WriteLine($"Current health: {health} hp.");
  41.                     }
  42.  
  43.                 }
  44.                 else if (splitted[0] == "chest")
  45.                 {
  46.                     bitcoins += int.Parse(splitted[1]);
  47.                     currBitcoins += int.Parse(splitted[1]);
  48.                     Console.WriteLine($"You found {currBitcoins} bitcoins.");
  49.  
  50.                 }
  51.                 else
  52.                 {
  53.                     int attack = int.Parse(splitted[1]);
  54.                     health -= attack;
  55.                     if (health <= 0)
  56.                     {
  57.                         Console.WriteLine($"You died! Killed by {splitted[0]}.");
  58.                         Console.WriteLine($"Best room: {i+1}");
  59.                         notDead = false;
  60.                         break;
  61.                     }
  62.                     else
  63.                     {
  64.                         Console.WriteLine($"You slayed {splitted[0]}.");
  65.                     }
  66.                 }
  67.             }
  68.             if (notDead)
  69.             {
  70.                 Console.WriteLine("You've made it!");
  71.                 Console.WriteLine($"Bitcoins: {bitcoins}");
  72.                 Console.WriteLine($"Health: {health}");
  73.             }
  74.  
  75.         }
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement