/// <summary>
        /// Changes the target cell to include the new target tile.
        /// </summary>
        public void Do()
        {
            if (CanBeDone())
            {
                previousTile = targetCell.GetTile();

                // Cell.AddChild is overriden to ensure that only one tile exists.  This action
                // removes the previous tile and replaces it with the new one.
                targetCell.AddChild(targetTile);
            }
        }
コード例 #2
0
        public TileUI(MapEditorController controller, CellComponent observable)
        {
            InitializeComponent();
            this.controller = controller;
            this.cell       = observable;

            // Initialize Image
            if (observable != null)
            {
                // Register for TileChange event.
                observable.TileChangedEvent += this.ChangeTile;
                observable.UnitAddedEvent   += this.UnitAddedToCell;
                observable.UnitRemovedEvent += this.UnitRemovedFromCell;

                TileFactory tf = TileFactory.Instance;
                this.Image = tf.getBitmapImproved(observable.GetTile());

                foreach (ModelComponent m in observable.EntitiesContainedWithin)
                {
                    if (m is UnitComponent)
                    {
                        UnitUI unitUI = new UnitUI(controller, m as UnitComponent);
                        Controls.Add(unitUI);
                        unitUI.MouseClick += TileUI_MouseDown;
                    }
                }
            }



            AllowDrop = true;
        }
コード例 #3
0
        protected override void onDraw(XnaDrawArgs e)
        {
            // Determine all of the cells in view
            ZRTSModel.Map map            = ((XnaUITestGame)Game).Model.GetScenario().GetGameWorld().GetMap();
            Point         upperLeftCell  = new Point(ScrollX / CellDimension, ScrollY / CellDimension);
            Point         lowerRightCell = new Point(Math.Min((ScrollX + DrawBox.Width) / CellDimension, map.GetWidth() - 1), Math.Min((ScrollY + DrawBox.Height) / CellDimension, map.GetHeight() - 1));
            Point         offset         = new Point(ScrollX % CellDimension, ScrollY % CellDimension);

            // Draw all of the tiles
            for (int x = upperLeftCell.X; x <= lowerRightCell.X; x++)
            {
                for (int y = upperLeftCell.Y; y <= lowerRightCell.Y; y++)
                {
                    CellComponent   cell   = map.GetCellAt(x, y);
                    Tile            tile   = cell.GetTile();
                    DrawTileVisitor drawer = new DrawTileVisitor(e.SpriteBatch, ((XnaUITestGame)Game).SpriteSheet, new Rectangle((x - upperLeftCell.X) * CellDimension - offset.X, (y - upperLeftCell.Y) * CellDimension - offset.Y, CellDimension, CellDimension));
                    tile.Accept(drawer);
                }
            }
        }
コード例 #4
0
        private CellComponent findEmptyNeighborCell(GameModel model)
        {
            CellComponent insertCell = null;
            int           width      = model.GetScenario().GetGameWorld().GetMap().GetWidth();
            int           height     = model.GetScenario().GetGameWorld().GetMap().GetWidth();

            foreach (CellComponent cell in building.CellsContainedWithin)
            {
                int x = cell.X;
                int y = cell.Y;

                if (x < width - 1)
                {
                    CellComponent c = model.GetScenario().GetGameWorld().GetMap().GetCellAt(x + 1, y);
                    if (c.GetTile().Passable() && c.EntitiesContainedWithin.Count == 0)
                    {
                        insertCell = c;
                        break;
                    }

                    if (y < height - 1)
                    {
                        c = model.GetScenario().GetGameWorld().GetMap().GetCellAt(x + 1, y + 1);
                        if (c.GetTile().Passable() && c.EntitiesContainedWithin.Count == 0)
                        {
                            insertCell = c;
                            break;
                        }
                    }

                    if (y > 0)
                    {
                        c = model.GetScenario().GetGameWorld().GetMap().GetCellAt(x + 1, y);
                        if (c.GetTile().Passable() && c.EntitiesContainedWithin.Count == 0)
                        {
                            insertCell = c;
                            break;
                        }
                    }
                }

                if (x > 0)
                {
                    CellComponent c = model.GetScenario().GetGameWorld().GetMap().GetCellAt(x - 1, y);
                    if (c.GetTile().Passable() && c.EntitiesContainedWithin.Count == 0)
                    {
                        insertCell = c;
                        break;
                    }

                    if (y < height - 1)
                    {
                        c = model.GetScenario().GetGameWorld().GetMap().GetCellAt(x - 1, y + 1);
                        if (c.GetTile().Passable() && c.EntitiesContainedWithin.Count == 0)
                        {
                            insertCell = c;
                            break;
                        }
                    }

                    if (y > 0)
                    {
                        c = model.GetScenario().GetGameWorld().GetMap().GetCellAt(x - 1, y);
                        if (c.GetTile().Passable() && c.EntitiesContainedWithin.Count == 0)
                        {
                            insertCell = c;
                            break;
                        }
                    }
                }
            }

            return(insertCell);
        }