Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _03._Inventory
- {
- class Invenotry
- {
- static void Main()
- {
- List<string> inventory = Console.ReadLine()
- .Split(", ")
- .ToList();
- string command = Console.ReadLine();
- while (command != "Craft!")
- {
- string[] currentCommand = command.Split(" - ");
- string instruction = currentCommand[0];
- if (instruction == "Collect")
- {
- string item = currentCommand[1];
- if (!inventory.Contains(item))
- {
- inventory.Add(item);
- }
- }
- else if (instruction == "Drop")
- {
- string item = currentCommand[1];
- if (inventory.Contains(item))
- {
- inventory.Remove(item);
- }
- }
- else if (instruction == "Combine Items")
- {
- string[] items = currentCommand[1].Split(':');
- string oldItem = items[0];
- string newItem = items[1];
- if (inventory.Contains(oldItem))
- {
- int index = inventory.IndexOf(oldItem) + 1;
- inventory.Insert(index, newItem);
- }
- // NB!! NB !!
- }
- else if (instruction == "Renew")
- {
- string item = currentCommand[1];
- if (inventory.Contains(item))
- {
- inventory.Remove(item);
- inventory.Add(item);
- }
- }
- command = Console.ReadLine();
- }
- Console.WriteLine(string.Join(", ", inventory));
- }
- }
- }
Add Comment
Please, Sign In to add comment