コード例 #1
0
 private void VisitChildren(ModelComponent component)
 {
     foreach (ModelComponent child in component.GetChildren())
     {
         child.Accept(this);
     }
 }
コード例 #2
0
        override public void AddChild(ModelComponent child)
        {
            // Ensure that we only have one tile or resource
            List <ModelComponent> toRemove = new List <ModelComponent>();

            if (child is Tile)
            {
                foreach (ModelComponent tile in GetChildren())
                {
                    if (tile is Tile)
                    {
                        toRemove.Add(tile);
                    }
                }
            }
            else if (child is MapResource)
            {
                foreach (ModelComponent resource in GetChildren())
                {
                    if (resource is MapResource)
                    {
                        toRemove.Add(resource);
                    }
                }
            }
            foreach (ModelComponent component in toRemove)
            {
                // Called in this manner to avoid the NotifyAll in RemoveChild().
                GetChildren().Remove(component);
            }
            // Handles the nofity.
            base.AddChild(child);
        }
        private void listenToCellsWithinVisibilityRange()
        {
            // Get the Correct Bounds.
            int startX = getStartX();
            int endX   = getEndX();
            int startY = getStartY();
            int endY   = getEndY();

            // Get the Map object.
            ModelComponent gameWorldComponent = location;

            while (!(gameWorldComponent is Gameworld))
            {
                gameWorldComponent = gameWorldComponent.Parent;
            }
            Map map = ((Gameworld)(gameWorldComponent)).GetMap();

            for (int i = startX; i <= endX; i++)
            {
                for (int j = startY; j <= endY; j++)
                {
                    CellComponent cell = map.GetCellAt(i, j);
                    cell.UnitAddedEvent += new EntityInCellChangedHandler(handleUnitAddedToCell);
                }
            }
        }
        public override void AddChild(ModelComponent child)
        {
            // Ensure that we only have one tile or resource
            List<ModelComponent> toRemove =  new List<ModelComponent>();
            if (child is Tile)
            {
                foreach (ModelComponent tile in GetChildren())
                {
                    if (tile is Tile)
                    {
                        toRemove.Add(tile);
                    }
                }
            }
            else if (child is MapResource)
            {
                foreach (ModelComponent resource in GetChildren())
                {
                    if (resource is MapResource)
                    {
                        toRemove.Add(resource);
                    }
                }
            }
            foreach (ModelComponent component in toRemove)
            {
                // Called in this manner to avoid the NotifyAll in RemoveChild().
                GetChildren().Remove(component);

            }
            // Handles the nofity.
            base.AddChild(child);
        }
 /// <summary>
 /// Creates and fires an UnitAttackedEnemyEvent
 /// </summary>
 /// <param name="target">The target the UnitComponent is attacking.</param>
 public void createAttackEvent(ModelComponent target)
 {
     if (UnitAttackedEnemyHanlders != null)
     {
         UnitAttackedEnemyHanlders(this, new UnitAttackedEnemyArgs(target));
     }
 }
 public override void RemoveChild(ModelComponent child)
 {
     if (child != actionQueue)
     {
         base.RemoveChild(child);
     }
 }
 public void Visit(ModelComponent component)
 {
     if (AbstractComponentVisitor != null)
     {
         component.Accept(AbstractComponentVisitor);
     }
 }
コード例 #8
0
        /// <summary>
        /// Add game entity to this cell
        /// </summary>
        /// <param name="entity">The Entity to add</param>
        public void AddEntity(ModelComponent entity)
        {
            if (entitiesContainedWithin.Count == 0)
            {
                if (entity is UnitComponent || entity is MapResource || entity is Building)
                {
                    entitiesContainedWithin.Add(entity);

                    if (entity is UnitComponent)
                    {
                        UnitArgs args = new UnitArgs();
                        args.Unit = (UnitComponent)entity;
                        args.Unit.UnitAttackedEnemyHanlders += new UnitAttackedEnemyHandler(handleUnitInCellAttackingEnemy);
                        if (UnitAddedEvent != null)
                        {
                            UnitAddedEvent(this, args);
                        }
                    }
                    if (entity is Building)
                    {
                        // do nothing special?
                    }
                }
            }
        }
        public virtual void AddChild(ModelComponent child)
        {
            children.Add(child);

            // Handles the NotifyAll()
            child.SetContainer(this);
        }
コード例 #10
0
        public virtual void AddChild(ModelComponent child)
        {
            children.Add(child);

            // Handles the NotifyAll()
            child.SetContainer(this);
        }
        private void stopListeningToCells(PointF oldPoint)
        {
            // Get the Correct Bounds.
            int startX = getStartX();
            int endX   = getEndX();
            int startY = getStartX();
            int endY   = getEndY();

            // Get the Map object for this game.
            ModelComponent gameWorldComponent = location;

            while (!(gameWorldComponent is Gameworld))
            {
                gameWorldComponent = gameWorldComponent.Parent;
            }
            Map map = ((Gameworld)(gameWorldComponent)).GetMap();

            for (int i = startX; i < endX; i++)
            {
                for (int j = startY; j < endY; j++)
                {
                    CellComponent cell = map.GetCellAt(i, j);
                    cell.UnitAddedEvent -= new EntityInCellChangedHandler(handleUnitAddedToCell);
                }
            }
        }
        private bool unitIsAnEnemy(UnitComponent unit)
        {
            // Find the PlayerComponent of unit.
            ModelComponent temp = unit.Parent;

            while (!(temp is PlayerComponent || temp == null))
            {
                temp = temp.Parent;
            }
            if (temp == null)
            {
                return(false);
            }
            PlayerComponent unitOwner = (PlayerComponent)temp;

            // Find the PlayerComponent of this UnitComponent;
            temp = this.Parent;
            while (!(temp is PlayerComponent || temp == null))
            {
                temp = temp.Parent;
            }
            if (temp == null)
            {
                return(false);
            }
            PlayerComponent myOwner = (PlayerComponent)temp;

            return(myOwner.EnemyList.Contains(unitOwner));
        }
コード例 #13
0
 public override void AddChild(ModelComponent child)
 {
     if (child is EntityAction)
     {
         base.AddChild(child);
     }
 }
コード例 #14
0
        private bool addUnit()
        {
            // Get the player who owns this building.
            ModelComponent temp = building.Parent;

            while (!(temp is PlayerComponent))
            {
                temp = temp.Parent;
            }
            PlayerComponent player = (PlayerComponent)temp;

            // Get the Gameworld.
            while (!(temp is ZRTSModel.GameModel.GameModel))
            {
                temp = temp.Parent;
            }
            ZRTSModel.GameModel.GameModel model = (ZRTSModel.GameModel.GameModel)temp;

            // Get the CellComponent to insert into.
            CellComponent insertCell = findEmptyNeighborCell(model);

            if (insertCell == null)
            {
                return(false);                // No empty CellComponent.
            }

            // Add Unit to the Map.
            UnitComponent unit = new UnitComponent(stats);

            unit.PointLocation = new PointF(insertCell.X + 0.5f, insertCell.Y + 0.5f);

            // Add Unit to the Player who owns the building.
            player.GetUnitList().AddChild(unit);
            return(true);
        }
 public virtual void AddChild(ModelComponent child)
 {
     if (child != null)
     {
         child.SetContainer(this);
         children.Add(child);
     }
 }
 public void Visit(ModelComponent component)
 {
     component.UnregisterAll();
     foreach (ModelComponent c in component.GetChildren())
     {
         c.Accept(this);
     }
 }
 public void Visit(ModelComponent component)
 {
     component.UnregisterAll();
     foreach (ModelComponent c in component.GetChildren())
     {
         c.Accept(this);
     }
 }
コード例 #18
0
 public virtual void AddChild(ModelComponent child)
 {
     if (child != null)
     {
         child.SetContainer(this);
         children.Add(child);
     }
 }
コード例 #19
0
 public void SetContainer(ModelComponent composite)
 {
     if (container != null)
     {
         container.GetChildren().Remove(this);
     }
     container = composite;
 }
コード例 #20
0
 /// <summary>
 /// Removes a PlayerComponent from the list
 /// </summary>
 /// <param name="child"></param>
 public override void RemoveChild(ModelComponent child)
 {
     base.RemoveChild(child);
     PlayerListChangedEventArgs e = new PlayerListChangedEventArgs();
     e.PlayersAddedOrRemoved.Add((PlayerComponent)child);
     if (PlayerRemovedEvent != null)
     {
         PlayerRemovedEvent(this, e);
     }
 }
コード例 #21
0
 /// <summary>
 /// Removes a child ModelComponent from the UnitList if it is contained by this. Fires
 /// off an UnitRemovedEvent.
 /// </summary>
 /// <param name="child"></param>
 public override void RemoveChild(ModelComponent child)
 {
     base.RemoveChild(child);
     if (UnitRemovedEvent != null && child is UnitComponent)
     {
         UnitRemovedEventArgs args = new UnitRemovedEventArgs();
         args.Unit = (UnitComponent)child;
         UnitRemovedEvent(this, args);
     }
 }
コード例 #22
0
        UnitComponent unit; // Unit performing the AttackAction

        #endregion Fields

        #region Constructors

        public AttackAction(UnitComponent unit, ModelComponent target, Gameworld gw)
        {
            this.unit = unit;

            if (target is UnitComponent)
            {
                this.target = (UnitComponent)target;
            }
            this.gw = gw;
        }
コード例 #23
0
 public override void RemoveChild(ModelComponent child)
 {
     base.RemoveChild(child);
     if (UnitRemovedEvent != null && child is UnitComponent)
     {
         UnitRemovedEventArgs args = new UnitRemovedEventArgs();
         args.Unit = (UnitComponent)child;
         UnitRemovedEvent(this, args);
     }
 }
コード例 #24
0
 /// <summary>
 /// Remove cell from the map
 /// </summary>
 /// <param name="child"></param>
 public override void RemoveChild(ModelComponent child)
 {
     if (GetChildren().Contains(child))
     {
         // This ensures that the child is a cell, and that it is actually contained in the map.
         CellComponent cell = (CellComponent)child;
         cells[cell.X, cell.Y] = null;
         base.RemoveChild(child);
     }
 }
コード例 #25
0
        UnitComponent unit;         // Unit performing the AttackAction
        public AttackAction(UnitComponent unit, ModelComponent target, Gameworld gw)
        {
            this.unit = unit;

            if (target is UnitComponent)
            {
                this.target = (UnitComponent)target;
            }
            this.gw = gw;
        }
コード例 #26
0
        /// <summary>
        /// Removes a PlayerComponent from the list. Fires an PlayerRemovedEvent.
        /// </summary>
        /// <param name="child"></param>
        public override void RemoveChild(ModelComponent child)
        {
            base.RemoveChild(child);
            PlayerListChangedEventArgs e = new PlayerListChangedEventArgs();

            e.PlayersAddedOrRemoved.Add((PlayerComponent)child);
            if (PlayerRemovedEvent != null)
            {
                PlayerRemovedEvent(this, e);
            }
        }
コード例 #27
0
 /// <summary>
 /// Adds a child to the UnitList. Only add's the child if it is a UnitComponent.
 /// Fires off an UnitAddedEvent.
 /// </summary>
 /// <param name="child">The ModelComponent to be added.</param>
 public override void AddChild(ModelComponent child)
 {
     if (child is UnitComponent)
     {
         base.AddChild(child);
         UnitAddedEventArgs args = new UnitAddedEventArgs();
         args.Unit = (UnitComponent) child;
         if (UnitAddedEvent != null)
         {
             UnitAddedEvent(this, args);
         }
     }
 }
 public override void AddChild(ModelComponent child)
 {
     // Allow only one scenario.
     if (child is ScenarioComponent)
     {
         ScenarioComponent scenario = GetScenario();
         if (scenario != null)
         {
             RemoveChild(scenario);
         }
     }
     base.AddChild(child);
 }
 public void AddChildAt(ModelComponent child, int p)
 {
     if (child != null)
     {
         AddChild(child);
         // Some classes may override add child to only accept certain children.  Ensure that it got added before placing it in the correct location.
         if (GetChildren().Contains(child))
         {
             GetChildren().Remove(child);
             GetChildren().Insert(0, child);
         }
     }
 }
コード例 #30
0
 public void AddChildAt(ModelComponent child, int p)
 {
     if (child != null)
     {
         AddChild(child);
         // Some classes may override add child to only accept certain children.  Ensure that it got added before placing it in the correct location.
         if (GetChildren().Contains(child))
         {
             GetChildren().Remove(child);
             GetChildren().Insert(0, child);
         }
     }
 }
