Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace _02DungeonestDark
- {
- class Program
- {
- static void Main(string[] args)
- {
- string rooms = Console.ReadLine();
- string[] allRooms = rooms.Split('|', StringSplitOptions.RemoveEmptyEntries);
- int health = 100;
- int coins = 0;
- for (int i = 0; i < allRooms.Length; i++)
- {
- string command = allRooms[i];
- string[] tokens = command.Split();
- string firstWord = tokens[0];
- if (firstWord=="potion")
- {
- int healthPoints = int.Parse(tokens[1]);
- if (health==100)
- {
- Console.WriteLine("You healed for 0 hp.");
- Console.WriteLine("Current health: {0} hp.",health);
- continue;
- }
- if (health+healthPoints<=100)
- {
- health += healthPoints;
- Console.WriteLine("You healed for {0} hp.",healthPoints);
- Console.WriteLine("Current health: {0} hp.", health);
- continue;
- }
- if (health+healthPoints>100)
- {
- int excess = (health + healthPoints) - 100;
- int actualHP = healthPoints - excess;
- health = 100;
- Console.WriteLine("You healed for {0} hp.", actualHP);
- Console.WriteLine("Current health: {0} hp.", health);
- continue;
- }
- }
- else if (firstWord=="chest")
- {
- int foundCoins = int.Parse(tokens[1]);
- coins += foundCoins;
- Console.WriteLine("You found {0} coins.",foundCoins);
- continue;
- }
- else
- {
- int monsterAttack = int.Parse(tokens[1]);
- if (health-monsterAttack>0)
- {
- health -= monsterAttack;
- Console.WriteLine("You slayed {0}.",firstWord);
- continue;
- }
- else
- {
- Console.WriteLine("You died! Killed by {0}.",firstWord);
- Console.WriteLine("Best room: {0}",i+1);
- return;
- }
- }
- }
- Console.WriteLine("You've made it!");
- Console.WriteLine($"Coins: {coins}");
- Console.WriteLine($"Health: {health}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement