// Gets necessary points from the slot shape to only include relevant points // ie) in the case of { 0, 0, 1} only point (2, 0) is relevant 'cause the first two are empty // ---------------------------^ this point public static List <Vector2> FilterPoints(SlotShape slotShape) { List <Vector2> gridSlots = new List <Vector2>(); for (int y = 0; y < slotShape.Shape.GetLength(0); y++) { for (int x = 0; x < slotShape.Shape.GetLength(1); x++) { if (slotShape.IsOpenSlot(x, y)) { gridSlots.Add(new Vector2(x, y)); } } } return(gridSlots); }
// Populates Inventory with InventorySlots along the possible areas of the slotShape used. // Creating A Slot: SlotShape --- InventorySlot // { 1 1 1 } [ ] [ ] [ ] // { 1 1 1 } ---> [ ] [ ] [ ] = 7 created Slots // { 0 1 0 } ... [ ] ... private int PopulateInventory(SlotShape slotShape) { int slotsCreated = 0; for (int y = 0; y < _inventorySlots.GetLength(0); y++) { for (int x = 0; x < _inventorySlots.GetLength(1); x++) { if (slotShape.IsOpenSlot(x, y)) { if (CreateInventorySlot(x, y)) { slotsCreated++; } } } } return(slotsCreated); }
public void SlotShapeTests() { SlotShape ss = new SlotShape(); Assert.AreEqual("[ ]\n", ss.ToString()); ss = new SlotShape(new int[, ] { { 1, 0, 1 } }); Assert.AreEqual("[ ] [ ]\n", ss.ToString()); ss = new SlotShape(new int[, ] { { 1 }, { 0 }, { 1 } }); Assert.AreEqual("[ ]\n \n[ ]\n", ss.ToString()); ss = new SlotShape(new int[, ] { { 1, 1, 1 }, { 1, 1, 1 }, { 1, 1, 1 } }); Assert.AreEqual("[ ][ ][ ]\n[ ][ ][ ]\n[ ][ ][ ]\n", ss.ToString()); ss = new SlotShape(new int[, ] { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } }); Assert.AreEqual(" \n \n \n", ss.ToString()); ss = new SlotShape(new int[, ] { { 1, 0, 1 }, { 0, 1, 0 }, { 1, 0, 1 } }); Assert.AreEqual(true, ss.IsOpenSlot(0, 0)); Assert.AreEqual(false, ss.IsOpenSlot(1, 0)); Assert.AreEqual(true, ss.IsOpenSlot(2, 0)); Assert.AreEqual(false, ss.IsOpenSlot(0, 1)); Assert.AreEqual(true, ss.IsOpenSlot(1, 1)); Assert.AreEqual(false, ss.IsOpenSlot(2, 1)); Assert.AreEqual(true, ss.IsOpenSlot(0, 2)); Assert.AreEqual(false, ss.IsOpenSlot(1, 2)); Assert.AreEqual(true, ss.IsOpenSlot(2, 2)); }