コード例 #31
0
 public override void AddChild(ModelComponent child)
 {
     if (child is UnitComponent)
     {
         base.AddChild(child);
         UnitAddedEventArgs args = new UnitAddedEventArgs();
         args.Unit = (UnitComponent)child;
         if (UnitAddedEvent != null)
         {
             UnitAddedEvent(this, args);
         }
     }
 }
コード例 #32
0
        /// <summary>
        /// Adds a Component to this CellComponent.
        /// </summary>
        /// <param name="child">The Component to add</param>
        override public void AddChild(ModelComponent child)
        {
            // Ensure that we only have one tile or resource
            List <ModelComponent> toRemove = new List <ModelComponent>();

            if (child is Tile)
            {
                foreach (ModelComponent tile in GetChildren())
                {
                    if (tile is Tile)
                    {
                        toRemove.Add(tile);
                    }
                }
            }
            else if (child is MapResource)
            {
                foreach (ModelComponent resource in GetChildren())
                {
                    if (resource is MapResource)
                    {
                        toRemove.Add(resource);
                        if (entitiesContainedWithin.Count != 0)
                        {
                            UnitArgs args = new UnitArgs();
                            args.Unit = (UnitComponent)entitiesContainedWithin[0];
                            entitiesContainedWithin.Clear();
                            if (UnitRemovedEvent != null)
                            {
                                UnitRemovedEvent(this, args);
                            }
                        }
                    }
                }
                entitiesContainedWithin.Add(child);
            }
            foreach (ModelComponent component in toRemove)
            {
                RemoveChild(component);
            }
            base.AddChild(child);

            // Handle notifications
            if (child is Tile)
            {
                if (TileChangedEvent != null)
                {
                    TileChangedEvent(this, new TileChangedEventArgs((Tile)child));
                }
            }
        }
コード例 #33
0
 /// <summary>
 /// Removed a BuildingComponent from this object. Fires off a BuildingRemoved event.
 /// </summary>
 /// <param name="child">The BuildingComponent to be removed.</param>
 public override void RemoveChild(ModelComponent child)
 {
     if (child is Building)
     {
         Building building = child as Building;
         base.RemoveChild(child);
         if (BuildingRemovedEventHandlers != null)
         {
             BuildingAddedEventArgs e = new BuildingAddedEventArgs();
             e.Building = building;
             BuildingRemovedEventHandlers(this, e);
         }
     }
 }
コード例 #34
0
 /// <summary>
 /// Removes an Entity from this Cell.
 /// </summary>
 /// <param name="entity">The Entity to remove</param>
 public void RemoveEntity(ModelComponent entity)
 {
     entitiesContainedWithin.Remove(entity);
     if (entity is UnitComponent)
     {
         UnitArgs args = new UnitArgs();
         args.Unit = (UnitComponent)entity;
         args.Unit.UnitAttackedEnemyHanlders -= new UnitAttackedEnemyHandler(handleUnitInCellAttackingEnemy);
         if (UnitRemovedEvent != null)
         {
             UnitRemovedEvent(this, args);
         }
     }
 }
コード例 #35
0
        /// <summary>
        /// Remove building from the Map.
        /// </summary>
        /// <param name="component">The building to remove</param>
        /// <returns>True if successfully removed from the map</returns>
        public bool removeBuildingFromMap(ModelComponent component)
        {
            Building tempBuild = (Building)component;

            for (int i = (int)tempBuild.PointLocation.X; i < (int)tempBuild.PointLocation.X + tempBuild.Width; ++i)
            {
                for (int j = (int)tempBuild.PointLocation.Y; j < (int)tempBuild.PointLocation.Y + tempBuild.Height; ++j)
                {
                    tempBuild.CellsContainedWithin.Remove(GetCellAt(i, j));
                    GetCellAt(i, j).RemoveEntity(tempBuild);
                }
            }
            return(true);
        }
