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);
- }
- string command = Console.ReadLine();
- while (command!= "End")
- {
- 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]);
- string attacker = 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;
- }
- }
- else if (arr[0] == "Heal")
- {
- string name = arr[1];
- int amount = int.Parse(arr[2]);
- if (heroes[name][0] + amount >= 100)
- {
- heroes[name][0] = 100;
- var recovered = 100 - heroes[name][0];
- Console.WriteLine($"{name} healed for {recovered} HP!");
- }
- else
- {
- heroes[name][0] += amount;
- Console.WriteLine($"{name} healed for {amount} HP!");
- }
- }
- else
- {
- break;
- }
- command = Console.ReadLine();
- }
- var sortedHeroes = heroes.OrderByDescending(x => x.Value[0]).ThenBy(x => x.Key).ToList();
- foreach (var item in sortedHeroes)
- {
- Console.WriteLine($"{item.Key}");
- Console.WriteLine($" HP: {item.Value[0]}");
- Console.WriteLine($" MP: {item.Value[1]}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement