protected override Item CreateItem(string itemTypeString, string itemNameString, Location itemLocation, Item item) { switch (itemTypeString) { case "weapon": { item = new Weapon(itemNameString, itemLocation); return item; } case "wood": { item = new Wood(itemNameString, itemLocation); return item; } case "iron": { item = new Iron(itemNameString, itemLocation); return item; } default: { return base.CreateItem(itemTypeString, itemNameString, itemLocation, item); } } }
private void HandleCraftInteraction(string[] commandWords, Person actor) { var craftedItemType = commandWords[2]; string craftedItemName = commandWords[3]; Item theNewCraftedItem = null; var actorInventory = actor.ListInventory(); if (craftedItemType == "weapon") { bool hasWood = PossessTheRequiredItem(actorInventory, ItemType.Wood); bool hasIron = PossessTheRequiredItem(actorInventory, ItemType.Iron); if (hasWood && hasIron) { theNewCraftedItem = new Weapon(craftedItemName); this.AddToPerson(actor, theNewCraftedItem); theNewCraftedItem.UpdateWithInteraction("craft"); } } else if (craftedItemType == "armor") { bool hasIron = PossessTheRequiredItem(actorInventory, ItemType.Iron); if (hasIron) { theNewCraftedItem = new Armor(craftedItemName); this.AddToPerson(actor, theNewCraftedItem); theNewCraftedItem.UpdateWithInteraction("craft"); } } }
private void CraftWeapon(string newItemName, Person actor) { var ironItems = actor.ListInventory().Where(x => x.ItemType == ItemType.Iron); var woodItems = actor.ListInventory().Where(x => x.ItemType == ItemType.Wood); if (ironItems != null && woodItems != null && ironItems.Count() > 0 && woodItems.Count() > 0) { var item = new Weapon(newItemName, null); actor.AddToInventory(item); ownerByItem.Add(item, actor); item.UpdateWithInteraction("craft"); } }
private void HandleCraftInteraction(Person actor, string itemType, string itemName) { Item newItem; if (itemType == "weapon" && actor.InventorryContains(ItemType.Wood, ItemType.Iron)) { newItem=new Weapon(itemName); this.AddToPerson(actor, newItem); } else if (itemType == "armor" && actor.InventorryContains(ItemType.Iron)) { newItem =new Armor(itemName); this.AddToPerson(actor, newItem); } }
protected override Item CreateItem(string itemTypeString, string itemNameString, Location itemLocation, Item item) { switch (itemTypeString) { case "weapon": item = new Weapon(itemNameString, itemLocation); break; case "iron": item = new Iron(itemNameString, itemLocation); break; default: return base.CreateItem(itemTypeString, itemNameString, itemLocation,item); break; } return item; }
protected override Item CreateItem(string itemTypeString, string itemNameString, Location itemLocation, Item item) { Item itemToBeCreated = null; switch (itemTypeString) { case "weapon": itemToBeCreated = new Weapon(itemNameString, itemLocation); break; case "wood": itemToBeCreated = new Wood(itemNameString, itemLocation); break; default: itemToBeCreated = base.CreateItem(itemTypeString, itemNameString, itemLocation, itemToBeCreated); break; } return itemToBeCreated; }
private void HandleCraftInteraction(Person actor, string name) { if (actor.ListInventory().Exists(x => x is Iron)) { if (actor.ListInventory().Exists(x => x is Weapon)) { var item = new Weapon(name); actor.AddToInventory(item); this.AddToPerson(actor, item); return; } else { var item = new Armor(name); actor.AddToInventory(item); this.AddToPerson(actor, item); } } }
protected virtual Item CreateItem(string itemTypeString, string itemNameString, Location itemLocation, Item item) { switch (itemTypeString) { case "armor": item = new Armor(itemNameString, itemLocation); break; case "weapon": item = new Weapon(itemNameString, itemLocation); break; case "wood": item = new Wood(itemNameString, itemLocation); break; case "iron": item = new Iron(itemNameString, itemLocation); break; default: break; } return item; }
protected override Item CreateItem(string itemTypeString, string itemNameString, Location itemLocation, Item item) { if (itemTypeString == "armor") { base.CreateItem(itemTypeString, itemNameString, itemLocation, item); } switch (itemTypeString) { case "weapon": item = new Weapon(itemNameString, itemLocation); break; case "wood": item = new Wood(itemNameString, itemLocation); break; case "iron": item = new Iron(itemNameString, itemLocation); break; default: break; } return item; }
private void HandleCraftInteraction(Person actor, string itemType, string itemName) { if (actor.ListInventory().Find(i => i is Iron) != null) { if (itemType == "weapon" && actor.ListInventory().Find(i => i is Wood) != null) { var item = new Weapon(itemName); actor.AddToInventory(item); this.ownerByItem.Add(item, actor); } else if (itemType == "armor") { var item = new Armor(itemName); actor.AddToInventory(item); this.ownerByItem.Add(item, actor); } } }
private void HandleCraftInteraction(string[] commandWords, Person actor) { var itemsInInventory = actor.ListInventory(); bool[] hasItemTypes = this.CheckActorInventoryForItem(itemsInInventory); switch (commandWords[2].ToLower()) { case ArmorCase: { if (hasItemTypes[0]) { var craftedArmor = new Armor(commandWords[3], actor.Location); this.AddToPerson(actor, craftedArmor); } break; } case WeaponCase: { if (hasItemTypes[0] && hasItemTypes[1]) { var craftedWeapon = new Weapon(commandWords[3], actor.Location); this.AddToPerson(actor, craftedWeapon); } break; } default: break; } }
private void HandleCraftInteraction(string[] commandWords, Person actor) { var itemString = commandWords[2]; Item item = null; List<ItemType> requiredItems; switch(itemString) { case "weapon": item = new Weapon(commandWords[3]); requiredItems = Weapon. break; case "armor": item = new Armor(commandWords[3]); break; default: break; } if(actor.ListInventory().Merge(item.)) { } }
private void HandleCraftInteraction(string[] commandWords, Person actor) { string craftItemType = commandWords[2]; string craftItemName = commandWords[3]; if (craftItemType == "armor") { bool hasIron = false; foreach (var item in actor.ListInventory()) { if (item.ItemType == ItemType.Iron) { hasIron = true; break; } } if (hasIron) { var addedItem = new Armor(craftItemName); this.AddToPerson(actor, addedItem); addedItem.UpdateWithInteraction("craft"); } } if (craftItemType == "weapon") { bool hasWood = false; bool hasIron = false; foreach (var item in actor.ListInventory()) { if (item.ItemType == ItemType.Wood) { hasWood = true; } else if (item.ItemType == ItemType.Iron) { hasIron = true; } } if (hasWood && hasIron) { var addedItem = new Weapon(craftItemName); this.AddToPerson(actor, addedItem); addedItem.UpdateWithInteraction("craft"); } } }
private void HandleCraftInteraction(Person actor, string itemToCraft, string itemName) { //A Person can craft items, provided he has some items in his inventory //A Person should be able to craft Weapons and Armor //Crafting an Armor requires that the Person has Iron in his inventory //Results in adding an Armor item in the Person’s inventory //Crafting a Weapon requires that the Person has Iron and Wood in his inventory //Syntax: Joro craft weapon/armor newItemName - gathers an item, naming it newItemName if the Person Joro has the necessary switch (itemToCraft) { case "armor": if (actor.ListInventory().Any(a => a.GetType() == typeof(Iron))) { Armor armor = new Armor(itemName); base.AddToPerson(actor, armor); actor.AddToInventory(new Armor(itemName)); } break; case "weapon": if (actor.ListInventory().Any(a => a.GetType() == typeof(Iron)) && actor.ListInventory().Any(a => a.GetType() == typeof(Wood))) { Weapon weapon = new Weapon(itemName); base.AddToPerson(actor, weapon); actor.AddToInventory(new Weapon(itemName)); } break; default: break; } }
// Private methods private void HandleCraftInteraction(string itemType, string newItemName, Person actor) { Item craftedItem = null; Item ironItem = actor.ListInventory().FirstOrDefault(i => i.ItemType == ItemType.Iron); Item woodItem = actor.ListInventory().FirstOrDefault(i => i.ItemType == ItemType.Wood); if (ironItem != null && itemType == "armor") { craftedItem = new Armor(newItemName); this.AddToPerson(actor, craftedItem); } else if (ironItem != null && woodItem != null && itemType == "weapon") { craftedItem = new Weapon(newItemName); this.AddToPerson(actor, craftedItem); } }
private void HandleCraftInteraction(Person actor, string itemType, string itemName) { if (actor.ListInventory().Count > 0) { if (itemType == "weapon" && actor.ListInventory().Any(x => x.ItemType == ItemType.Iron) && actor.ListInventory().Any(x => x.ItemType == ItemType.Wood)) { var weapon = new Weapon(itemName); AddToPerson(actor, weapon); } else if (itemType == "armor" && actor.ListInventory().Any(x => x.ItemType == ItemType.Iron)) { var armor = new Armor(itemName); AddToPerson(actor, armor); } } }
private void HandleCraftInteraction(string[] commandWords, Person actor) { List<Item> itemsInInventory = actor.ListInventory(); if (commandWords[2] == "weapon") { itemType = ItemType.Weapon; } else if (commandWords[2] == "armor") { itemType = ItemType.Armor; } foreach (var items in itemsInInventory) { if (items.ItemType == ItemType.Iron) { hasIron = true; } else if (items.ItemType == ItemType.Wood) { hasWood = true; } } if (hasWood == true && hasIron == true) { hasIronAndWood = true; } if (itemType == ItemType.Weapon && hasIronAndWood == true) { Weapon newWeapon = new Weapon(commandWords[3], null); this.AddToPerson(actor, newWeapon); } if (itemType == ItemType.Armor && hasIron == true) { Armor newArmor = new Armor(commandWords[3], null); this.AddToPerson(actor, newArmor); } }
private void HandleCraftInteraction(string[] commandWords, Person actor) { Item craftedItem = null; string itemType = commandWords[2]; string itemName = commandWords[3]; switch (itemType) { case "armor" : foreach (var item in actor.ListInventory()) { if (item.ItemType == ItemType.Iron) { craftedItem = new Armor(itemName); this.AddToPerson(actor, craftedItem); return; } } break; case "weapon" : bool hasIron = new bool(); bool hasWood = new bool(); foreach (var item in actor.ListInventory()) { if (item.ItemType == ItemType.Iron) { hasIron = true; } else if (item.ItemType == ItemType.Wood) { hasWood = true; } if (hasIron && hasWood) { craftedItem = new Weapon(itemName); this.AddToPerson(actor, craftedItem); return; } } break; default: break; } }
private void HandleCraftInteraction(Person actor, string itemTypeAsString, string newItemName) { var actorInventory = actor.ListInventory(); Item itemToAdd = null; var listOfNeededItems = null; switch (itemTypeAsString) { case "weapon" : if (actorInventory.Any(x => x.ItemType == ItemType.Wood) && actorInventory.Any(x => x.ItemType == ItemType.Iron)) { itemToAdd = new Weapon(newItemName); } break; case "armor" : if (actorInventory.Any(x => x.ItemType == ItemType.Iron)) { itemToAdd = new Armor(newItemName); } break; default: break; } if (itemToAdd != null) { this.AddToPerson(actor, itemToAdd); } }