Advertisement
AlexVanchov

3

Apr 4th, 2020
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.08 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. namespace Problem_3
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             Dictionary<string, List<int>> heroes = new Dictionary<string, List<int>>();
  11.             int n = int.Parse(Console.ReadLine());
  12.             for (int i = 0; i < n; i++)
  13.             {
  14.                 string character = Console.ReadLine();
  15.                 string[] charachterStats = character.Split(" ").ToArray();
  16.                 string name = charachterStats[0];
  17.                 int HP = int.Parse(charachterStats[1]);
  18.                 int MP = int.Parse(charachterStats[1]);
  19.                 heroes.Add(name, new List<int>());
  20.                 heroes[name].Add(HP);
  21.                 heroes[name].Add(MP);
  22.  
  23.             }
  24.             while (true)
  25.             {
  26.                 string command = Console.ReadLine();
  27.                 if (command == "End")
  28.                 {
  29.                     break;
  30.                 }
  31.                 string[] arr = command.Split("-").ToArray();
  32.                 if (arr[0] == "CastSpell")
  33.                 {
  34.                     string name = arr[1];
  35.                     int manaCost = int.Parse(arr[2]);
  36.                     string nameSpell = arr[3];
  37.                     if (heroes[name][1] >= manaCost)
  38.                     {
  39.                         heroes[name][1] -= manaCost;
  40.                         Console.WriteLine($"{name} has successfully cast {nameSpell} and now has {heroes[name][1]} MP!");
  41.                     }
  42.                     else
  43.                     {
  44.                         Console.WriteLine($"{name} does not have enough MP to cast {nameSpell}!");
  45.                     }
  46.                 }
  47.                 else if (arr[0] == "TakeDamage")
  48.                 {
  49.                     string name = arr[1];
  50.                     int damageTaken = int.Parse(arr[2]);
  51.                     int attacker = int.Parse(arr[3]);
  52.                     if (heroes[name][0] - damageTaken > 0)
  53.                     {
  54.                         heroes[name][0] -= damageTaken;
  55.                         Console.WriteLine($"{name} was hit for {damageTaken} HP by {attacker} and now has {heroes[name][0]} HP left!");
  56.                     }
  57.                     else
  58.                     {
  59.                         heroes.Remove(name);
  60.                         Console.WriteLine($"{name} has been killed by {attacker}!");
  61.                     }
  62.                 }
  63.                 else if (arr[0] == "Recharge")
  64.                 {
  65.                     string name = arr[1];
  66.                     int plusMana = int.Parse(arr[2]);
  67.  
  68.                     if (heroes[name][1] + plusMana >= 200)
  69.                     {
  70.                         heroes[name][1] = 200;
  71.                         var recovered = 200 - heroes[name][1];
  72.                         Console.WriteLine($"{name} recharged for {recovered} MP!");
  73.                     }
  74.                     else
  75.                     {
  76.                         heroes[name][1] += plusMana;
  77.                     }
  78.                 }
  79.             }
  80.         }
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement