Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- using System.Runtime.InteropServices;
- using System.Data;
- namespace _02._Boss_Rush
- {
- class Program
- {
- static void Main(string[] args)
- {
- var times = int.Parse(Console.ReadLine());
- Dictionary<string, int> health = new Dictionary<string, int>();
- Dictionary<string, int> mana = new Dictionary<string, int>();
- for (int i = 0; i < times; i++)
- {
- string[] input = Console.ReadLine().Split();
- //{hero name} {HP} {MP}
- if (!health.ContainsKey(input[0]))
- {
- health[input[0]] = int.Parse(input[1]);
- mana[input[0]] = int.Parse(input[2]);
- }
- }
- string[] command = Console.ReadLine().Split(" - ");
- while (command[0] != "End")
- {
- if (command[0] == "CastSpell")
- {
- //CastSpell – {hero name} – {MP needed} – {spell name}
- int need = int.Parse(command[2]);
- if (need > mana[command[1]])
- {
- Console.WriteLine($"{command[1]} does not have enough MP to cast {command[3]}!");
- }
- else
- {
- mana[command[1]] -= need;
- int left = mana[command[1]];
- Console.WriteLine($"{command[1]} has successfully cast {command[3]} and now has {left} MP!");
- }
- }
- if (command[0] == "TakeDamage")
- {
- //TakeDamage – {hero name} – {damage} – {attacker}
- health[command[1]] -= int.Parse(command[2]);
- if (health[command[1]] <= 0)
- {
- health.Remove(command[1]);
- mana.Remove(command[1]);
- Console.WriteLine($"{command[1]} has been killed by {command[3]}!");
- }
- else
- {
- int current = health[command[1]];
- Console.WriteLine($"{command[1]} was hit for {int.Parse(command[2])} HP by {command[3]} and now has {current} HP left!");
- }
- }
- if (command[0] == "Recharge")
- {
- //Recharge – {hero name} – {amount}
- mana[command[1]] += int.Parse(command[2]);
- if (mana[command[1]] > 200)
- {
- int difference = mana[command[1]] - 200;
- int amount = int.Parse(command[2]) - difference;
- mana[command[1]] = 200;
- Console.WriteLine($"{command[1]} recharged for {amount} MP!");
- }
- else
- {
- Console.WriteLine($"{command[1]} recharged for {int.Parse(command[2])} MP!");
- }
- }
- if (command[0] == "Heal")
- {
- //Heal – {hero name} – {amount}
- health[command[1]] += int.Parse(command[2]);
- if (health[command[1]] > 100)
- {
- int difference = health[command[1]] - 100;
- int amount = int.Parse(command[2]) - difference;
- health[command[1]] = 100;
- Console.WriteLine($"{command[1]} healed for {amount} HP!");
- }
- else
- {
- Console.WriteLine($"{command[1]} healed for {int.Parse(command[2])} HP!");
- }
- }
- command = Console.ReadLine().Split(" - ");
- }
- //• Print all members of your party who are still alive, sorted by their HP in descending order,
- //then by their name in ascending order, in the following format (their HP/MP need to be indented 2 spaces):
- foreach (var item in health.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
- {
- Console.WriteLine(item.Key);
- Console.WriteLine($" HP: {item.Value}");
- Console.WriteLine($" MP: {mana[item.Key]}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement