protected void ShowAddToInventory(Inventory inventory) { int itemId = 0; while (itemId != -1) { ListInventoryItems(inventory); Console.WriteLine("Type 'done' when you are finished adding."); itemId = GetIntInput("Enter an item id> ", "done"); if (itemId > 0) { bool getAmount = true; while (getAmount) { int amount = GetIntInput("Enter an amount for (" + itemId + ")> ", "done"); if (amount > 0) { if (inventory.GainItem(itemId, amount)) { Console.WriteLine("{0} of item {1} has been added.", amount, itemId); } else { Console.WriteLine("Could not add {0} of item {1}.", amount, itemId); } getAmount = false; } else if (amount == -1) { if (inventory.GainItem(itemId, 1)) { Console.WriteLine("1 of item {0} has been added.", itemId); } else { Console.WriteLine("Could not add 1 of item {0}.", itemId); } getAmount = false; itemId = -1; } else { Console.WriteLine("That is an incorrect amount."); } } } else { Console.WriteLine("That is an incorrect item id."); } } }
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(); } }
protected void ShowAddToInventory(Inventory inventory) { int itemId = 0; while (itemId != -1) { ListInventoryItems(inventory); Console.WriteLine("Type 'done' when you are finished adding."); itemId = GetIntInput("Enter an item id> ", "done"); if (itemId > 0) { bool getAmount = true; while (getAmount) { int amount = GetIntInput("Enter an amount for (" + itemId + ")> ", "done"); if (amount > 0) { if(inventory.GainItem(itemId, amount)) Console.WriteLine("{0} of item {1} has been added.", amount, itemId); else Console.WriteLine("Could not add {0} of item {1}.", amount, itemId); getAmount = false; } else if (amount == -1) { if (inventory.GainItem(itemId, 1)) Console.WriteLine("1 of item {0} has been added.", itemId); else Console.WriteLine("Could not add 1 of item {0}.", itemId); getAmount = false; itemId = -1; } else { Console.WriteLine("That is an incorrect amount."); } } } else { Console.WriteLine("That is an incorrect item id."); } } }