Advertisement
nikolayneykov

Untitled

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