コード例 #36
0
 public override void RemoveChild(ModelComponent child)
 {
     if (child is Building)
     {
         Building building = child as Building;
         base.RemoveChild(child);
         if (BuildingRemovedEventHandlers != null)
         {
             BuildingAddedEventArgs e = new BuildingAddedEventArgs();
             e.Building = building;
             BuildingRemovedEventHandlers(this, e);
         }
     }
 }
 /// <summary>
 /// Checks the accepting component to see if it is the type we are looking for, and if so, checks for the child given at construction.
 /// Updates the state of the visitor and ensures that it will not be evaluated again.
 /// </summary>
 /// <param name="component"></param>
 public override void Visit(ModelComponent component)
 {
     if (modelType.GetType().Equals(component.GetType()) && !evaluated)
     {
         foreach (ModelComponent mc in component.GetChildren())
         {
             if (mc == child)
             {
                 containsChild = true;
                 break;
             }
         }
         evaluated = true;
     }
 }
        /// <summary>
        /// Adds a Component to this CellComponent.
        /// </summary>
        /// <param name="child">The Component to add</param>
        public override void AddChild(ModelComponent child)
        {
            // Ensure that we only have one tile or resource
            List<ModelComponent> toRemove =  new List<ModelComponent>();
            if (child is Tile)
            {
                foreach (ModelComponent tile in GetChildren())
                {
                    if (tile is Tile)
                    {
                        toRemove.Add(tile);
                    }
                }
            }
            else if (child is MapResource)
            {
                foreach (ModelComponent resource in GetChildren())
                {
                    if (resource is MapResource)
                    {
                        toRemove.Add(resource);
                        if (entitiesContainedWithin.Count != 0)
                        {
                            UnitArgs args = new UnitArgs();
                            args.Unit = (UnitComponent)entitiesContainedWithin[0];
                            entitiesContainedWithin.Clear();
                            if (UnitRemovedEvent != null)
                                UnitRemovedEvent(this, args);
                        }
                    }
                }
                entitiesContainedWithin.Add(child);
            }
            foreach (ModelComponent component in toRemove)
            {
                RemoveChild(component);
            }
            base.AddChild(child);

            // Handle notifications
            if (child is Tile)
            {
                if (TileChangedEvent != null)
                {
                    TileChangedEvent(this, new TileChangedEventArgs((Tile)child));
                }
            }
        }
コード例 #39
0
 /// <summary>
 /// Add building to the Map.
 /// </summary>
 /// <param name="component">The building to add</param>
 /// <returns>True if successfully added to the map</returns>
 public bool addBuildingToMap(ModelComponent component)
 {
     if (canAddBuildingToMap(component))
     {
         Building tempBuild = (Building)component;
         for (int i = (int)tempBuild.PointLocation.X; i < (int)tempBuild.PointLocation.X + tempBuild.Width; ++i)
         {
             for (int j = (int)tempBuild.PointLocation.Y; j < (int)tempBuild.PointLocation.Y + tempBuild.Height; ++j)
             {
                 tempBuild.CellsContainedWithin.Add(GetCellAt(i, j));
                 GetCellAt(i, j).AddEntity(tempBuild);
             }
         }
         return true;
     }
     else return false;
 }
コード例 #40
0
        /// <summary>
        /// Check if the building can be added to the map.  A building can only be added to the Map if there is enough space to
        /// place the building and there are no Entities on those spaces.
        /// </summary>
        /// <param name="component">The building to add</param>
        /// <returns>True if building can be added or the component is not the building, otherwise, false is returned!</returns>
        public bool canAddBuildingToMap(ModelComponent component)
        {
            if (component is Building)
            {
                Building tempBuild = (Building)component;
                if (GetCellAt((int)tempBuild.PointLocation.X, (int)tempBuild.PointLocation.Y).ContainsEntity())
                {
                    return(false);
                }
                else
                {
                    return(isEnoughSpace(tempBuild));
                }
            }

            return(false);
        }
        private int getEndX()
        {
            int            endX = (int)pointLocation.X + (int)visibilityRange;
            ModelComponent gameWorldComponent = location;

            while (!(gameWorldComponent is Gameworld))
            {
                gameWorldComponent = gameWorldComponent.Parent;
            }
            Map map = ((Gameworld)(gameWorldComponent)).GetMap();

            if (endX >= map.GetWidth())
            {
                endX = map.GetWidth() - 1;
            }

            return(endX);
        }
        public void SetContainer(ModelComponent composite)
        {
            ModelComponent tempContainer = container;
            if (container != null)
            {
                container.GetChildren().Remove(this);
            }
            container = composite;

            // Notify the new tree.
            NotifyAll();

            if (tempContainer != null)
            {
                // Notify the old tree.
                tempContainer.NotifyAll();
            }
        }
        private int getEndY()
        {
            int            endY = (int)pointLocation.Y + (int)visibilityRange;
            ModelComponent gameWorldComponent = location;

            while (!(gameWorldComponent is Gameworld))
            {
                gameWorldComponent = gameWorldComponent.Parent;
            }
            Map map = ((Gameworld)(gameWorldComponent)).GetMap();

            if (endY >= map.GetHeight())
            {
                endY = map.GetHeight() - 1;
            }

            return(endY);
        }
コード例 #44
0
 /// <summary>
 /// Add cell to the map (aka tile)
 /// </summary>
 /// <param name="child"></param>
 public override void AddChild(ModelComponent child)
 {
     // Ensure that only cells are children to the map
     if (child is CellComponent)
     {
         CellComponent cell = (CellComponent)child;
         // Ensure that the cell is inbounds
         if (cell.X >= 0 && cell.X < width && cell.Y >= 0 && cell.Y < height)
         {
             // Remove cell currently located at that position
             if (cells[cell.X, cell.Y] != null)
             {
                 RemoveChild(cells[cell.X, cell.Y]);
             }
             cells[cell.X, cell.Y] = cell;
             base.AddChild(cell);
         }
     }
 }
コード例 #45
0
 /// <summary>
 /// Add cell to the map (aka tile)
 /// </summary>
 /// <param name="child"></param>
 public override void AddChild(ModelComponent child)
 {
     // Ensure that only cells are children to the map
     if (child is CellComponent)
     {
         CellComponent cell = (CellComponent)child;
         // Ensure that the cell is inbounds
         if (cell.X >= 0 && cell.X < width && cell.Y >= 0 && cell.Y < height)
         {
             // Remove cell currently located at that position
             if (cells[cell.X, cell.Y] != null)
             {
                 RemoveChild(cells[cell.X, cell.Y]);
             }
             cells[cell.X, cell.Y] = cell;
             base.AddChild(cell);
         }
     }
 }
 private void handleUnitAddedToCell(object obj, UnitArgs e)
 {
     if (e.Unit == this)             // I'm seeing my own move event.
     {
     }
     else             // Saw another Unit added to a CellComponent.
     {
         if (unitIsAnEnemy(e.Unit) && this.AttackStance == UnitAttackStance.Aggressive && this.actionQueue.GetChildren().Count == 0)
         {
             ModelComponent temp = Parent;
             while (!(temp is Gameworld))
             {
                 temp = temp.Parent;
             }
             AttackAction attackAction = new AttackAction(this, e.Unit, (Gameworld)temp);
             actionQueue.AddChild(attackAction);
         }
     }
 }
 /// <summary>
 /// Overrides AddChild from ModelComponent to ensure that the model is composed of only one scenario.
 /// </summary>
 /// <param name="child"></param>
 public override void AddChild(ModelComponent child)
 {
     // Allow only one scenario.
     if (child is ScenarioComponent)
     {
         ScenarioComponent scenario = GetScenario();
         if (scenario != null)
         {
             RemoveChild(scenario);
         }
         base.AddChild(child);
         if (ScenarioChangedEvent != null)
         {
             ScenarioChangedEvent(this, new ScenarioChangedEventArgs());
         }
     }
     else
     {
         base.AddChild(child);
     }
 }
 public void Visit(ModelComponent component)
 {
     Console.WriteLine("ModelComponentVisitor");
 }
        /// <summary>
        /// Add game entity to this cell
        /// </summary>
        /// <param name="entity">The Entity to add</param>
        public void AddEntity(ModelComponent entity)
        {
            if (entitiesContainedWithin.Count == 0)
            {
                if (entity is UnitComponent || entity is MapResource || entity is Building)
                {
                    entitiesContainedWithin.Add(entity);

                    if (entity is UnitComponent)
                    {
                        UnitArgs args = new UnitArgs();
                        args.Unit = (UnitComponent)entity;
                        args.Unit.UnitAttackedEnemyHanlders += new UnitAttackedEnemyHandler(handleUnitInCellAttackingEnemy);
                        if (UnitAddedEvent != null)
                        {
                            UnitAddedEvent(this, args);
                        }
                    }
                    if (entity is Building)
                    {
                        // do nothing special?
                    }
                }
            }
        }
        /// <summary>
        /// Checking if a specific entity is owned by a player
        /// </summary>
        /// <param name="entity"></param>
        /// <returns>True if that entity is owned by the player, false otherwise.</returns>
        private bool entityBelongsToPlayer(ModelComponent entity)
        {
            PlayerComponent player = (PlayerComponent)((XnaUITestGame)game).Model.GetScenario().GetGameWorld().GetPlayerList().GetChildren()[0];

            if (entity is UnitComponent)
            {
                return player.GetUnitList().GetChildren().Contains(entity);
            }
            else if (entity is Building)
            {
                return player.BuildingList.GetChildren().Contains(entity);
            }

            return false;
        }
 /// <summary>
 /// Creates and fires an UnitAttackedEnemyEvent
 /// </summary>
 /// <param name="target">The target the UnitComponent is attacking.</param>
 public void createAttackEvent(ModelComponent target)
 {
     if (UnitAttackedEnemyHanlders != null)
     {
         UnitAttackedEnemyHanlders(this, new UnitAttackedEnemyArgs(target));
     }
 }
