Advertisement
ilian_test

Untitled

Feb 25th, 2021
1,052
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.26 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. namespace ConsoleApp49
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int a = 0;
  11.             int health = 100;
  12.             int coins = 0;
  13.             // var input = "cat 100|potion 30|orc 10|chest 10|snake 25|chest 110";
  14.             var input = Console.ReadLine();
  15.              int count = input.Split(' ').Length;
  16.             for (int i = 0; i < count - 1; i++)
  17.             {
  18.                 a += 1;
  19.                 var output = Regex.Replace(input.Split("|")[i], @"[^0-9a-zA-Z\ ]+", "");
  20.  
  21.                 var item = Regex.Replace(output.Split()[0], @"[^0-9a-zA-Z\ ]+", "");
  22.  
  23.                 if (item == "potion")
  24.                 {
  25.                     var value = Regex.Replace(output.Split()[1], @"[^0-9a-zA-Z\ ]+", "");
  26.                     if (health <= 100)
  27.                     {
  28.                         int h = health;
  29.                         health += int.Parse(value);
  30.                         if (health >= 100)
  31.                         {
  32.                             if(h <= 100)
  33.                             {
  34.                                 Console.WriteLine("You healed for {0} hp.", 100 - h);
  35.                             }
  36.                             else
  37.                             {
  38.                                 Console.WriteLine("You healed for {0} hp.", 0);
  39.                             }
  40.                            
  41.  
  42.                             health = 100;
  43.                            
  44.                             Console.WriteLine("Current health: {0} hp.", health);
  45.                         }
  46.                         else
  47.                         {
  48.                             Console.WriteLine("You healed for {0} hp.", value);
  49.                             Console.WriteLine("Current health: {0} hp.", health);
  50.                         }
  51.                        
  52.  
  53.                     }
  54.                    
  55.  
  56.                 }
  57.                 else if (item == "chest")
  58.                 {
  59.                     var value = Regex.Replace(output.Split()[1], @"[^0-9a-zA-Z\ ]+", "");
  60.                     coins += int.Parse(value);
  61.                     Console.WriteLine("You found {0} bitcoins.", value);
  62.  
  63.                 }
  64.                 else
  65.                 {
  66.                     var value = Regex.Replace(output.Split()[1], @"[^0-9a-zA-Z\ ]+", "");
  67.                     health -= int.Parse(value);
  68.                     if (health > 0)
  69.                     {
  70.                         Console.WriteLine("You slayed {0}.", item);
  71.  
  72.                     }
  73.                     else if (health <= 0)
  74.                     {
  75.                         if(a == 0)
  76.                         {
  77.                             a += 1;
  78.                         }
  79.                         Console.WriteLine("You died! Killed by boss.");
  80.                         Console.WriteLine("Best room: {0}", a);
  81.                         break;
  82.                     }
  83.  
  84.  
  85.                 }
  86.                
  87.             }
  88.             if(a == count - 1)
  89.             {
  90.                 Console.WriteLine("You've made it!");
  91.                 Console.WriteLine("Bitcoins: {0}", coins);
  92.                 Console.WriteLine("Health: {0}", health);
  93.             }
  94.            
  95.         }
  96.     }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement