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; }
private CellComponent findEmptyNeighborCell(ZRTSModel.GameModel.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); }