private void setUpController(Scenario scenario)
 {
     this.scenario      = scenario;
     this.gameWorld     = this.scenario.getGameWorld();
     this.visMapLogic   = new VisibilityMapLogic(scenario.getGameWorld(), scenario.getPlayer());
     this.locController = new EntityLocController(scenario, this.visMapLogic);
 }
        private void setUpController(Scenario scenario)
        {
            this.scenario         = scenario;
            this.gameWorld        = this.scenario.getGameWorld();
            this.actionController = new ActionController(scenario);
            this.locController    = new EntityLocController(scenario);


            setUpFactories();
            this.creator = new EntityCreator(this.unitFactory, this.buildingFactory);
        }
/*** HELPER FUNCTIONS ****/

        /// <summary>
        /// This function will search the cells that the unit can see for the closest enemy Unit.
        /// </summary>
        /// <param name="unit">The unit doing the searching</param>
        /// <param name="gw">The GameWorld to search</param>
        /// <returns>The closest enemy Unit or null if none exists</returns>
        private static Unit searchCellsForEnemy(Unit unit, GameWorld gw)
        {
            byte offset = (byte)unit.stats.visibilityRange;

            int xStart = (short)unit.x - offset;
            int xEnd   = (short)unit.x + offset;
            int yStart = (short)unit.y - offset;
            int yEnd   = (short)unit.y + offset;

            // Make sure that our bounds are valid. (Assumes that no Unit has a visibility range longer than the map.)
            if (xStart < 0)
            {
                xStart = 0;
            }
            else if (xEnd >= gw.map.width)
            {
                xEnd = gw.map.width;
            }

            if (yStart < 0)
            {
                yStart = 0;
            }
            else if (yEnd >= gw.map.height)
            {
                yEnd = gw.map.height;
            }

            Unit  target   = null;
            float distance = 10000f;

            // Set all cell explored flags to true.
            for (int i = xStart; i < xEnd; i++)
            {
                for (int j = yStart; j < yEnd; j++)
                {
                    Unit temp = gw.map.getCell(i, j).getUnit();

                    if (temp != null && unit.getOwner().isEnemy(temp.getOwner()))
                    {
                        float tDis = EntityLocController.findDistance(unit.x, unit.y, temp.x, temp.y);

                        if (tDis < distance)
                        {
                            target   = temp;
                            distance = tDis;
                        }
                    }
                }
            }

            return(target);
        }
        /// <summary>
        /// Given an entity, this function will cause the entity to perform whatever action is currently on the entity's
        /// action queue.
        /// </summary>
        /// <param name="entity"></param>
        public void update(Entity entity, EntityLocController locController)
        {
            Queue<ActionCommand> actionQueue = entity.getActionQueue();
            if(actionQueue.Count > 0)
            {
                ActionCommand command = actionQueue.Peek();

                if (command.work())
                {
                    actionQueue.Dequeue();
                }
                if (entity.entityType == Entity.EntityType.Unit)
                {
                    locController.updateUnitLocation((Unit)entity);
                }
            }
        }
        /// <summary>
        /// Given an entity, this function will cause the entity to perform whatever action is currently on the entity's
        /// action queue.
        /// </summary>
        /// <param name="entity"></param>
        public void update(Entity entity, EntityLocController locController)
        {
            Queue <ActionCommand> actionQueue = entity.getActionQueue();

            if (actionQueue.Count > 0)
            {
                ActionCommand command = actionQueue.Peek();

                if (command.work())
                {
                    actionQueue.Dequeue();
                }
                if (entity.entityType == Entity.EntityType.Unit)
                {
                    locController.updateUnitLocation((Unit)entity);
                }
            }
        }
        /// <summary>
        /// Given an entity, this function will cause the entity to perform whatever action is currently on the entity's
        /// action queue.
        /// </summary>
        /// <param name="entity"></param>
        public void update(Entity entity, EntityLocController locController)
        {
            List <ActionCommand> actionQueue = entity.getActionQueue();

            if (actionQueue.Count > 0)
            {
                ActionCommand command = actionQueue[0];
                //Console.WriteLine(command.actionType);
                if (command.work())
                {
                    // Action is done, remove and set Entity's state to idle.
                    actionQueue.RemoveAt(0);
                    entity.getState().setPrimaryState(State.PrimaryState.Idle);
                }

                if (entity.entityType == Entity.EntityType.Unit)
                {
                    // Unit may have moved, update it's location in the GameWorld.
                    locController.updateUnitLocation((Unit)entity);
                }
            }
        }
        /// <summary>
        /// This method will find the cell closest to 'unit' that 'entity' is currently occupying.
        /// </summary>
        /// <param name="unit"></param>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static Cell findClosestCell(Unit unit, StaticEntity se, GameWorld gw)
        {
            Cell  cell = null;
            float dis  = 10000;

            short xC     = se.orginCell.Xcoord;
            short yC     = se.orginCell.Ycoord;
            short width  = se.width;
            short height = se.height;

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    if (EntityLocController.findDistance(unit.x, unit.y, xC + i, yC + j) <= dis)
                    {
                        cell = gw.map.getCell(xC + i, yC + j);
                        dis  = EntityLocController.findDistance(unit.x, unit.y, xC + i, yC + j);
                    }
                }
            }

            return(cell);
        }
        private void setUpController(Scenario scenario)
        {
            this.scenario = scenario;
            this.gameWorld = this.scenario.getGameWorld();
            this.actionController = new ActionController(scenario);
            this.locController = new EntityLocController(scenario);

            setUpFactories();
            this.creator = new EntityCreator(this.unitFactory, this.buildingFactory);
        }
 private void setUpController(Scenario scenario)
 {
     this.scenario = scenario;
     this.gameWorld = this.scenario.getGameWorld();
     this.visMapLogic = new VisibilityMapLogic(scenario.getGameWorld(), scenario.getPlayer());
     this.locController = new EntityLocController(scenario, this.visMapLogic);
 }
        /// <summary>
        /// Given an entity, this function will cause the entity to perform whatever action is currently on the entity's
        /// action queue.
        /// </summary>
        /// <param name="entity"></param>
        public void update(Entity entity, EntityLocController locController)
        {
            List<ActionCommand> actionQueue = entity.getActionQueue();
            if(actionQueue.Count > 0)
            {
                ActionCommand command = actionQueue[0];

                if (command.work())
                {
                    // Action is done, remove and set Entity's state to idle.
                    actionQueue.RemoveAt(0);
                    entity.getState().setPrimaryState(State.PrimaryState.Idle);
                }

                if (entity.entityType == Entity.EntityType.Unit)
                {
                    // Unit may have moved, update it's location in the GameWorld.
                    locController.updateUnitLocation((Unit)entity);
                }
            }
        }