nikolayneykov

Untitled

Mar 1st, 2019
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.32 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.             //константни стойности, които впоследствие се променят
  12.             int initialHealth = 100; //тестваме на части преди последния печат с initialHealth = 50
  13.             int initialCoins = 0;
  14.  
  15.             //четем вход
  16.  
  17.             string[] dungeonsRoom = Console.ReadLine().Split('|').ToArray(); //единични кавички за сплитването
  18.  
  19.             //правим foreach loop
  20.  
  21.             //foreach (var item in dungeonsRoom)
  22.             //{
  23.             //Console.WriteLine(item);
  24.             //}
  25.  
  26.  
  27.             //въртим от 0 до броя на стаите
  28.             for (int i = 0; i < dungeonsRoom.Length; i++) //въртим от 0 до броя на стаите
  29.             {
  30.                 string[] currentRoom = dungeonsRoom[i].Split().ToArray(); //тук пазим отделните половинки в масив
  31.                                                                           //Console.WriteLine(currentRoom);
  32.                                                                           //взимаме лявата и дясната част
  33.                                                                           //лявата част ще бъде винаги стринг
  34.                 string command = currentRoom[0];
  35.                 int number = int.Parse(currentRoom[1]);
  36.  
  37.                 //гледаме лявата част от всеки един елемент каква е
  38.                 if (command == "potion")
  39.                 {
  40.                     int healthGain = Math.Min(number, 100 - initialHealth);
  41.                     initialHealth += healthGain;
  42.                     Console.WriteLine($"You healed for {healthGain} hp.");
  43.                     Console.WriteLine($"Current health: {initialHealth} hp.");
  44.                 }
  45.                 else if (command == "chest")
  46.                 {
  47.                     //chest 1000
  48.                     initialCoins += number;
  49.                     Console.WriteLine($"You found {number} coins.");
  50.  
  51.                 }
  52.                 else //monster
  53.                 {
  54.                     //rat 10
  55.                     string monsterName = command;
  56.                     initialHealth -= number; //You should remove the monster's attack from your health.
  57.  
  58.                     if (initialHealth > 0) //оцелели сме и сме убили чудовището
  59.                     {
  60.                         Console.WriteLine($"You slayed {monsterName}.");
  61.                     }
  62.                     else
  63.                     {
  64.                         Console.WriteLine($"You died! Killed by {monsterName}.");
  65.                         Console.WriteLine($"Best room: {i + 1}");
  66.                         return;
  67.                     }
  68.                 }
  69.             }
  70.  
  71.             //ако сме преминали през всички стаи успешно
  72.             Console.WriteLine($"You've made it!");
  73.             Console.WriteLine($"Coins: {initialCoins}");
  74.             Console.WriteLine($"Health: {initialHealth}");
  75.  
  76.         }
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment