Advertisement
nikolayneykov

Untitled

Mar 7th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.87 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _02DungeonestDark
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int health = 100;
  11.             int coins = 0;
  12.  
  13.             string[] dungeonsRoom = Console.ReadLine().Split('|').ToArray();
  14.  
  15.             for (int i = 0; i < dungeonsRoom.Length; i++)
  16.             {
  17.                 string[] currentRoom = dungeonsRoom[i].Split().ToArray();
  18.                 string content = currentRoom[0];                    //съдържанието в стаята
  19.                 int number = int.Parse(currentRoom[1]);             //стойността в стаята
  20.  
  21.                 if (content == "potion")                            //ако намерим potion
  22.                 {
  23.                     int currentHealth = health;
  24.                     health += number;
  25.                     if (health > 100)
  26.                     {
  27.                         Console.WriteLine($"You healed for {100 - currentHealth} hp.");
  28.                         Console.WriteLine($"Current health: 100 hp.");
  29.                         health = 100;
  30.                     }
  31.                     else //ако кръвта е под 100
  32.                     {
  33.                         Console.WriteLine($"You healed for {number} hp."); //хилваме се само с Number
  34.                         Console.WriteLine($"Current health: {health} hp.");
  35.                     }
  36.  
  37.                 }
  38.                 else if (content == "chest")                        //намерили сме сандък с пари
  39.                 {
  40.                     coins += number;                                //добавяме парите от сандъка към нашите
  41.                     Console.WriteLine($"You found {number} coins.");//принтираме колко пари сме намерили
  42.  
  43.                 }
  44.                 else //намерили сме чудовище в стаята
  45.                 {
  46.                     string monsterName = content;
  47.                     health -= number;
  48.  
  49.                     if (health > 0) //живи сме и сме убили чудовището
  50.                     {
  51.                         Console.WriteLine($"You slayed {monsterName}.");
  52.                     }
  53.                     else  //ако умрем принтираме съобщение на конзолата и прекъсваме цикъла
  54.                     {
  55.                         Console.WriteLine($"You died! Killed by {monsterName}.\nBest room: {i + 1}");
  56.                         break;
  57.                     }
  58.                 }
  59.             }
  60.  
  61.             if (health > 0) //ако сме живи принтираме последното съобщение
  62.             {
  63.                 Console.WriteLine($"You've made it!\nCoins: {coins}\nHealth: {health}");
  64.             }
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement