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); }
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); }
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); }