Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- class Hero
- {
- public string Name { get; set; }
- public int HP { get; set; }
- public int MP { get; set; }
- public Hero(string name, int hp, int mp)
- {
- this.Name = name;
- this.HP = hp;
- this.MP = mp;
- }
- }
- class Program
- {
- static List<Hero> heroes = new List<Hero>();
- static void Main()
- {
- GetHeroesInfo();
- string input;
- while ((input = Console.ReadLine()) != "End")
- {
- string[] cmd = input.Split(" - ");
- Hero hero = heroes.Find(x => x.Name == cmd[1]);
- switch (cmd[0])
- {
- case "CastSpell": CastSpell(cmd, hero); break;
- case "TakeDamage": TakeDamage(cmd, hero); break;
- case "Recharge": Recharge(cmd, hero); break;
- case "Heal": Heal(cmd, hero); break;
- }
- }
- foreach (Hero hero in heroes)
- {
- Console.WriteLine(hero.Name);
- Console.WriteLine($" HP: {hero.HP}");
- Console.WriteLine($" MP: {hero.MP}");
- }
- }
- private static void GetHeroesInfo()
- {
- int numberOfHeroes = int.Parse(Console.ReadLine());
- for (int i = 0; i < numberOfHeroes; i++)
- {
- string[] entryInfo = Console.ReadLine().Split();
- string name = entryInfo[0];
- int hp = int.Parse(entryInfo[1]);
- int mp = int.Parse(entryInfo[2]);
- heroes.Add(new Hero(name, hp, mp));
- }
- }
- private static void TakeDamage(string[] cmd, Hero hero)
- {
- int damage = int.Parse(cmd[2]);
- string attacker = cmd[3];
- hero.HP -= damage;
- if (hero.HP > 0)
- Console.WriteLine($"{hero.Name} was hit for {damage} HP by {attacker} and now has {hero.HP} HP left!");
- else
- {
- Console.WriteLine($"{hero.Name} has been killed by {attacker}!");
- heroes.Remove(hero);
- }
- }
- private static void CastSpell(string[] cmd, Hero hero)
- {
- int mpNeeded = int.Parse(cmd[2]);
- string spellName = cmd[3];
- if (hero.MP >= mpNeeded)
- {
- hero.MP -= mpNeeded;
- Console.WriteLine($"{hero.Name} has successfully cast {spellName} and now has {hero.MP} MP!");
- }
- else
- Console.WriteLine($"{hero.Name} does not have enough MP to cast {spellName}!");
- }
- private static void Recharge(string[] cmd, Hero hero)
- {
- int amount = int.Parse(cmd[2]);
- int rechargedFor = Math.Min(amount, 200 - hero.MP);
- hero.MP += rechargedFor;
- Console.WriteLine($"{hero.Name} recharged for {rechargedFor} MP!");
- }
- private static void Heal(string[] cmd, Hero hero)
- {
- int amount = int.Parse(cmd[2]);
- int healedFor = Math.Min(amount, 100 - hero.HP);
- hero.HP += healedFor;
- Console.WriteLine($"{hero.Name} healed for {healedFor} HP!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement