/// <summary> /// Constructs a new EntityView /// </summary> /// <param name="model">The entity that view is meant to show</param> /// <param name="position">The position of the entity</param> /// <param name="tman">The ThreadSafeEventManager that is controlled the XmasView</param> public EntityView(XmasEntity model, XmasPosition position, ThreadSafeEventManager tman) { this.model = model; this.Position = position; eventqueue = model.ConstructEventQueue(); tman.AddEventQueue(eventqueue); }
public LoggerEntityView(XmasEntity model , XmasPosition position , ThreadSafeEventManager evtman , Logger logstream ) : base(model, position, evtman) { this.logstream = logstream; eventqueue.Register (new Trigger<UnitMovePostEvent> (entity_UnitMovePostEvent)); eventqueue.Register (new Trigger<UnitMovePreEvent> (entity_UnitMovePreEvent)); eventqueue.Register (new Trigger<PackageGrabbedEvent> (entity_PackageGrabbedEvent)); }
//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; }
//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(); }
/// <summary> /// Sets the position of an entity /// </summary> /// <param name="xmasEntity">The entity which position is being set</param> /// <param name="tilePosition">The position where the entity is set</param> /// <returns>Whether or not it could be succesfully set at that position</returns> public abstract bool SetEntityPosition(XmasEntity xmasEntity, XmasPosition tilePosition);
public VacuumMovedEvent(XmasPosition from, XmasPosition to) { this.From = from; this.To = to; }
public ConsolePlayerView(XmasEntity model, XmasPosition position, ThreadSafeEventManager evtman) : base(model, position, evtman) { }
public EntityAddedEvent(XmasEntity addedXmasEntity, XmasPosition position) { this.addedXmasEntity = addedXmasEntity; this.addedPosition = position; }
public override bool SetEntityPosition(XmasEntity xmasEntity, XmasPosition tilePosition) { return SetEntityPosition (xmasEntity, (TilePosition)tilePosition); }
public override EntityView ConstructEntityView(XmasEntity model, XmasPosition position) { return new LoggerEntityView(model, position, evtman, logstream); }
public ConsoleEntityView(XmasEntity model, XmasPosition position, ThreadSafeEventManager evtman) : base(model, position, evtman) { eventqueue.Register(new Trigger<UnitMovePostEvent>(entityView_UnitMovePostEvent)); }
public override EntityView ConstructEntityView(XmasEntity model, XmasPosition position) { ConsoleEntityView retval = (ConsoleEntityView) Activator.CreateInstance(typeDict[model.GetType()], model, position, evtman); return retval; }
public ConsoleGrabberView(XmasEntity model, XmasPosition position, ThreadSafeEventManager evtman) : base(model, position, evtman) { this.EventQueue.Register(new Trigger<PackageGrabbedEvent>(_ => haspackage = true)); this.eventqueue.Register(new Trigger<PackageReleasedEvent>(_ => haspackage = false)); }
/// <summary> /// Gets a collection of entities which are located at a certain position /// </summary> /// <param name="pos">The position where the entities are retrieved from</param> /// <returns>a collection of entities</returns> public abstract ICollection<XmasEntity> GetEntities(XmasPosition pos);
public ConsoleImpassableWallView(XmasEntity model, XmasPosition position, ThreadSafeEventManager evtman) : base(model, position, evtman) { }
public PositionPercept(XmasPosition position) { this.position = position; }
public override ICollection<XmasEntity> GetEntities(XmasPosition pos) { Point p = ((TilePosition)pos).Point; return map [p].Entities; }