Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace Problem_3
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, List<int>> heroes = new Dictionary<string, List<int>>();
- int n = int.Parse(Console.ReadLine());
- for (int i = 0; i < n; i++)
- {
- string character = Console.ReadLine();
- string[] charachterStats = character.Split(" ").ToArray();
- string name = charachterStats[0];
- int HP = int.Parse(charachterStats[1]);
- int MP = int.Parse(charachterStats[1]);
- heroes.Add(name, new List<int>());
- heroes[name].Add(HP);
- heroes[name].Add(MP);
- }
- while (true)
- {
- string command = Console.ReadLine();
- if (command == "End")
- {
- break;
- }
- string[] arr = command.Split("-").ToArray();
- if (arr[0] == "CastSpell")
- {
- string name = arr[1];
- int manaCost = int.Parse(arr[2]);
- string nameSpell = arr[3];
- if (heroes[name][1] >= manaCost)
- {
- heroes[name][1] -= manaCost;
- Console.WriteLine($"{name} has successfully cast {nameSpell} and now has {heroes[name][1]} MP!");
- }
- else
- {
- Console.WriteLine($"{name} does not have enough MP to cast {nameSpell}!");
- }
- }
- else if (arr[0] == "TakeDamage")
- {
- string name = arr[1];
- int damageTaken = int.Parse(arr[2]);
- int attacker = int.Parse(arr[3]);
- if (heroes[name][0] - damageTaken > 0)
- {
- heroes[name][0] -= damageTaken;
- Console.WriteLine($"{name} was hit for {damageTaken} HP by {attacker} and now has {heroes[name][0]} HP left!");
- }
- else
- {
- heroes.Remove(name);
- Console.WriteLine($"{name} has been killed by {attacker}!");
- }
- }
- else if (arr[0] == "Recharge")
- {
- string name = arr[1];
- int plusMana = int.Parse(arr[2]);
- if (heroes[name][1] + plusMana >= 200)
- {
- heroes[name][1] = 200;
- var recovered = 200 - heroes[name][1];
- Console.WriteLine($"{name} recharged for {recovered} MP!");
- }
- else
- {
- heroes[name][1] += plusMana;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement