Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Problem_3._Heroes_of_Code_and_Logic_VII
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, int[]> hero = new Dictionary<string, int[]>();
- int n = int.Parse(Console.ReadLine());
- for (int i = 0; i < n; i++)
- {
- string[] input = Console.ReadLine().Split();
- string heroName = input[0];
- int hp = int.Parse(input[1]);
- int mp = int.Parse(input[2]);
- hero.Add(heroName, new int[2]{ hp, mp});
- }
- string commands ;
- while ((commands = Console.ReadLine()) != "End")
- {
- string[] split = commands.Split(" - ");
- string mainCommand = split[0];
- string heroName = split[1];
- //CastSpell – {hero name} – {MP needed} – {spell name}
- if (mainCommand == "CastSpell")
- {
- int mpNeeded = int.Parse(split[2]);
- string spellName = split[3];
- if (hero.ContainsKey(heroName))
- {
- if (hero[heroName][1] >= mpNeeded)
- {
- hero[heroName][1] = hero[heroName][1] - mpNeeded;
- Console.WriteLine($"{heroName} has successfully cast {spellName} and now has {hero[heroName][1]} MP!");
- }
- else
- {
- Console.WriteLine($"{heroName} does not have enough MP to cast {spellName}!");
- }
- }
- }
- //TakeDamage – { hero name} – { damage} – { attacker}
- if (mainCommand == "TakeDamage")
- {
- int damage = int.Parse(split[2]);
- string attacker = split[3];
- if (hero.ContainsKey(heroName))
- {
- if (hero[heroName][0] > damage)
- {
- hero[heroName][0] = hero[heroName][0] - damage;
- Console.WriteLine($"{heroName} was hit for {damage} HP by {attacker} and now has {hero[heroName][0]} HP left!");
- }
- else
- {
- hero.Remove(heroName);
- Console.WriteLine($"{heroName} has been killed by {attacker}!");
- }
- }
- }
- //Recharge – {hero name} – {amount}
- if (mainCommand == "Recharge")
- {
- int manaHeal = int.Parse(split[2]);
- if (hero.ContainsKey(heroName))
- {
- int manaLeft = 0;
- manaLeft = hero[heroName][1] + manaHeal;
- if (manaLeft > 200)
- {
- manaLeft = 200 - hero[heroName][1];
- hero[heroName][1] = 200;
- Console.WriteLine($"{heroName} recharged for {manaLeft} MP!");
- }
- else if (hero[heroName][1] <= 200)
- {
- hero[heroName][1] = manaLeft;
- Console.WriteLine($"{heroName} recharged for {manaHeal} MP!");
- }
- }
- }
- //Heal – {hero name} – {amount}
- if (mainCommand == "Heal")
- {
- int hpHeal = int.Parse(split[2]);
- if (hero.ContainsKey(heroName))
- {
- int leftHp= 0;
- leftHp = hero[heroName][0]+ hpHeal;
- if (leftHp > 100)
- {
- leftHp = 100 - hero[heroName][0];
- hero[heroName][0] = 100;
- Console.WriteLine($"{heroName} healed for {leftHp} HP!");
- }
- else if (leftHp <= 100)
- {
- hero[heroName][0] = leftHp;
- Console.WriteLine($"{heroName} healed for {hpHeal} HP!");
- }
- }
- }
- }
- hero = hero.OrderByDescending(x => x.Value[0]).ThenBy(x => x.Key).ToDictionary(x => x.Key, x => x.Value);
- foreach (var element in hero)
- {
- Console.WriteLine($"{element.Key}");
- Console.WriteLine($"HP: {element.Value[0]}");
- Console.WriteLine($"MP: {element.Value[1]}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement