Advertisement
Lyubohd

02. MuOnline

Jul 1st, 2020
1,200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.02 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Problem02
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string[] rooms = Console.ReadLine().Split("|");
  10.             int initialHealth = 100;
  11.             int initialBitcoins = 0;
  12.  
  13.             for (int i = 0; i < rooms.Length; i++)
  14.             {
  15.                 string[] tokens = rooms[i].Split();
  16.                 string command = tokens[0];
  17.                 int number = int.Parse(tokens[1]);
  18.  
  19.                 if ("potion" == command)
  20.                 {
  21.                     int value = 0;
  22.                     if (number + initialHealth <= 100)
  23.                     {
  24.                         value = number;
  25.                     }
  26.                     else
  27.                     {
  28.                         value = 100 - initialHealth;
  29.                     }
  30.                     initialHealth += value;
  31.                     Console.WriteLine($"You healed for {value} hp.");
  32.                     Console.WriteLine($"Current health: {initialHealth} hp.");
  33.                 }
  34.                 else if ("chest" == command)
  35.                 {
  36.                     initialBitcoins += number;
  37.                     Console.WriteLine($"You found {number} bitcoins.");
  38.                 }
  39.                 else
  40.                 {
  41.                     initialHealth -= number;
  42.                     if (initialHealth > 0)
  43.                     {
  44.                         Console.WriteLine($"You slayed {command}.");
  45.                     }
  46.                     else
  47.                     {
  48.                         Console.WriteLine($"You died! Killed by {command}.");
  49.                         Console.WriteLine($"Best room: {i + 1}");
  50.                         break;
  51.                     }
  52.                 }
  53.             }
  54.  
  55.             if (initialHealth > 0)
  56.             {
  57.                 Console.WriteLine("You've made it!");
  58.                 Console.WriteLine($"Bitcoins: {initialBitcoins}");
  59.                 Console.WriteLine($"Health: {initialHealth}");
  60.             }
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement