Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace HeroesOfCode
- {
- class Program
- {
- static void Main(string[] args)
- {
- int numberOfHeroes = int.Parse(Console.ReadLine());
- var dictHeroHPMP = new Dictionary<string, List<int>>();
- for (int i = 0; i < numberOfHeroes; i++)
- {
- string[] input = Console.ReadLine().Split();
- string hero = input[0];
- int hitPoints = int.Parse(input[1]);
- int manaPoints = int.Parse(input[2]);
- dictHeroHPMP[hero] = new List<int>();
- dictHeroHPMP[hero].Add(hitPoints);
- dictHeroHPMP[hero].Add(manaPoints);
- }
- string command = string.Empty;
- while ((command = Console.ReadLine()) != "End")
- {
- string[] commandArray = command.Split(" - ");
- if (commandArray[0] == "CastSpell")
- {
- string hero = commandArray[1];
- int manaPointsNeeded = int.Parse(commandArray[2]);
- string spellName = commandArray[3];
- if (manaPointsNeeded <= dictHeroHPMP[hero][1])
- {
- dictHeroHPMP[hero][1] = dictHeroHPMP[hero][1] - manaPointsNeeded;
- Console.WriteLine($"{hero} has successfully cast {spellName} and now has {dictHeroHPMP[hero][1]} MP!");
- }
- else if (manaPointsNeeded > dictHeroHPMP[hero][1])
- {
- Console.WriteLine($"{hero} does not have enough MP to cast {spellName}!");
- }
- }
- else if (commandArray[0] == "TakeDamage")
- {
- string hero = commandArray[1];
- int damage = int.Parse(commandArray[2]);
- string attacker = commandArray[3];
- dictHeroHPMP[hero][0] = dictHeroHPMP[hero][0] - damage;
- if (dictHeroHPMP[hero][0] > 0)
- {
- Console.WriteLine($"{hero} was hit for {damage} HP by {attacker} and now has {dictHeroHPMP[hero][0]} HP left!");
- }
- else
- {
- dictHeroHPMP.Remove(hero);
- Console.WriteLine($"{hero} has been killed by {attacker}!");
- }
- }
- else if (commandArray[0] == "Recharge")
- {
- string hero = commandArray[1];
- int amount = int.Parse(commandArray[2]);
- int initialMP = dictHeroHPMP[hero][1];
- int amountRecovered = 0;
- dictHeroHPMP[hero][1] = dictHeroHPMP[hero][1] + amount;
- if (dictHeroHPMP[hero][1] > 200)
- {
- dictHeroHPMP[hero][1] = 200;
- amountRecovered = 200 - initialMP;
- }
- else if (dictHeroHPMP[hero][1] <= 200)
- {
- amountRecovered = dictHeroHPMP[hero][1] - initialMP;
- }
- Console.WriteLine($"{hero} recharged for {amountRecovered} MP!");
- }
- else if (commandArray[0] == "Heal")
- {
- string hero = commandArray[1];
- int amount = int.Parse(commandArray[2]);
- int initialHP = dictHeroHPMP[hero][0];
- int amountRecovered = 0;
- dictHeroHPMP[hero][0] = dictHeroHPMP[hero][0] + amount;
- if (dictHeroHPMP[hero][0] > 100)
- {
- dictHeroHPMP[hero][0] = 100;
- amountRecovered = 100 - initialHP;
- }
- else if (dictHeroHPMP[hero][0] <= 100)
- {
- amountRecovered = dictHeroHPMP[hero][0] - initialHP;
- }
- Console.WriteLine($"{hero} healed for {amountRecovered} HP!");
- }
- }
- foreach (var kvp in dictHeroHPMP.OrderByDescending(x => x.Value[0]).ThenBy(x => x.Key))
- {
- string hero = kvp.Key;
- int hitPoints = kvp.Value[0];
- int manaPoints = kvp.Value[1];
- Console.WriteLine(hero);
- Console.WriteLine($" HP: {hitPoints}");
- Console.WriteLine($" MP: {manaPoints}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement