public SpaceState(Area a, PGISlotItem it) { item = null; index = -1; area = a; item = it; }
public SpaceState(int i, PGISlotItem it) { item = null; index = i; area = new Area(-1, -1, -1, -1); item = it; }
bool Push(Area area, PGISlotItem item) { if (!HasSpaceAt(area)) { return(false); } History.Push(new SpaceState(area, item)); Set(area, true); return(true); }
/// <summary> /// Sets the state for a given area in the simulation grid. /// Remember that <c>true</c> means 'occupied' and <c>false</c> /// means 'empty'. /// </summary> /// <param name="area"></param> /// <param name="state"></param> public void Set(Area area, bool state) { int startX = area.x; int startY = area.y; for (int y = startY; y < startY + area.height; y++) { for (int x = startX; x < startX + area.width; x++) { Grid[x, y] = state; } } }
SpaceState FindFirstAvailableGridLocation(PGISlotItem item) { for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { Area a = new Area(x, y, item.CellWidth, item.CellHeight); if (HasSpaceAt(a)) { return(new SpaceState(a, item)); } } } return(SpaceState.Invalid); }
bool HasSpaceAt(Area area) { int startX = area.x; int startY = area.y; for (int y = startY; y < startY + area.height; y++) { for (int x = startX; x < startX + area.width; x++) { if (Grid[x, y]) { return(false); } } } return(true); }