private byte WAIT_TICKS = 5; // How many ticks to wait for another unit to move.

        #endregion Fields

        #region Constructors

        /// <summary>
        /// This constructor will create a MoveAction to the given targetX, and targetY.
        /// </summary>
        /// <param name="targetX">X coordinate destination of the move action in game space.</param>
        /// <param name="targetY">Y coordinate destination of the move action in game space.</param>
        public MoveAction(float targetX, float targetY, Map map, UnitComponent unit)
        {
            this.targetY = targetY;
            this.targetX = targetX;
            this.map = map;
            this.unit = unit;
        }
        public void TestUnitNotReactingToEnemyAddedOutsideRange()
        {
            setupModel();
            // Add a unit to each player.
            UnitList list = ((PlayerComponent)model.GetScenario().GetGameWorld().GetPlayerList().GetChildren()[0]).GetUnitList();
            UnitList list2 = ((PlayerComponent)model.GetScenario().GetGameWorld().GetPlayerList().GetChildren()[1]).GetUnitList();

            // Create a Unit for Player 1
            UnitComponent unit1 = new UnitComponent();
            list.AddChild(unit1);
            unit1.PointLocation = new PointF(0.5f, 0.5f);
            unit1.AttackStance = UnitComponent.UnitAttackStance.Aggressive;
            unit1.VisibilityRange = 4.0f;

            // Create a Unit for Player 2
            UnitComponent unit2 = new UnitComponent();
            list2.AddChild(unit2);
            unit2.PointLocation = new PointF(9.5f, 9.5f); // outisde unit1's visibility range (4.0f).

            bool output = false;
            // Check to see if unit1 noticed unit2 being added.
            if (unit1.GetActionQueue().GetChildren().Count > 0)
            {
                if (unit1.GetActionQueue().GetChildren()[0] is AttackAction)
                {
                    AttackAction action = (AttackAction)unit1.GetActionQueue().GetChildren()[0];

                    output = action.Target == unit2;
                }
            }

            Assert.IsFalse(output);
        }
        private int unitType; // Type frame

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="game">Game component</param>
        /// <param name="unit">Unit Model</param>
        /// <param name="sourceRect">Location of the image representing this unit on the spritesheet</param>
        public UnitUI(Game game, UnitComponent unit, Rectangle sourceRect)
            : base(game, sourceRect)
        {
            this.unit = unit;
            this.OnClick += getAttacked;

            unit.SelectHandler += new ModelComponentSelectedHandler(onSelectChanged);
            unit.UnitStateChangedHandlers += new UnitStateChangedHanlder(onUnitStateChanged);
            unit.UnitAttackedEnemyHanlders += new UnitAttackedEnemyHandler(onAttack);

            pixel = new Texture2D(game.GraphicsDevice, 1, 1, true, SurfaceFormat.Color);
            pixel.SetData(new[] { Color.White });

            if (unit.IsZombie)
            {
                unitType = GameConfig.ZOMBIE_START_Y;
            }
            else
            {
                if (unit.Type.Equals("soldier"))
                {
                    unitType = GameConfig.SOLDIER_START_Y;
                }
                else
                {
                    unitType = GameConfig.WORKER_START_Y;
                }
            }
        }
 /// <summary>
 /// Constructor for selected units
 /// </summary>
 /// <param name="game"></param>
 /// <param name="unit"></param>
 public SelectedEntityUI(Game game, UnitComponent unit)
     : base(game)
 {
     this.unit = unit;
     unit.HPChangedEventHandlers += UpdateHPBar;
     this.SizeChanged += onResize;
     this.OnClick += selectUnit;
 }
        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;
        }
        public UnitUI(MapEditorController controller, UnitComponent unit)
        {
            InitializeComponent();

            this.controller = controller;
            this.unit = unit;

            // Initialize Image
            if (unit != null)
            {
                // TODO: Register for move events.

                // Get Image
                BitmapManager manager = BitmapManager.Instance;
                this.Image = manager.getBitmap(unit.Type);
            }
        }
        public override void Visit(UnitComponent unit)
        {
            int desiredHeight = (int)Game.Font.MeasureString("anything").Y;
            int desiredWidth = Layout.DrawBox.Width / 2;

            TextBox textbox1 = new TextBox(Game, "HP:  ", "right");
            textbox1.DrawBox = new Rectangle(0, 0, desiredWidth, desiredHeight);
            Layout.AddChild(textbox1);
            TextBox textbox2 = new TextBox(Game, unit.CurrentHealth + " / " + unit.MaxHealth, "left");
            textbox2.DrawBox = new Rectangle(0, 0, desiredWidth, desiredHeight);
            Layout.AddChild(textbox2);

            TextBox textbox3 = new TextBox(Game, "Attack Damage:  ", "right");
            textbox3.DrawBox = new Rectangle(0, 0, desiredWidth, desiredHeight);
            Layout.AddChild(textbox3);
            TextBox textbox4 = new TextBox(Game, unit.Attack.ToString(), "left");
            textbox4.DrawBox = new Rectangle(0, 0, desiredWidth, desiredHeight);
            Layout.AddChild(textbox4);

            TextBox textbox5 = new TextBox(Game, "Attack Range:  ", "right");
            textbox5.DrawBox = new Rectangle(0, 0, desiredWidth, desiredHeight);
            Layout.AddChild(textbox5);
            TextBox textbox6 = new TextBox(Game, unit.AttackRange.ToString(), "left");
            textbox6.DrawBox = new Rectangle(0, 0, desiredWidth, desiredHeight);
            Layout.AddChild(textbox6);

            TextBox textbox7 = new TextBox(Game, "Attack Delay:  ", "right");
            textbox7.DrawBox = new Rectangle(0, 0, desiredWidth, desiredHeight);
            Layout.AddChild(textbox7);
            TextBox textbox8 = new TextBox(Game, unit.AttackTicks.ToString(), "left");
            textbox8.DrawBox = new Rectangle(0, 0, desiredWidth, desiredHeight);
            Layout.AddChild(textbox8);

            TextBox textbox9 = new TextBox(Game, "Attack Delay:  ", "right");
            textbox9.DrawBox = new Rectangle(0, 0, desiredWidth, desiredHeight);
            Layout.AddChild(textbox9);
            TextBox textbox10 = new TextBox(Game, unit.AttackTicks.ToString(), "left");
            textbox10.DrawBox = new Rectangle(0, 0, desiredWidth, desiredHeight);
            Layout.AddChild(textbox10);
        }
        public void TestUnitReactingToEnemyMovingWithinRange()
        {
            setupModel();
            // Add a unit to each player.
            UnitList list = ((PlayerComponent)model.GetScenario().GetGameWorld().GetPlayerList().GetChildren()[0]).GetUnitList();
            UnitList list2 = ((PlayerComponent)model.GetScenario().GetGameWorld().GetPlayerList().GetChildren()[1]).GetUnitList();

            // Create a Unit for Player 1
            UnitComponent unit1 = new UnitComponent();
            list.AddChild(unit1);
            unit1.PointLocation = new PointF(0.5f, 0.5f);
            unit1.AttackStance = UnitComponent.UnitAttackStance.Aggressive;
            unit1.VisibilityRange = 4.0f;

            // Create a Unit for Player 2
            UnitComponent unit2 = new UnitComponent();
            list2.AddChild(unit2);
            unit2.PointLocation = new PointF(9.5f, 9.5f); // outisde unit1's visibility range (4.0f).

            // Check to make sure that unit1 did not notice unit2 being added.
            bool output = false;
            if (unit1.GetActionQueue().GetChildren().Count > 0)
            {
                if (unit1.GetActionQueue().GetChildren()[0] is AttackAction)
                {
                    AttackAction action = (AttackAction)unit1.GetActionQueue().GetChildren()[0];

                    output = action.Target == unit2;
                }
            }
            Assert.IsFalse(output);

            // Have unit2 move into unit1's visibility range.
            MoveAction move = new MoveAction(2.0f, 2.0f, model.GetScenario().GetGameWorld().GetMap(), unit2);

            //Have unit2 move until the move action is completed.
            while (!move.Work()) { }

            // Test that unit1 has been given an AttackAction with unit2 as the target.
            output = false;
            if (unit1.GetActionQueue().GetChildren().Count > 0)
            {
                if (unit1.GetActionQueue().GetChildren()[0] is AttackAction)
                {
                    AttackAction action = (AttackAction)unit1.GetActionQueue().GetChildren()[0];

                    output = action.Target == unit2;
                }
            }
            Assert.IsTrue(output);
        }
        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;
        }
        /// <summary>
        /// This function will check if the NEXT Cell that the unit is currently moving onto is empty or not.
        /// </summary>
        /// <param name="unit">The Unit whose location we check</param>
        /// <returns>True if the next Cell in its path is vacant, false otherwise</returns>
        private bool isNextCellVacant(UnitComponent unit)
        {
            int curX = (int)unit.PointLocation.X;
            int curY = (int)unit.PointLocation.Y;
            int nextX = curX;
            int nextY = curY;

            if (path[0].Y < curY)
                nextY = curY - 1;
            else if (path[0].Y > curY)
                nextY = curY + 1;

            if (path[0].X < curX)
                nextX = curX - 1;
            else if (path[0].X > curX)
                nextX = curX + 1;

            // I'm not sure if this will ever be true, but if the next cell's coords come out to be the same as the unit's
            // current cell coords, evaluate to true;
            if (nextX == curX && nextY == curY)
                return true;

            // Check to make sure that the next cells coords exist within the map's boundaries.
            else if (map.GetCellAt(nextX, nextY) == null)
                return false;

            return map.GetCellAt(nextX, nextY).EntitiesContainedWithin.Count == 0;
        }
 /// <summary>
 /// Update building's construction progress
 /// </summary>
 /// <param name="building">building underconstruction</param>
 /// <param name="worker">Assigned worker for place the building</param>
 private void updateBuildingProgress(Building building, UnitComponent worker)
 {
     if (building.MaxHealth - building.CurrentHealth <= worker.BuildSpeed)
     {
         // Finish the building.
         building.CurrentHealth = building.MaxHealth;
         building.Completed = true;
     }
     else
     {
         // Continue building the building.
         building.CurrentHealth += ((UnitComponent)Parent.Parent).BuildSpeed;
     }
 }
        /// <summary>
        /// Select Entity UI (Icon represent the unit)
        /// </summary>
        /// <param name="unit"></param>
        /// <returns></returns>
        public SelectedEntityUI BuildSelectedEntityUI(UnitComponent unit)
        {
            SelectedEntityUI seui = new SelectedEntityUI(game, unit);
            seui.DrawBox = new Rectangle(0, 0, 75, 75);

            // Add the HP Bar to the UI.
            HPBar hpBar = new HPBar(game);
            hpBar.MaxHP = unit.MaxHealth;
            hpBar.CurrentHP = unit.CurrentHealth;
            hpBar.DrawBox = new Rectangle(5, 67, 65, 5);

            PictureBox pictureBox = BuildPictureBox("selectionAvatar",unit.Type);
            pictureBox.DrawBox = new Rectangle(7, 3, 61, 61);
            seui.AddChild(pictureBox);
            seui.AddChild(hpBar);
            return seui;
        }
        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);
        }
 public override void Visit(UnitComponent unit)
 {
     ZRTSCompositeViewUIFactory factory = ZRTSCompositeViewUIFactory.Instance;
     ui = factory.BuildSelectedEntityUI(unit);
 }
 public SimpleAttackUnitAction(UnitComponent unit, UnitComponent target)
 {
     this.unit = unit;
     this.target = target;
 }
 public void Visit(UnitComponent unit)
 {
     output.WriteStartElement("Unit");
     output.WriteAttributeString("Type", unit.Type);
     output.WriteAttributeString("CanAttack", unit.CanAttack.ToString());
     output.WriteAttributeString("Attack", unit.Attack.ToString());
     output.WriteAttributeString("AttackRange", unit.AttackRange.ToString());
     output.WriteAttributeString("AttackTicks", unit.AttackTicks.ToString());
     output.WriteAttributeString("BuildSpeed", unit.BuildSpeed.ToString());
     output.WriteAttributeString("CanBuild", unit.CanBuild.ToString());
     output.WriteAttributeString("CanHarvest", unit.CanHarvest.ToString());
     output.WriteAttributeString("CurrentHealth", unit.CurrentHealth.ToString());
     output.WriteAttributeString("MaxHealth", unit.MaxHealth.ToString());
     output.WriteAttributeString("X", unit.PointLocation.X.ToString());
     output.WriteAttributeString("Y", unit.PointLocation.Y.ToString());
     output.WriteAttributeString("Speed", unit.Speed.ToString());
     VisitChildren(unit);
     output.WriteEndElement();
 }
 public UnitAttackStanceChangedArgs(UnitComponent unit, UnitComponent.UnitAttackStance newAttackStance, UnitComponent.UnitAttackStance oldAttackStance)
 {
     this.unit = unit;
     this.newAttackStance = newAttackStance;
     this.oldAttackStance = oldAttackStance;
 }
        /// <summary>
        /// Variation of the takeStep method. The unit will move to the center of the targetCell. (x + 0.5f, y + 0.5f)
        /// </summary>
        /// <returns>true if at the end of the path, false otherwise.</returns>
        private bool takeStepMiddle(UnitComponent unit)
        {
            bool completed = false;

            // Check if we are at the center of the target Cell
            if (unit.PointLocation.X == path[0].X + CENTER && unit.PointLocation.Y == path[0].Y + CENTER)
            {
                // Remove the next Cell in the path.  If that was the last Cell, we're done
                path.RemoveAt(0);
                if (path.Count == 0)
                    completed = true;

            }

            // If we aren't at the center of the next Cell, and that Cell is vacant, move towards it
            else if (isNextCellVacant(unit))
            {
                if (waiting)
                {
                    waiting = false;
                    ticksWaiting = 0;
                }
                moveMiddle(unit);
            }

            // Otherwise, the next Cell in our path is not vacant; wait for a while or compute a new path
            else
            {
                waiting = true;
                ticksWaiting++;

                // We've been waiting long enough, compute a new path.
                if (ticksWaiting % WAIT_TICKS == 0)
                    path = FindPath.between(map, map.GetCellAt((int)unit.PointLocation.X, (int)unit.PointLocation.Y), map.GetCellAt((int)targetX, (int)targetY));
            }

            return completed;
        }
        /// <summary>
        /// Move the unit towards the center of targetCell.
        /// </summary>
        private void moveMiddle(UnitComponent unit)
        {
            float speed = (unit.Speed);

            if (path[0].Y + CENTER > unit.PointLocation.Y)
            {
                if (path[0].X + CENTER> unit.PointLocation.X)
                {
                    unit.UnitOrient = UnitComponent.Orient.SE;
                }
                else if (path[0].X + CENTER < unit.PointLocation.X)
                {
                    unit.UnitOrient = UnitComponent.Orient.SW;
                }
                else
                {
                    unit.UnitOrient = UnitComponent.Orient.S;
                }
            }
            else if (path[0].Y + CENTER < unit.PointLocation.Y)
            {
                if (path[0].X + CENTER> unit.PointLocation.X)
                {
                    unit.UnitOrient = UnitComponent.Orient.NE;
                }
                else if (path[0].X + CENTER< unit.PointLocation.X)
                {
                    unit.UnitOrient = UnitComponent.Orient.NW;
                }
                else
                {
                    unit.UnitOrient = UnitComponent.Orient.N;
                }
            }
            else if (path[0].X + CENTER< unit.PointLocation.X)
            {
                unit.UnitOrient = UnitComponent.Orient.W;
            }
            else if (path[0].X + CENTER> unit.PointLocation.X)
            {
                unit.UnitOrient = UnitComponent.Orient.E;
            }

            // If we are within the range of the destination point, simply move there
            if (Math.Sqrt(Math.Pow(path[0].Y + CENTER - unit.PointLocation.Y, 2) + Math.Pow(path[0].X + CENTER - unit.PointLocation.X, 2)) <= speed)
            {
                PointF directionVector = new PointF(path[0].X + CENTER - unit.PointLocation.X, path[0].Y + CENTER - unit.PointLocation.Y);
                // We are within |unit.speed| of the targetCell's center, set unit's position to center.
                unit.PointLocation = new PointF(path[0].X + CENTER, path[0].Y + CENTER);

            }
            else
            {
                PointF directionVector = new PointF(path[0].X + CENTER - unit.PointLocation.X, path[0].Y + CENTER - unit.PointLocation.Y);
                float magnitude = (float)Math.Sqrt(Math.Pow((double)directionVector.X, 2.0) + Math.Pow((double)directionVector.Y, 2.0));
                directionVector.X = directionVector.X / magnitude * unit.Speed;
                directionVector.Y = directionVector.Y / magnitude * unit.Speed;
                unit.PointLocation = new PointF(unit.PointLocation.X + directionVector.X, unit.PointLocation.Y + directionVector.Y);
            }
        }
 public override void Visit(UnitComponent unit)
 {
     this.pictureBox = ZRTSCompositeViewUIFactory.Instance.BuildPictureBox("bigAvatar", unit.Type);
 }
        public void TestUnitReactingToEnemyAddedWithinRange()
        {
            setupModel();
            // Add a unit to each player.
            UnitList list = ((PlayerComponent)model.GetScenario().GetGameWorld().GetPlayerList().GetChildren()[0]).GetUnitList();
            UnitList list2 = ((PlayerComponent)model.GetScenario().GetGameWorld().GetPlayerList().GetChildren()[1]).GetUnitList();

            // Create a unit for Player 1
            UnitComponent unit1 = new UnitComponent();
            list.AddChild(unit1);
            unit1.PointLocation = new PointF(0.5f, 0.5f);
            unit1.AttackStance = UnitComponent.UnitAttackStance.Aggressive;

            // Create a unit for Player 2
            UnitComponent unit2 = new UnitComponent();
            list2.AddChild(unit2);
            unit2.PointLocation = new PointF(1.5f, 1.5f);

            bool output = false;
            // Check to see if unit1 noticed unit2 being added next to it and correctly gave itself an attack action.
            if (unit1.GetActionQueue().GetChildren().Count > 0)
            {
                if (unit1.GetActionQueue().GetChildren()[0] is AttackAction)
                {
                    AttackAction action = (AttackAction)unit1.GetActionQueue().GetChildren()[0];

                    output =  action.Target == unit2;
                }
            }

            // unit1 should react to unit2 being added next to it.
            Assert.IsTrue(output);
        }
        public ScenarioComponent GenerateScenarioFromXML()
        {
            ScenarioComponent scenario = null;
            if (reader.Read())
            {
                // Go to the Scenario (skip the XML line)
                reader.Read();
                scenario = new ScenarioComponent();
                ModelComponent currentComponent = scenario;
                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                        case XmlNodeType.Element:
                            switch (reader.Name)
                            {
                                case "Gameworld":
                                    Gameworld gameworld = new Gameworld();
                                    currentComponent.AddChild(gameworld);
                                    if (!reader.IsEmptyElement)
                                        currentComponent = gameworld;
                                    break;
                                case "Map":
                                    int width = Int32.Parse(reader.GetAttribute("Width"));
                                    int height = Int32.Parse(reader.GetAttribute("Height"));
                                    Map map = new Map(width, height);
                                    currentComponent.AddChild(map);
                                    if (!reader.IsEmptyElement)
                                        currentComponent = map;
                                    break;
                                case "Cell":
                                    int x = Int32.Parse(reader.GetAttribute("X"));
                                    int y = Int32.Parse(reader.GetAttribute("Y"));
                                    CellComponent cell = new CellComponent();
                                    cell.X = x;
                                    cell.Y = y;
                                    currentComponent.AddChild(cell);
                                    if (!reader.IsEmptyElement)
                                        currentComponent = cell;
                                    break;
                                case "PlayerList":
                                    PlayerList playerList = new PlayerList();
                                    currentComponent.AddChild(playerList);
                                    if (!reader.IsEmptyElement)
                                        currentComponent = playerList;
                                    break;
                                case "Player":
                                    PlayerComponent player = new PlayerComponent();
                                    player.Name = reader.GetAttribute("Name");
                                    player.Race = reader.GetAttribute("Race");
                                    player.Gold = Int32.Parse(reader.GetAttribute("Gold"));
                                    player.Metal = Int32.Parse(reader.GetAttribute("Metal"));
                                    player.Wood = Int32.Parse(reader.GetAttribute("Wood"));
                                    currentComponent.AddChild(player);
                                    if (!reader.IsEmptyElement)
                                        currentComponent = player;
                                    break;
                                case "BuildingList":
                                    if (!reader.IsEmptyElement)
                                        currentComponent = ((PlayerComponent)currentComponent).BuildingList;
                                    break;
                                case "UnitList":
                                    if (!reader.IsEmptyElement)
                                        currentComponent = ((PlayerComponent)currentComponent).GetUnitList();
                                    break;
                                case "Sand":
                                    Sand sand = new Sand();
                                    currentComponent.AddChild(sand);
                                    if (!reader.IsEmptyElement)
                                        currentComponent = sand;
                                    break;
                                case "Mountain":
                                    Mountain mountain = new Mountain();
                                    currentComponent.AddChild(mountain);
                                    if (!reader.IsEmptyElement)
                                        currentComponent = mountain;
                                    break;
                                case "Grass":
                                    Grass grass = new Grass();
                                    currentComponent.AddChild(grass);
                                    if (!reader.IsEmptyElement)
                                        currentComponent = grass;
                                    break;
                                case "Unit":
                                    UnitComponent unit = new UnitComponent();
                                    currentComponent.AddChild(unit);
                                    float unitX = float.Parse(reader.GetAttribute("X"));
                                    float unitY = float.Parse(reader.GetAttribute("Y"));
                                    unit.PointLocation = new PointF(unitX, unitY);
                                    unit.Type = reader.GetAttribute("Type");
                                    unit.MaxHealth = short.Parse(reader.GetAttribute("MaxHealth"));
                                    unit.CurrentHealth = short.Parse(reader.GetAttribute("CurrentHealth"));
                                    unit.CanHarvest = bool.Parse(reader.GetAttribute("CanHarvest"));
                                    unit.CanAttack = bool.Parse(reader.GetAttribute("CanAttack"));
                                    unit.Attack = short.Parse(reader.GetAttribute("Attack"));
                                    unit.AttackRange = float.Parse(reader.GetAttribute("AttackRange"));
                                    unit.AttackTicks = byte.Parse(reader.GetAttribute("AttackTicks"));
                                    unit.CanBuild = bool.Parse(reader.GetAttribute("CanBuild"));
                                    unit.BuildSpeed = byte.Parse(reader.GetAttribute("BuildSpeed"));
                                    unit.Speed = float.Parse(reader.GetAttribute("Speed"));
                                    /*
                                     * Type="zombie" CanAttack="True"
                                     * Attack="20" AttackRange="4" AttackTicks="10"
                                     * BuildSpeed="30" CanBuild="True" CanHarvest="False"
                                     * CurrentHealth="100" MaxHealth="100" X="12" Y="13"
                                     * Speed="0.1"
                                     */
                                    if (!reader.IsEmptyElement)
                                        currentComponent = unit;
                                    break;
                                case "Building":
                                    Building building = new Building();
                                    currentComponent.AddChild(building);
                                    building.Width = Int32.Parse(reader.GetAttribute("Width"));
                                    building.Height = Int32.Parse(reader.GetAttribute("Height"));
                                    building.PointLocation = new PointF(float.Parse(reader.GetAttribute("X")), float.Parse(reader.GetAttribute("Y")));
                                    building.Type = reader.GetAttribute("Type");
                                    building.CanProduce = bool.Parse(reader.GetAttribute("CanProduce"));
                                    if (!reader.IsEmptyElement)
                                        currentComponent = building;
                                    break;
                                default:
                                    break;
                            }
                            break;
                        case XmlNodeType.EndElement:
                            if (currentComponent != null)
                                currentComponent = currentComponent.Parent;
                            break;
                    }

                }
                Console.WriteLine("XmlTextReader Properties Test");
                Console.WriteLine("===================");
                // Read this element's properties and display them on console
                Console.WriteLine("Name:" + reader.Name);
                Console.WriteLine("Base URI:" + reader.BaseURI);
                Console.WriteLine("Local Name:" + reader.LocalName);
                Console.WriteLine("Attribute Count:" + reader.AttributeCount.ToString());
                Console.WriteLine("Depth:" + reader.Depth.ToString());
                Console.WriteLine("Node Type:" + reader.NodeType.ToString());
                Console.WriteLine("Attribute Count:" + reader.Value.ToString());
            }
            return scenario;
        }
 public AddUnitCommand(UnitComponent unit, PlayerComponent player, CellComponent cell)
 {
     this.unit = unit;
     this.player = player;
     this.cell = cell;
 }
 public UnitOrientationChangedEventArgs(UnitComponent unit, UnitComponent.Orient oldOrientation, UnitComponent.Orient newOrientation)
 {
     this.unit = unit;
     this.oldOrientation = oldOrientation;
     this.newOrientation = newOrientation;
 }
 /// <summary>
 /// Give selected units an attack command
 /// </summary>
 /// <param name="unit">target unit</param>
 public void TellSelectedUnitsToAttack(UnitComponent unit)
 {
     List<ModelComponent> selectedEntities = getGameModel().GetSelectionState().SelectedEntities;
     bool canAttack = true;
     bool playerEntities = false;
     foreach (ModelComponent entity in selectedEntities)
     {
         if (entityBelongsToPlayer(entity))
         {
             playerEntities = true;
             if (!(entity is UnitComponent))
             {
                 canAttack = false;
                 break;
             }
             else
             {
                 UnitComponent u = entity as UnitComponent;
                 if (!u.CanAttack)
                 {
                     canAttack = false;
                     break;
                 }
             }
         }
     }
     if (canAttack && playerEntities)
     {
         foreach (UnitComponent u in selectedEntities)
         {
             u.GetActionQueue().GetChildren().Clear();
             u.GetActionQueue().AddChild(new AttackAction(u, unit, getGameModel().GetScenario().GetGameWorld()));
         }
     }
 }
        public void testUnitObstruction()
        {
            setUpModel();
            List<CellComponent> path;
            UnitComponent soldier = new UnitComponent();
            Map map = model.GetScenario().GetGameWorld().GetMap();
            map.GetCellAt(14, 14).AddEntity(soldier);

            path = Pathfinder.FindPath.between(map, map.GetCellAt(1, 1), map.GetCellAt(14, 14));
            Assert.IsNotEmpty(path);
            Assert.True(path[path.Count - 1].X >= 13 && path[path.Count - 1].X <= 15
                && path[path.Count - 1].Y >= 13 && path[path.Count - 1].Y <= 15);
            Assert.True(path[path.Count - 1].GetTile().Passable());
        }
        /// <summary>
        /// Construct a unit UI (image representation)
        /// </summary>
        /// <param name="unit"></param>
        /// <returns>Unit image</returns>
        public UnitUI BuildUnitUI(UnitComponent unit)
        {
            UnitUI unitUI = null;
            if (unit.Type.Equals("soldier"))
            {
                unitUI = new UnitUI(game, unit, new Rectangle(0, GameConfig.SOLDIER_START_Y, 36, 36));
                //unitUI = new UnitUI(game, unit, new Rectangle(2, 128, 16, 27));
                unitUI.DrawBox = new Rectangle(0, 0, GameConfig.UNIT_WIDTH, GameConfig.UNIT_HEIGHT);
            }

            else if (unit.Type.Equals("zombie"))
            {
                unit.IsZombie = true;
                unitUI = new UnitUI(game, unit, new Rectangle(0, GameConfig.ZOMBIE_START_Y, 36, 36));
                unitUI.DrawBox = new Rectangle(0, 0, GameConfig.UNIT_WIDTH, GameConfig.UNIT_HEIGHT);
                //unitUI.DrawBox = new Rectangle(20, 0, 32, 54);
            }

            else if (unit.Type.Equals("worker"))
            {
                unitUI = new UnitUI(game, unit, new Rectangle(0, GameConfig.WORKER_START_Y, 36, 36));
                unitUI.DrawBox = new Rectangle(0, 0, GameConfig.UNIT_WIDTH, GameConfig.UNIT_HEIGHT);
            }
            return unitUI;
        }
 public virtual void Visit(UnitComponent unit)
 {
     Visit((ModelComponent)unit);
 }
 public UnitStateChangedEventArgs(UnitComponent unit, UnitComponent.UnitState oldState, UnitComponent.UnitState newState)
 {
     this.unit = unit;
     this.oldState = oldState;
     this.newState = newState;
 }
 public void Visit(UnitComponent unit)
 {
     if (UnitVisitor != null)
         unit.Accept(UnitVisitor);
 }