示例#1
0
文件: Game.cs 项目: Lorinet/HackLife
        public static int AddItem(Item itm)
        {
            int iid = GetInventoryID(itm.Glyph);

            if (iid == -1)
            {
                int index = 0;
                while (Inventory.ContainsKey(index))
                {
                    index++;
                }
                Inventory.Add(index, new Item(itm.Count, itm.Glyph));
                DrawInventorySlots();
                return(index);
            }
            else
            {
                Inventory[iid].Count += itm.Count;
                DrawInventorySlots();
                return(iid);
            }
        }
示例#2
0
文件: ThisGame.cs 项目: janoskaz/game
 public static Inventory LoadInventoryFromXml(XmlElement node)
 {
     int bagsize = int.Parse(node.GetAttribute("maxsize"));
     Inventory inv = new Inventory(bagsize);
     foreach (XmlNode child in node.ChildNodes)
     {
         XmlElement childElement = (XmlElement)child;
         string name = childElement.Name;
         switch(name)
         {
         case "Item":
         {
             inv.Add(LoadItemFromXml(childElement));
             break;
         }
         case "Equipment":
         {
             inv.Add(LoadEquipmentFromXml(childElement));
             break;
         }
         case "Weapon":
         {
             inv.Add(LoadWeaponFromXml(childElement));
             break;
         }
         }
     }
     return inv;
 }