public static void DisplayGrid(IEnumerable maze, GameObject vertexPrefab) { foreach (GraphVertex gv in maze) { Vector2 gvPosition = gv.CoreCoordinates; GameObject objCore = GameObject.Instantiate(vertexPrefab, new Vector3(gvPosition.x, gvPosition.y, vertexPrefab.transform.position.z), Quaternion.identity); // Displays the teleport, if any, and stores the coordinates of the teleport-connected cell CellComponent cellViewer = objCore.GetComponent <CellComponent>(); if (gv.TeleportCell != null) { // Stores the teleport coordinates into the CellComponent of gv Vector3 teleportCellCoo = new Vector3(gv.TeleportCell.CoreCoordinates.x, gv.TeleportCell.CoreCoordinates.y, -2); cellViewer.TeleportOtherCell = teleportCellCoo; // Sets the color of the cell according to the teleporter objCore.GetComponent <SpriteRenderer> ().color = gv.TeleportColor; // Instantiates the teleporter cellViewer.AddTeleporter(); } // Displays the walls foreach (Wall w in gv.Walls) { cellViewer.DisplayWallWithPhysics(w); } } }
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; }
// If the character leaves the teleport, we set the currentTeleportCell as null void OnTriggerExit2D(Collider2D c) { if (c.gameObject.tag.Equals("teleporter")) { currentTeleportCell = null; } }
/// <summary> /// Initialize necessary components /// </summary> private void initialize() { game = new XnaUITestGame(); ZRTSController controller = new ZRTSController(game); game.Components.Add(controller); model = new GameModel(); ScenarioComponent scenario = new ScenarioComponent(50, 50); player1 = new PlayerComponent(); player2 = new PlayerComponent(); player1.Name = "Nate"; player2.Name = "Smith"; // Add sand 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; map.AddChild(cell); } } model.AddChild(scenario); game.Model = model; game.Model.PlayerInContext = player1; // Set a main Player //Create two players and set them to be enemies. game.Model.GetScenario().GetGameWorld().GetPlayerList().AddChild(player1); game.Model.GetScenario().GetGameWorld().GetPlayerList().AddChild(player2); // Set target enemy player1.EnemyList.Add(player2); player2.EnemyList.Add(player1); game.Controller = controller; // Add worker to player unitList = new List <ModelComponent>(); unitList.Add(new UnitComponent()); ((UnitComponent)unitList[0]).CanBuild = true; ((UnitComponent)unitList[0]).Type = "worker"; ((UnitComponent)unitList[0]).PointLocation = new PointF(20, 20); //(1) Get Player#1 currentPlayer1 = (PlayerComponent)((XnaUITestGame)game).Model.GetScenario().GetGameWorld().GetPlayerList().GetChildren()[0]; // check if fetch the correct player Assert.AreEqual("Nate", currentPlayer1.Name); // (2) Add the actual player's unit list currentPlayer1.GetUnitList().AddChild(unitList[0]); }
// COLLISION HANDLERS // If the character is on a teleport, we store this teleport in case the mouse gets on the character void OnTriggerEnter2D(Collider2D c) { if (c.gameObject.tag.Equals("teleporter")) { currentTeleportCell = c.gameObject.GetComponentInParent <CellComponent> (); } }
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 GameModel)) { temp = temp.Parent; } GameModel model = (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); }
private void setupModel() { model = new GameModel(); ScenarioComponent scenario = new ScenarioComponent(20, 20); // 20 x 20 Gameworld. // 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; map.AddChild(cell); } } model.AddChild(scenario); //Create two players and set them to be enemies. model.GetScenario().GetGameWorld().GetPlayerList().AddChild(new PlayerComponent()); model.GetScenario().GetGameWorld().GetPlayerList().AddChild(new PlayerComponent()); PlayerComponent player1 = (PlayerComponent)model.GetScenario().GetGameWorld().GetPlayerList().GetChildren()[0]; PlayerComponent player2 = (PlayerComponent)model.GetScenario().GetGameWorld().GetPlayerList().GetChildren()[1]; player1.EnemyList.Add(player2); player2.EnemyList.Add(player1); }
private CellComponent findClosestCell(PointF point) { double distanceSquared = Math.Pow(map.GetWidth(), 2.0) + Math.Pow(map.GetHeight(), 2.0); CellComponent cell = null; for (int i = Math.Max((int)building.PointLocation.X - 1, 0); i <= building.PointLocation.X + building.Width + 1; i++) { for (int j = Math.Max((int)building.PointLocation.Y - 1, 0); j <= building.PointLocation.Y + building.Height + 1; j++) { // Ignore cases in the middle of the proposed building site. if (!(i >= (int)building.PointLocation.X && i < (int)building.PointLocation.X + building.Width && j >= (int)building.PointLocation.Y && j < (int)building.PointLocation.Y + building.Height)) { double calculatedDistanceSquared = findDistanceSquared(point.X, point.Y, i, j); if (calculatedDistanceSquared <= distanceSquared) { if (map.GetCellAt(i, j) != null) { cell = map.GetCellAt(i, j); distanceSquared = calculatedDistanceSquared; } } } } } return(cell); }
public void Handle(CellComponent cell) { try { cell.Dispatcher.Invoke(() => { cell.Background = Settings.Instance.Immune; }); } catch { } }
private void SetWallAll(ref DynamicBuffer <EntityBufferElement> cellsBuffer, bool isWall) { for (int i = 0; i < cellsBuffer.Length; i++) { Entity entity = cellsBuffer[i].Entity; CellComponent cellComp = ActiveEntityManager.GetComponentData <CellComponent>(entity); cellComp.IsWall = isWall; PostUpdateCommands.SetComponent(entity, cellComp); } }
public void UnregisterFromEvents() { cell.TileChangedEvent -= this.ChangeTile; cell.UnitAddedEvent -= this.UnitAddedToCell; cell.UnitRemovedEvent -= this.UnitRemovedFromCell; AllowDrop = false; cell = null; // Keep the image from disposing. this.Image = null; }
internal void updateCellType(int x, int y) { TileFactory tf = TileFactory.Instance; //Cell selectedCell = model.scenario.getGameWorld().map.getCell(x, y); //selectedCell.tile = tf.getTile(model.TileTypeSelected); //model.notifyAll(); CellComponent cell = improvedModel.GetScenario().GetGameWorld().GetMap().GetCellAt(x, y); // Cell automatically removes old tile from overrided AddChild. cell.AddChild(tf.GetImprovedTile(improvedModel.TileTypeSelected)); // TODO: Change to new improvedModel here. }
private void SetWall(ref DynamicBuffer <EntityBufferElement> cellsBuffer, int sizeInCellX, int2 pos, bool isWall) { int index = (sizeInCellX * pos.y) + pos.x; Debug.AssertFormat(index >= 0 && index < cellsBuffer.Length, "Index {0} is not within buffer length {1}", index, cellsBuffer.Length); Entity entity = cellsBuffer[index].Entity; CellComponent cellComp = ActiveEntityManager.GetComponentData <CellComponent>(entity); cellComp.IsWall = isWall; PostUpdateCommands.SetComponent(entity, cellComp); }
internal void OnDragMapCell(CellComponent cell) { if (model.GetSelectionState().SelectionType == typeof(ZRTSModel.Tile)) { TileFactory tf = TileFactory.Instance; ZRTSModel.Tile tile = tf.GetImprovedTile(model.GetSelectionState().SelectedTileType); ChangeCellTileCommand command = new ChangeCellTileCommand(cell, tile); if (command.CanBeDone()) { model.GetCommandStack().ExecuteCommand(command); } } }
/// <summary> /// This function will perform a building cycle if the number of ticks since the last cycle is equal to TICKS_PER_CYCLE. /// </summary> /// <returns>true if the building is complete and the action is finished, false otherwise.</returns> public override bool Work() { if (!building.Completed) { if (curTicks % TICKS_PER_CYCLE == 0) { // Check if unit is adjacent to building. if (isUnitNextToBuilding()) { // Add the building to the model if we have not done so yet. if (building.Parent == null) { // TODO: Ensure that the spaces are cleared. Perhaps wait/give up, as with move? PlayerComponent player = Parent.Parent.Parent.Parent as PlayerComponent; player.BuildingList.AddChild(building); for (int i = (int)building.PointLocation.X; i < building.PointLocation.X + building.Width; i++) { for (int j = (int)building.PointLocation.Y; j < building.PointLocation.Y + building.Height; j++) { building.CellsContainedWithin.Add(map.GetCellAt(i, j)); map.GetCellAt(i, j).AddEntity(building); } } } if (building.MaxHealth - building.CurrentHealth <= ((UnitComponent)Parent.Parent).BuildSpeed) { // Finish the building. building.CurrentHealth = building.MaxHealth; building.Completed = true; } else { // Continue building the building. building.CurrentHealth += ((UnitComponent)Parent.Parent).BuildSpeed; } } else { // Move towards the building. Insert a move action into the Unit's action queue. CellComponent targetCell = findClosestCell(((UnitComponent)Parent.Parent).PointLocation); MoveAction moveAction = new MoveAction(targetCell.X, targetCell.Y, map); Parent.AddChildAt(moveAction, 0); } } } curTicks++; return(building.Completed); }
// set an object with a specific value at cell away from player position private void UpdateMap_ObjectPosition(int horizontalShift, int verticalShift, string objectFound, float levelCertainty) { int horizontalPosition = this.playerCol + horizontalShift; int verticalPosition = this.playerRow - verticalShift; // Update the map to fit the new size if the position is outside from previous one UpdateMap_Size(horizontalPosition, verticalPosition); CellComponent cell = elementMap[this.playerRow - verticalShift, this.playerCol + horizontalShift]; if (cell.GetIsChangeable()) { cell.ModifyElement(objectFound, levelCertainty); } }
/* * helper functions */ /// <summary> /// Prints the path to console. /// </summary> /// <param name="path">The path to print</param> private static void printPath(List <CellComponent> path, float distance) { CellComponent end = path[path.Count - 1]; // bool intended = (intendedEnd == path[path.Count - 1]); // Console.WriteLine("-> {0} from ({1}, {2}) to ({3}, {4}) found", intended ? "Path" : "Nearest path", path[0].X, path[0].Y, intendedEnd.Xcoord, intendedEnd.Ycoord); Console.Write("-> Path: "); for (int i = 0; i < path.Count - 1; i++) { Console.Write(String.Format("({0}, {1}), ", path[i].X, path[i].Y)); } Console.WriteLine(String.Format("({0}, {1})", end.X, end.Y)); Console.WriteLine(" Waypoints: {0}", path.Count); Console.WriteLine(" Cell Distance: {0}", distance / 10); Console.WriteLine(" Time to Find: {0}", span); }
// Add a new row to the map. If n is positive, then we add to the bottom, otherwise to the top; private void AddMapRow(int n) { CellComponent[,] tempMap = new CellComponent[this.row + Mathf.Abs(n), col]; int tempRow = tempMap.GetUpperBound(0) + 1; int tempCol = tempMap.GetUpperBound(1) + 1; if (n < 0) { for (int i = 0; i < tempRow; i++) { for (int j = 0; j < tempCol; j++) { if (i < -n) { tempMap[i, j] = new CellComponent(); } else { tempMap[i, j] = this.elementMap[i + n, j]; } } } // update the player's coordinate this.playerRow -= n; } else { for (int i = 0; i < tempRow; i++) { for (int j = 0; j < tempCol; j++) { if (i < this.row) { tempMap[i, j] = this.elementMap[i, j]; } else { tempMap[i, j] = new CellComponent(); } } } } this.elementMap = tempMap; this.row += Mathf.Abs(n); }
// Add a new column to the map. If n is positive, then we add to the right, otherwise to the left; private void AddMapColunm(int n) { CellComponent[,] tempMap = new CellComponent[this.row, this.col + Mathf.Abs(n)]; int tempRow = tempMap.GetUpperBound(0) + 1; int tempCol = tempMap.GetUpperBound(1) + 1; if (n < 0) { for (int i = 0; i < tempRow; i++) { for (int j = 0; j < tempCol; j++) { if (j < -n) { tempMap[i, j] = new CellComponent(); } else { tempMap[i, j] = this.elementMap[i, j + n]; } } } // update the player's coordinate this.playerCol -= n; } else { for (int i = 0; i < tempRow; i++) { for (int j = 0; j < tempCol; j++) { if (j >= this.col) { tempMap[i, j] = new CellComponent(); } else { tempMap[i, j] = this.elementMap[i, j]; } } } } this.elementMap = tempMap; this.col += Mathf.Abs(n); }
public void GenerateField() { for (int row = 0; row < Row_count; row++) { for (int column = 0; column < Col_count; column++) { Cells[row, column] = new CellComponent(); var cell = Cells[row, column]; cell.SetColor(DefaultColor); cell.SetEmpty(true); cell.SetCellSize(CellSize); cell.SetPosInField(new Point { Y = row, X = column }); //cell.SetPositionABS(); } } }
/// <summary> /// Creates a CreateNewScenario dialog and uses it to determine the name and size of the new scenario. Then, generates a /// new scenario of the appropriate size. /// </summary> public void createNewScenario() { if (model.GetScenario() != null) { model.GetScenario().RemoveChild(model.GetScenario().GetGameWorld()); // TODO: Ask if the user wants to discard the current scenario or save it. } CreateNewScenarioDialog dialog = new CreateNewScenarioDialog(); dialog.ShowDialog(); if (dialog.ExitWithCreate) { // Create a scenario with a map of the appropriate size ScenarioComponent scenario = new ScenarioComponent(dialog.ScenarioWidth, dialog.ScenarioHeight); // 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 Grass()); cell.X = i; cell.Y = j; map.AddChild(cell); } } // TODO: Update SaveInfo model to change filename and UpToDate flag. // Automatically discards old scenario, by overloaded AddChild function. model.AddChild(scenario); // Empty the command queue model.GetCommandStack().EmptyStacks(); // We may have just destroyed a large scenario, so collect that garbage. // Commented out - only used for testing purposes. The C# garbage collector takes a LONG time to be activated if this call is not made, // but if the call is made, it disrupts UI. // GC.Collect(); } }
/// <summary> /// Determines from the selection state if we are placing a resource, building, unit, or tile, and then places it based on /// the selection state. /// </summary> /// <param name="x"></param> /// <param name="y"></param> internal void OnClickMapCell(int x, int y) { if (model.GetSelectionState().SelectionType == typeof(ZRTSModel.Tile)) { TileFactory tf = TileFactory.Instance; CellComponent cell = model.GetScenario().GetGameWorld().GetMap().GetCellAt(x, y); ZRTSModel.Tile tile = tf.GetImprovedTile(model.GetSelectionState().SelectedTileType); ChangeCellTileCommand command = new ChangeCellTileCommand(cell, tile); if (command.CanBeDone()) { model.GetCommandStack().ExecuteCommand(command); } } else if (model.GetSelectionState().SelectionType == typeof(UnitComponent)) { // Get instance of Unit Factory, produce unit, and place on map for the given player. } }
protected override void OnUpdate() { entityQuery = GetEntityQuery(ComponentType.ReadOnly <CellComponent>()); NativeArray <CellComponent> cellSpriteDataArray = entityQuery.ToComponentDataArray <CellComponent>(Allocator.TempJob); MaterialPropertyBlock materialPropertyBlock = new MaterialPropertyBlock(); Vector4[] uv = new Vector4[1]; Camera mainC = Camera.main; Material SpriteSheetMat = CreateTileMap.GetInstance().SpriteSheetMat; Mesh mesh = CreateTileMap.GetInstance().quadMesh; int shaderPropertyId = Shader.PropertyToID("_MainTex_UV"); //Account for limitations of DrawMeshInstanced int sliceCount = 1023; for (int i = 0; i < cellSpriteDataArray.Length; i += sliceCount) { int sliceSize = math.min(cellSpriteDataArray.Length - i, sliceCount); List <Matrix4x4> matrixList = new List <Matrix4x4>(); List <Vector4> uvList = new List <Vector4>(); for (int j = 0; j < sliceSize; j++) { CellComponent cellComponentData = cellSpriteDataArray[i + j]; matrixList.Add(cellComponentData.matrix); uvList.Add(cellComponentData.uv); } materialPropertyBlock.SetVectorArray(shaderPropertyId, uvList); Graphics.DrawMeshInstanced( mesh, 0, SpriteSheetMat, matrixList, materialPropertyBlock); } cellSpriteDataArray.Dispose(); }
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); } } }
internal void OnClickMapCell(CellComponent cellComponent, float xPercent, float yPercent) { if (model.GetSelectionState().SelectionType == typeof(ZRTSModel.Tile)) { TileFactory tf = TileFactory.Instance; ZRTSModel.Tile tile = tf.GetImprovedTile(model.GetSelectionState().SelectedTileType); ChangeCellTileCommand command = new ChangeCellTileCommand(cellComponent, tile); if (command.CanBeDone()) { model.GetCommandStack().ExecuteCommand(command); } } else if (model.GetSelectionState().SelectionType == typeof(UnitComponent)) { UnitFactory uf = UnitFactory.Instance; UnitComponent unit = uf.Create(model.GetSelectionState().SelectedUnitType); //unit.PointLocation = new PointF((float)cellComponent.X + xPercent, (float)cellComponent.Y + yPercent); PlayerComponent player = model.GetScenario().GetGameWorld().GetPlayerList().GetPlayerByName(model.GetSelectionState().SelectedPlayer); AddUnitCommand command = new AddUnitCommand(unit, player, cellComponent); if (command.CanBeDone()) { model.GetCommandStack().ExecuteCommand(command); } } else if (model.GetSelectionState().SelectionType == typeof(Building)) { BuildingFactory bf = BuildingFactory.Instance; Building building = bf.Build(model.GetSelectionState().SelectedBuildingType, true); //building.PointLocation = new PointF((float)cellComponent.X + xPercent, (float)cellComponent.Y + yPercent); PlayerComponent player = model.GetScenario().GetGameWorld().GetPlayerList().GetPlayerByName(model.GetSelectionState().SelectedPlayer); AddBuildingCommand command = new AddBuildingCommand(building, player, cellComponent); if (command.CanBeDone()) { model.GetCommandStack().ExecuteCommand(command); } } }
/* * public functions */ /// <summary> /// The core function; calls all valid auxiliary functions and returns the path (advanced features can be toggled) /// Includes a boolean toggle for use of advanced pathfinding functions /// </summary> /// <param name="map">The Map</param> /// <param name="start">The starting Cell</param> /// <param name="end">The ending Cell</param> /// <param name="advanced"> A boolean toggle for advanced functions</param> /// <returns>The path as a list of waypoints</returns> public static List <CellComponent> between(Map map, CellComponent start, CellComponent end, bool advanced) { // begin timing the operation DateTime startTime = DateTime.Now; // convert the given Cell-based data to Node-based data NodeMap nodeMap = new NodeMap(map); Node nodeStart = nodeMap.getNode(start.X, start.Y); Node nodeEnd = nodeMap.getNode(end.X, end.Y); // perform advanced pre-calculation tasks if (advanced) { // if the end Node is invalid, replace it with the nearest valid Node if (!nodeEnd.isValid) { nodeEnd = Advanced.nearestValidEnd(nodeMap, nodeStart, nodeEnd); } } // find the path List <Node> nodePath = Basic.findPath(nodeMap, nodeStart, nodeEnd); // convert the path from List<Node> format back to List<Cell> format List <CellComponent> path = new List <CellComponent>(nodePath.Count); for (int i = 0; i < nodePath.Count; i++) { path.Add(map.GetCellAt(nodePath[i].X, nodePath[i].Y)); } // grab and print path data float dist = (float)(nodePath[nodePath.Count - 1].Gscore); span = DateTime.Now - startTime; //printPath(path, dist); return(path); }
private void TryPuttingBlock(List <Cell> availableCells) { CellComponent cellComponent = GetCellUnderBlock(); Cell closestCell = availableCells[0]; foreach (Cell c in availableCells) { if (c.CellComponent == cellComponent) { closestCell = c; break; } } GameField.GetInstance().PutBlockAt(_block, closestCell); availableCells.ForEach(x => x.CellComponent.SetActive(false)); if (GameField.GetInstance().CheckWinCondition()) { UIManager.GetInstance().ShowWinMenu(); } }
private Vector3 InstCell(Transform parent, Cell cell) { Transform cellTrans = Instantiate( prefabsDictionary[Paths.Prefabs.CELL]).transform; cellTrans.SetParent(parent); CellComponent cellComp = cellTrans.GetComponent <CellComponent>(); Vector3 cellPos = cellTrans.position; cellPos.x = cell.Column * CELL_SIZE; cellPos.z = cell.Row * CELL_SIZE * -1; cell.x = cellPos.x; cell.z = cellPos.z; cellTrans.position = cellPos; cellComp.SetPassages(cell); return(cellPos); }
// Initialize the 2D array map, and set the player at the center position private void CreateMap(int row, int col) { if (elementMap == null) { elementMap = new CellComponent[row, col]; this.row = elementMap.GetUpperBound(0) + 1; this.col = elementMap.GetUpperBound(1) + 1; for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { elementMap[i, j] = new CellComponent(); } } elementMap[row / 2, col / 2].SetIsPlayer(true); this.playerRow = row / 2; this.playerCol = col / 2; } }
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); }