コード例 #52
0
 /// <summary>
 /// Remove cell from the map
 /// </summary>
 /// <param name="child"></param>
 public override void RemoveChild(ModelComponent child)
 {
     if (GetChildren().Contains(child))
     {
         // This ensures that the child is a cell, and that it is actually contained in the map.
         CellComponent cell = (CellComponent)child;
         cells[cell.X, cell.Y] = null;
         base.RemoveChild(child);
     }
 }
 public override void AddChild(ModelComponent child)
 {
     if (child is BuildingAction)
         base.AddChild(child);
 }
コード例 #54
0
        /// <summary>
        /// Check if the building can be added to the map.  A building can only be added to the Map if there is enough space to
        /// place the building and there are no Entities on those spaces.
        /// </summary>
        /// <param name="component">The building to add</param>
        /// <returns>True if building can be added or the component is not the building, otherwise, false is returned!</returns>
        public bool canAddBuildingToMap(ModelComponent component)
        {
            if (component is Building)
            {
                Building tempBuild = (Building)component;
                if (GetCellAt((int)tempBuild.PointLocation.X, (int)tempBuild.PointLocation.Y).ContainsEntity())
                {
                    return false;
                }
                else
                {
                    return isEnoughSpace(tempBuild);
                }
            }

            return false;
        }
 public override void RemoveChild(ModelComponent child)
 {
     if (child != actionQueue)
         base.RemoveChild(child);
 }
コード例 #56
0
 public virtual void RemoveChild(ModelComponent child)
 {
     // No op - Map's only children are the cells.
 }
 /// <summary>
 /// Removes an Entity from this Cell.
 /// </summary>
 /// <param name="entity">The Entity to remove</param>
 public void RemoveEntity(ModelComponent entity)
 {
     entitiesContainedWithin.Remove(entity);
     if (entity is UnitComponent)
     {
         UnitArgs args = new UnitArgs();
         args.Unit = (UnitComponent)entity;
         args.Unit.UnitAttackedEnemyHanlders -= new UnitAttackedEnemyHandler(handleUnitInCellAttackingEnemy);
         if (UnitRemovedEvent != null)
             UnitRemovedEvent(this, args);
     }
 }
 public virtual void RemoveChild(ModelComponent child)
 {
     child.SetContainer(null);
 }
 public void SetContainer(ModelComponent composite)
 {
     if (container != null)
     {
         container.GetChildren().Remove(this);
     }
     container = composite;
 }
コード例 #60
0
 /// <summary>
 /// Remove building from the Map.
 /// </summary>
 /// <param name="component">The building to remove</param>
 /// <returns>True if successfully removed from the map</returns>
 public bool removeBuildingFromMap(ModelComponent component)
 {
     Building tempBuild = (Building)component;
     for (int i = (int)tempBuild.PointLocation.X; i < (int)tempBuild.PointLocation.X + tempBuild.Width; ++i)
     {
         for (int j = (int)tempBuild.PointLocation.Y; j < (int)tempBuild.PointLocation.Y + tempBuild.Height; ++j)
         {
             tempBuild.CellsContainedWithin.Remove(GetCellAt(i, j));
             GetCellAt(i, j).RemoveEntity(tempBuild);
         }
     }
     return true;
 }