/// <summary>
 /// Constructor for selected building
 /// </summary>
 /// <param name="game"></param>
 /// <param name="building"></param>
 public SelectedEntityUI(Game game, Building building)
     : base(game)
 {
     this.building = building;
     this.SizeChanged += onResize;
     this.OnClick += selectBuilding;
 }
        public BuildingUI(MapEditorController controller, Building building)
        {
            InitializeComponent();

            this.controller = controller;
            this.building = building;

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

                // Get Image
                BitmapManager manager = BitmapManager.Instance;
                this.Image = manager.getBitmap(building.Type);
            }
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="game">game object</param>
        /// <param name="building">Building model</param>
        /// <param name="sourceRect">Location on the spritesheet</param>
        public BuildingUI(Game game, Building building, Rectangle sourceRect)
            : base(game, sourceRect)
        {
            this.building = building;
            //this.OnClick += getAttacked;
            pixel = new Texture2D(game.GraphicsDevice, 1, 1, true, SurfaceFormat.Color);
            pixel.SetData(new[] { Color.White });
            this.building.SelectHandler += new ZRTSModel.EventHandlers.ModelComponentSelectedHandler(onSelectChanged);

            if (building.Type.Equals("barracks"))
            {
                this.SourceRect = new Rectangle(GameConfig.BUILDING_CONSTRUCTION, GameConfig.BUILDING_START_Y, 216, 216);
            }
            else if (building.Type.Equals("hospital"))
            {
                this.SourceRect = new Rectangle(GameConfig.BUILDING_CONSTRUCTION, GameConfig.HOSPITAL_START_Y, 216, 216);
            }
            else if (building.Type.Equals("house"))
            {
                this.SourceRect = new Rectangle(GameConfig.BUILDING_CONSTRUCTION, GameConfig.HOUSE_START_Y, 216, 216);
            }
        }
        internal BuildingUI BuildBuildingUI(Building building)
        {
            BuildingUI buildingUI = null;
            buildingUI = new BuildingUI(game, building, new Rectangle(0, 0, 1, 1));
            buildingUI.DrawBox = new Rectangle(0, 0, building.Width * GameConfig.TILE_DIM, building.Height * GameConfig.TILE_DIM);

            return buildingUI;
        }
        /// <summary>
        /// Create User Interface (icon) for each selected entity (Building
        /// </summary>
        /// <param name="building"></param>
        /// <returns></returns>
        public SelectedEntityUI BuildSelectedEntityUI(Building building)
        {
            SelectedEntityUI seui = new SelectedEntityUI(game, building);
            seui.DrawBox = new Rectangle(0, 0, 75, 75);

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

            PictureBox pictureBox = BuildPictureBox("selectionAvatar", building.Type);
            pictureBox.DrawBox = new Rectangle(7, 3, 61, 61);
            seui.AddChild(pictureBox);
            seui.AddChild(hpBar);
            return seui;
        }
 /// <summary>
 /// Tell selected units to attack building
 /// </summary>
 /// <param name="building"></param>
 internal void TellSelectedUnitsToAttack(Building building)
 {
     // TODO: Implement
 }
 public override void Visit(Building building)
 {
     ZRTSCompositeViewUIFactory factory = ZRTSCompositeViewUIFactory.Instance;
     ui = factory.BuildSelectedEntityUI(building);
 }
        /// <summary>
        /// Checking if there is enough space to place a building.
        /// </summary>
        /// <param name="tempBuild">target building</param>
        /// <returns>True if there is enough space. False otherwise.</returns>
        private bool isEnoughSpace(Building tempBuild)
        {
            // check surrounding cells
            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)
                {
                    if (GetCellAt(i, j).ContainsEntity())
                    {
                        return false;
                    }
                }
            }

            return true;
        }
 public AddBuildingCommand(Building building, PlayerComponent player, CellComponent cell)
 {
     this.building = building;
     this.player = player;
     this.cell = cell;
 }
 public virtual void Visit(Building building)
 {
     Visit((ModelComponent)building);
 }
        private void setUpModel()
        {
            model = new GameModel();
            ScenarioComponent scenario = new ScenarioComponent(20, 20); // 20 x 20 Gameworld.
            Building obstruction = new Building();

            // Add grass cells at each cell.
            ZRTSModel.Map map = scenario.GetGameWorld().GetMap();
            for (int i = 0; i < map.GetWidth(); i++)
            {
                for (int j = 0; j < map.GetHeight(); j++)
                {
                    CellComponent cell = new CellComponent();
                    cell.AddChild(new Sand());
                    cell.X = i;
                    cell.Y = j;

                    if (i >= 2 && i <= 10 && j >= 2 && j <= 10)
                        cell.AddEntity(obstruction);

                    if (i >= 15 && i <= 18 && j >= 15 && j <= 18)
                        cell.AddEntity(obstruction);
                    if (i == 16 && j == 16)
                        cell.RemoveEntity(obstruction);

                    map.AddChild(cell);

                }
            }
            model.AddChild(scenario);
        }
        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 void Visit(Building building)
 {
     output.WriteStartElement("Building");
     output.WriteAttributeString("Type", building.Type);
     output.WriteAttributeString("CurrentHealth", building.CurrentHealth.ToString());
     output.WriteAttributeString("MaxHealth", building.MaxHealth.ToString());
     output.WriteAttributeString("X", building.PointLocation.X.ToString());
     output.WriteAttributeString("Y", building.PointLocation.Y.ToString());
     output.WriteAttributeString("CanProduce", building.CanProduce.ToString());
     output.WriteAttributeString("Completed", building.Completed.ToString());
     output.WriteAttributeString("DropOffResources", building.DropOffResources.ToString());
     output.WriteAttributeString("FoodCost", building.FoodCost.ToString());
     output.WriteAttributeString("Height", building.Height.ToString());
     output.WriteAttributeString("Width", building.Width.ToString());
     output.WriteAttributeString("LumberCost", building.LumberCost.ToString());
     output.WriteAttributeString("MetalCost", building.MetalCost.ToString());
     output.WriteAttributeString("WaterCost", building.WaterCost.ToString());
     foreach (string s in building.ProductionTypes)
     {
         output.WriteAttributeString("ProductionType", s);
     }
     VisitChildren(building);
     output.WriteEndElement();
 }
 public override void Visit(Building building)
 {
     this.pictureBox = ZRTSCompositeViewUIFactory.Instance.BuildPictureBox("bigAvatar", building.Type);
 }