protected void ShowClearFromInventory(Inventory inventory) { bool exit = false; while (!exit) { if (inventory.IsEmpty()) { Console.WriteLine("This inventory is empty."); return; } ListInventoryItems(inventory); Console.WriteLine("Type 'done' when you are finished clearing."); int itemId = GetIntInput("Enter an item id> ", "done"); if (itemId > 0) { if (inventory.HasItem(itemId)) { int count = inventory.Count(itemId); inventory.ClearItem(itemId); Console.WriteLine("All {0} of item {1} have been cleared.", count, itemId); } else { Console.WriteLine("This inventory does not contain any {0}.", itemId); } } else if (itemId == -1) { exit = true; } else { Console.WriteLine("Incorrect item id."); } Console.WriteLine(); } }
protected void ShowRemoveFromInventory(Inventory inventory) { bool exit = false; while (!exit) { if (inventory.IsEmpty()) { Console.WriteLine("This inventory is empty."); return; } ListInventoryItems(inventory); Console.WriteLine("Type 'done' when you are finished removing."); int itemId = GetIntInput("Enter item id> ", "done"); if (itemId > 0) { if (inventory.HasItem(itemId)) { Console.WriteLine("Type 'all' to remove all."); int amount = GetIntInput("Enter the amount to remove> ", "all"); if (amount > 0) { if (inventory.GainItem(itemId, -amount)) Console.WriteLine("{0} of item {1} has been removed.", amount, itemId); else Console.WriteLine("Could not remove {0} of item {1}.", amount, itemId); } else if (amount == -1) { amount = inventory.Count(itemId); if (inventory.GainItem(itemId, -amount)) Console.WriteLine("All {0} of item {1} has been removed.", amount, itemId); else Console.WriteLine("Could not remove all of item {0}.", itemId); } else { Console.WriteLine("That is an invalid amount."); } } else { Console.WriteLine("This inventory does not contain any {0}.", itemId); } } else if (itemId == -1) { exit = true; } else { Console.WriteLine("Incorrect item id."); } Console.WriteLine(); } }
protected void ShowRemoveFromInventory(Inventory inventory) { bool exit = false; while (!exit) { if (inventory.IsEmpty()) { Console.WriteLine("This inventory is empty."); return; } ListInventoryItems(inventory); Console.WriteLine("Type 'done' when you are finished removing."); int itemId = GetIntInput("Enter item id> ", "done"); if (itemId > 0) { if (inventory.HasItem(itemId)) { Console.WriteLine("Type 'all' to remove all."); int amount = GetIntInput("Enter the amount to remove> ", "all"); if (amount > 0) { if (inventory.GainItem(itemId, -amount)) { Console.WriteLine("{0} of item {1} has been removed.", amount, itemId); } else { Console.WriteLine("Could not remove {0} of item {1}.", amount, itemId); } } else if (amount == -1) { amount = inventory.Count(itemId); if (inventory.GainItem(itemId, -amount)) { Console.WriteLine("All {0} of item {1} has been removed.", amount, itemId); } else { Console.WriteLine("Could not remove all of item {0}.", itemId); } } else { Console.WriteLine("That is an invalid amount."); } } else { Console.WriteLine("This inventory does not contain any {0}.", itemId); } } else if (itemId == -1) { exit = true; } else { Console.WriteLine("Incorrect item id."); } Console.WriteLine(); } }