Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _02DungeonestDark
- {
- class Program
- {
- static void Main(string[] args)
- {
- //константни стойности, които впоследствие се променят
- int initialHealth = 100; //тестваме на части преди последния печат с initialHealth = 50
- int initialCoins = 0;
- //четем вход
- string[] dungeonsRoom = Console.ReadLine().Split('|').ToArray(); //единични кавички за сплитването
- //правим foreach loop
- //foreach (var item in dungeonsRoom)
- //{
- //Console.WriteLine(item);
- //}
- //въртим от 0 до броя на стаите
- for (int i = 0; i < dungeonsRoom.Length; i++) //въртим от 0 до броя на стаите
- {
- string[] currentRoom = dungeonsRoom[i].Split().ToArray(); //тук пазим отделните половинки в масив
- //Console.WriteLine(currentRoom);
- //взимаме лявата и дясната част
- //лявата част ще бъде винаги стринг
- string command = currentRoom[0];
- int number = int.Parse(currentRoom[1]);
- //гледаме лявата част от всеки един елемент каква е
- if (command == "potion")
- {
- int healthGain = Math.Min(number, 100 - initialHealth);
- initialHealth += healthGain;
- Console.WriteLine($"You healed for {healthGain} hp.");
- Console.WriteLine($"Current health: {initialHealth} hp.");
- }
- else if (command == "chest")
- {
- //chest 1000
- initialCoins += number;
- Console.WriteLine($"You found {number} coins.");
- }
- else //monster
- {
- //rat 10
- string monsterName = command;
- initialHealth -= number; //You should remove the monster's attack from your health.
- if (initialHealth > 0) //оцелели сме и сме убили чудовището
- {
- Console.WriteLine($"You slayed {monsterName}.");
- }
- else
- {
- Console.WriteLine($"You died! Killed by {monsterName}.");
- Console.WriteLine($"Best room: {i + 1}");
- return;
- }
- }
- }
- //ако сме преминали през всички стаи успешно
- Console.WriteLine($"You've made it!");
- Console.WriteLine($"Coins: {initialCoins}");
- Console.WriteLine($"Health: {initialHealth}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment