//Override this to get all entities on the world at a specific location public override ICollection<XmasEntity> GetEntities(XmasPosition pos) { var vpos = (VacuumPosition)pos; //check if the vacuum cleaner is located at the position //then return the entity, if not give an empty collection XmasEntity[] vacuum; if (this.vacuumTiles[vpos.PosID] != null) vacuum = new XmasEntity[] { this.vacuumTiles[vpos.PosID] }; else vacuum = new XmasEntity[0]; //Check if dirt is located on the given position XmasEntity[] dirt; if (this.dirtTiles[vpos.PosID] != null) dirt = new XmasEntity[] { this.dirtTiles[vpos.PosID] }; else dirt = new XmasEntity[0]; //Concatenate the two collections of dirt and vacuum cleaner //and make them into an array for the data to be immutable return vacuum.Concat(dirt).ToArray(); }
//Override this to provide the ability for the world to change position of the entity public override bool SetEntityPosition(XmasEntity xmasEntity, XmasPosition tilePosition) { //This can be implemented by removing the entity from its last location //and re-add it to the tile of its new position var pos = (VacuumPosition) tilePosition; var lastpos = (VacuumPosition)this.GetEntityPosition(xmasEntity); if (xmasEntity is VacuumCleanerAgent) { this.vacuumTiles[lastpos.PosID] = null; this.vacuumTiles[pos.PosID] = xmasEntity as VacuumCleanerAgent; return true; } else if (xmasEntity is DirtEntity) { this.dirtTiles[lastpos.PosID] = null; this.dirtTiles[pos.PosID] = xmasEntity as DirtEntity; return true; } return false; }
public VacuumMovedEvent(XmasPosition from, XmasPosition to) { this.From = from; this.To = to; }
/// <summary> /// Constructor for making an EntitySpawnInformation /// </summary> /// <param name="pos">The position of the spawn</param> public EntitySpawnInformation(XmasPosition pos) { this.pos = pos; }