Advertisement
Sabev

Hero of Eldevir

Feb 10th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.90 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Fundamentals
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var team = Console.ReadLine().Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
  14.             var input = string.Empty;
  15.             while ((input = Console.ReadLine()) != "Battle")
  16.             {
  17.                 var tokens = input.Split().ToList();
  18.                 var command = tokens[0];
  19.  
  20.                 if (command == "Loot")
  21.                 {
  22.                     var player = tokens[1];
  23.                     if (!team.Contains(player))
  24.                     {
  25.                         team.Add(player);
  26.                         Console.WriteLine($"{player} has been added to the inventory.");
  27.                     }
  28.                     //else
  29.                     //{
  30.                         //Console.WriteLine($"{player} is already part of the team.");
  31.                     //}
  32.                 }
  33.                 else if (command == "Disenchant")
  34.                 {
  35.                     var player = tokens[1];
  36.                     //if (!team.Contains(player))
  37.                     //{
  38.  
  39.                         //Console.WriteLine($"{player} is not part of the team.");
  40.  
  41.                     //}
  42.                     if(team.Contains(player))
  43.                     {
  44.                         team.Remove(player);
  45.                         Console.WriteLine($"{player} has been disenchanted.");
  46.  
  47.                     }
  48.                 }
  49.                 else if (command == "Upgrade")
  50.                 {
  51.                     List<string> players = tokens[1].Split('/').ToList();
  52.                     string firstPlayer = players[0];
  53.                     string secondPlayer = players[1];
  54.  
  55.                     if (team.Contains(firstPlayer))
  56.                     {
  57.                         //team.Select(p => p.Replace(firstPlayer, secondPlayer));
  58.                         team[team.FindIndex(i => i.Equals(firstPlayer))] = firstPlayer + " ~ " + secondPlayer;
  59.                         Console.WriteLine($"{firstPlayer} has been upgraded to {firstPlayer} ~ {secondPlayer}.");
  60.                     }
  61.                     //else
  62.                     //{
  63.                         //Console.WriteLine($"{firstPlayer} is not part of the team.");
  64.                     //}
  65.                 }
  66.  
  67.                 if (team.Count == 0)
  68.                 {
  69.                     Console.WriteLine("The inventory is empty.");
  70.                     break;
  71.                 }
  72.             }
  73.             if (team.Count != 0)
  74.             {
  75.                 Console.WriteLine("Red Paladin's inventory :");
  76.                 foreach (var item in team)
  77.                 {
  78.                    
  79.                     Console.WriteLine($"--> {item}");
  80.                 }
  81.             }
  82.         }
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement