public Event(Cell orginCell, Entity sourceEntity, Entity targetEntity, EventType type) { this.orginCell = orginCell; this.sourceEntity = sourceEntity; this.targetEntity = targetEntity; this.type = type; }
/// <summary> /// Returns a portion of the overall Map /// </summary> /// <param name="x">The X-coordinate of the origin Cell</param> /// <param name="y">The Y-coordinate of the origin Cell</param> /// <param name="width">The width of the area to return</param> /// <param name="height">The height of the area to return</param> /// <returns>The requested portion of the Map</returns> public Cell[,] getCells(int x, int y, int width, int height) { Cell[,] c = new Cell[width, height]; for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { c[i, j] = getCell(x + i, y + j); } } return c; }
/* * constructors */ /// <summary> /// Constructor /// </summary> /// <param name="width">Intended Map width</param> /// <param name="height">Intended Map height</param> public Map(int width, int height) { this.width = (short)width; this.height = (short)height; this.cells = new Cell[width, height]; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { cells[i, j] = new Cell(); cells[i, j].Xcoord = (short)i; cells[i, j].Ycoord = (short)j; } } }
/* * constructors */ /// <summary> /// Constructor /// </summary> /// <param name="width">Intended Map width</param> /// <param name="height">Intended Map height</param> public Map(int width, int height) { this.width = (byte)width; this.height = (byte)height; this.cells = new Cell[width, height]; for (byte i = 0; i < width; i++) { for (byte j = 0; j < height; j++) { cells[i, j] = new Cell(); cells[i, j].Xcoord = i; cells[i, j].Ycoord = j; } } }
/// <summary> /// Check if there is room for the building /// </summary> /// <param name="b">Building to be built</param> /// <param name="c">Cell to be origin cell</param> /// <returns>True if there is enough space, false if else</returns> public bool checkSpace(Building b, Cell c) { int x = c.Xcoord; int y = c.Ycoord; if (x < 0 || x + b.width > map.width) return false; if (y < 0 || y + b.height > map.height) return false; for (int i = x; i < x + b.width; i++) { for (int j = y; j < y + b.height; j++) { if (!map.getCell(i, j).isValid) return false; } } return true; }
/// <summary> /// Inserts a StaticEntity to the Map, if possible /// </summary> /// <param name="e">The StaticEntity to add</param> /// <param name="c">The intended origin Cell</param> /// <returns>True if insertion was successful, false if not</returns> public bool insert(StaticEntity e, Cell c) { return insert(e, c.Xcoord, c.Ycoord); }
/// <summary> /// Copy constructor /// </summary> /// <param name="c">The Cell to copy</param> public Cell(Cell c) { this.entity = c.entity; this.isValid = c.isValid; }
public void setCell(Cell cell) { this.myCell = cell; }
/// <summary> /// Gives a command to a unit to build a building. /// </summary> /// <param name="unit">Unit to build the building</param> /// <param name="b">Building to be built</param> /// <param name="c">Origin cell of the building-to-be</param> /// <returns></returns> public bool makeUnitBuild(Entity unit, Building b, Cell c) { if (unit.entityType == Entity.EntityType.Unit) { if (gameWorld.checkSpace(b, c) && gameWorld.checkResources(b, scenario.getPlayer())) { if (locController.addEntity(b, c.Xcoord, c.Ycoord)) { b.health = 1; return ActionController.Instance.giveCommand(unit, new BuildAction(b, (Unit)unit, gameWorld)); } else { return false; } } } return false; }
public void setOrginCell(Cell orginCell) { this.orginCell = orginCell; Console.WriteLine(orginCell.Xcoord + ", " + orginCell.Ycoord); }
public void setOrginCell(Cell orginCell) { this.orginCell = orginCell; }
/// <summary> /// Gives a command to a unit to build a building. /// </summary> /// <param name="unit">Unit to build the building</param> /// <param name="b">Building to be built</param> /// <param name="c">Origin cell of the building-to-be</param> /// <returns></returns> public bool makeUnitBuild(Entity unit, Building b, Cell c) { if (unit.entityType == Entity.EntityType.Unit) { if (gameWorld.checkSpace(b, c) && gameWorld.checkResources(b, scenario.getPlayer())) { gameWorld.insert(b, c); return ActionController.Instance.giveCommand(unit, new BuildAction(b, (Unit) unit, gameWorld)); } } return false; }