public string AddItemToPool(string[] args) { string itemName = args[0]; switch (itemName) { case "HealthPotion": HealthPotion healthPotion = new HealthPotion(); itemPool.Push(healthPotion); break; case "PoisonPotion": PoisonPotion poisonPotion = new PoisonPotion(); itemPool.Push(poisonPotion); break; case "ArmorRepairKit": ArmorRepairKit armorRepairKit = new ArmorRepairKit(); itemPool.Push(armorRepairKit); break; default: throw new ArgumentException($"Invalid item \"{itemName}\"!"); } return($"{itemName} added to pool."); }
public static Item CreateItem(string name) { string itemName = name; Item newItem = null; if (itemName == "HealthPotion") { newItem = new HealthPotion(); } else if (itemName == "PoisonPotion") { newItem = new PoisonPotion(); } else if (itemName == "ArmorRepairKit") { newItem = new ArmorRepairKit(); } else { // throw new ArgumentException($"Invalid item type \"{itemName}\"!"); throw new ArgumentException($"Invalid item \"{itemName}\"!"); } return(newItem); }
public string AddItemToPool(string[] args) { string itemName = args[0]; Item item; switch (itemName) { case "HealthPotion": item = new HealthPotion(); break; case "PoisonPotion": item = new PoisonPotion(); break; case "ArmorRepairKit": item = new ArmorRepairKit(); break; default: throw new ArgumentException($"Invalid item \"{itemName}\"!"); } itemPool.Add(item); return($"{itemName} added to pool."); }
public string AddItemToPool(string[] args) { var itemName = args[0]; if (itemName != "PoisonPotion" && itemName != "HealthPotion" && itemName != "ArmorRepairKit") { throw new ArgumentException($"Invalid item \"{itemName}\"!"); } else { Item obj; if (itemName.Equals("PoisonPotion")) { obj = new PoisonPotion(); } else if (itemName.Equals("HealthPotion")) { obj = new HealthPotion(); } else { obj = new ArmorRepairKit(); } items.Add(obj); return($"{itemName} added to pool."); } }
public string AddItemToPool(string[] args) { string itemName = args[0]; Item item = null; switch (itemName) { case "ArmorRepairKit": item = new ArmorRepairKit(); pool.Push(item); return($"{item.Name} added to pool."); case "HealthPotion": item = new HealthPotion(); pool.Push(item); return($"{item.Name} added to pool."); case "PoisonPotion": item = new PoisonPotion(); pool.Push(item); return($"{item.Name} added to pool."); default: throw new ArgumentException(string.Format(ErrorMessages.InvalidItem, itemName)); } }
public string AddItemToPool(string[] args) { if (args[0] != nameof(ArmorRepairKit) && args[0] != nameof(HealthPotion) && args[0] != nameof(PoisonPotion)) { throw new ArgumentException($"Invalid item \"{args[0]}\"!"); } Item it = null; switch (args[0]) { case nameof(ArmorRepairKit): it = new ArmorRepairKit(); break; case nameof(HealthPotion): it = new HealthPotion(); break; case nameof(PoisonPotion): it = new PoisonPotion(); break; } pool.Push(it); return($"{args[0]} added to pool."); }
public Item CreateItem(string itemName) { Item item; switch (itemName) { case "HealthPotion": item = new HealthPotion(); break; case "PoisonPotion": item = new PoisonPotion(); break; case "ArmorRepairKit": item = new ArmorRepairKit(); break; default: throw new ArgumentException($"Invalid item \"{itemName}\"!"); } return(item); }