Exemplo n.º 1
0
 /// <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);
 }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
 //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;
 }
Exemplo n.º 4
0
        //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();
        }
Exemplo n.º 5
0
 /// <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);
Exemplo n.º 6
0
 public VacuumMovedEvent(XmasPosition from, XmasPosition to)
 {
     this.From = from;
     this.To = to;
 }
Exemplo n.º 7
0
 public ConsolePlayerView(XmasEntity model, XmasPosition position, ThreadSafeEventManager evtman)
     : base(model, position, evtman)
 {
 }
Exemplo n.º 8
0
 public EntityAddedEvent(XmasEntity addedXmasEntity, XmasPosition position)
 {
     this.addedXmasEntity = addedXmasEntity;
     this.addedPosition = position;
 }
Exemplo n.º 9
0
 public override bool SetEntityPosition(XmasEntity xmasEntity, XmasPosition tilePosition)
 {
     return SetEntityPosition (xmasEntity, (TilePosition)tilePosition);
 }
Exemplo n.º 10
0
 public override EntityView ConstructEntityView(XmasEntity model, XmasPosition position)
 {
     return new LoggerEntityView(model, position, evtman, logstream);
 }
Exemplo n.º 11
0
 public ConsoleEntityView(XmasEntity model, XmasPosition position, ThreadSafeEventManager evtman)
     : base(model, position, evtman)
 {
     eventqueue.Register(new Trigger<UnitMovePostEvent>(entityView_UnitMovePostEvent));
 }
Exemplo n.º 12
0
        public override EntityView ConstructEntityView(XmasEntity model, XmasPosition position)
        {
            ConsoleEntityView retval = (ConsoleEntityView) Activator.CreateInstance(typeDict[model.GetType()], model, position, evtman);

            return retval;
        }
Exemplo n.º 13
0
 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));
 }
Exemplo n.º 14
0
 /// <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)
 {
 }
Exemplo n.º 16
0
 public PositionPercept(XmasPosition position)
 {
     this.position = position;
 }
Exemplo n.º 17
0
 public override ICollection<XmasEntity> GetEntities(XmasPosition pos)
 {
     Point p = ((TilePosition)pos).Point;
     return map [p].Entities;
 }