示例#1
0
        public bool AddItem(InventoryItem item, short x, short y, Color color)
        {
            if (!IsPlaceable(item, x, y))
            {
                return(false);
            }
            InventoryActor temp = new InventoryActor(item, x, y, color);

            _inv.Add(temp);
            grid.Children.Add(temp.rect);
            return(true);
        }
示例#2
0
        public bool Move(InventoryActor item, short x, short y)
        {
            InventoryActor found = _inv.Find(i => i.Equals(item));

            if (found == null)
            {
                return(false);
            }
            if (!IsPlaceable(item.parent, x, y, item))
            {
                return(false);
            }
            found.X = x;
            found.Y = y;
            return(true);
        }
示例#3
0
        public bool IsPlaceable(InventoryItem item, short x, short y, InventoryActor ignoreEl = null)
        {
            if (x < 0 || x + item.width > _width || y < 0 || y + item.height > _height)
            {
                return(false);
            }
            List <int[]> positions = InventoryActor.GetItemPoitions(item, x, y);

            foreach (InventoryActor i in _inv)
            {
                if (i.Equals(ignoreEl))
                {
                    continue;
                }
                if (i.GetPositions().Exists(pos => positions.Exists(itemPos => itemPos[0] == pos[0] && itemPos[1] == pos[1])))
                {
                    return(false);
                }
            }
            return(true);
        }