//loads items from GameItems.xml private static void loadItemsFromNodes(XmlNodeList nodes) { if (nodes == null) { return; } foreach (XmlNode node in nodes) { GameItem.ItemCategory itemCategory = determineItemCategory(node.Name); //creates the gameitem using extension methods to acquire attributes GameItem gameItem = new GameItem(itemCategory, node.AttributeAsInt("id"), node.AttributeAsString("name"), node.AttributeAsInt("price"), itemCategory == GameItem.ItemCategory.Weapon); //allows item to have attack action and damage properties if identified as weapon if (itemCategory == GameItem.ItemCategory.Weapon) { gameItem.action = new AttackWithWeapon(gameItem, node.AttributeAsInt("minimumDamage"), node.AttributeAsInt("maximumDamage")); } else if (itemCategory == GameItem.ItemCategory.Consumable) { gameItem.action = new Heal(gameItem, node.AttributeAsInt("hpToHeal")); } _standardGameItems.Add(gameItem); } }
private static void LoadItemsFromNodes(XmlNodeList nodes) { if (nodes == null) { return; } foreach (XmlNode node in nodes) { GameItem.ItemCategory itemCategory = DetermineItemCategory(node.Name); GameItem gameItem = new GameItem(itemCategory, node.AttributeAsInt("ID"), node.AttributeAsString("Name"), node.AttributeAsInt("Price"), itemCategory == GameItem.ItemCategory.Weapon); if (itemCategory == GameItem.ItemCategory.Weapon) { gameItem.Action = new AttackWithWeapon(gameItem, node.AttributeAsInt("MinimumDamage"), node.AttributeAsInt("MaximumDamage")); } else if (itemCategory == GameItem.ItemCategory.Consumable) { gameItem.Action = new Heal(gameItem, node.AttributeAsInt("HitPointsToHeal")); } _standardGameItems.Add(gameItem); } }
private static void LoadItemsFromNodes(XmlNodeList nodes) { if (nodes == null) { return; } foreach (XmlNode node in nodes) { GameItem.ItemCategory itemCategory = DetermineItemCategory(node.Name); //Maybe turn this into a switch case and use the functions below GameItem gameItem = new GameItem(itemCategory, node.GetXmlAttributeAsInt("ID"), node.GetXmlAttributeAsString("Name"), node.GetXmlAttributeAsInt("Price"), false); if (itemCategory == GameItem.ItemCategory.Consumable) { gameItem.Action = new Heal(gameItem, node.GetXmlAttributeAsInt("HitPointsToHeal")); } _standardGameItems.Add(gameItem); } }
private static void LoadItemsFromNodes(XmlNodeList nodes) { if (nodes == null) { return; } foreach (XmlNode node in nodes) { GameItem.ItemCategory itemCategory = DetermineItemCategory(node.Name); GameItem gameItem = new GameItem(itemCategory, node.AttributeAsInt("ID"), node.AttributeAsString("NAME"), node.AttributeAsInt("PRICE"), itemCategory == GameItem.ItemCategory.Weapon); if (itemCategory == GameItem.ItemCategory.Weapon) { gameItem.ACTION = new AttackWithWeapon(gameItem, node.AttributeAsInt("MINDMG"), node.AttributeAsInt("MAXDMG")); } else if (itemCategory == GameItem.ItemCategory.Consumable) { gameItem.ACTION = new Heal(gameItem, node.AttributeAsInt("HPTOHEAL")); } _standardgameitems.Add(gameItem); } }
public static List <GameItem> ItemsThatAre(this IEnumerable <GameItem> inventory, GameItem.ItemCategory category) { return(inventory.Where(i => i.Category == category).ToList()); }