private void initGrid() { int width = levelGrid.ColumnDefinitions.Count(); int height = levelGrid.RowDefinitions.Count(); for (int y = 0; y < height; y++) { List<Tile> row = new List<Tile>(); for (int x = 0; x < width; x++) { if (x == 0 || y == 0 || x == width - 1 || y == height - 1) { Wall wall = new Wall(); wall.SetValue(Grid.ColumnProperty, x); wall.SetValue(Grid.RowProperty, y); row.Add(wall); levelGrid.Children.Add(wall); } else { Floor floor = new Floor(); floor.SetValue(Grid.ColumnProperty, x); floor.SetValue(Grid.RowProperty, y); row.Add(floor); levelGrid.Children.Add(floor); } } tiles.Add(row); } }
private void verticalPlus_Click(object sender, RoutedEventArgs e) { if (levelGrid.RowDefinitions.Count() >= maxGridHeight) { return; } //Add a new row to the grid. RowDefinition gridRow = new RowDefinition(); gridRow.Height = new GridLength(levelModel.CellSize); levelGrid.RowDefinitions.Add(gridRow); //Get the new total width and height. int width = levelGrid.ColumnDefinitions.Count(); int height = levelGrid.RowDefinitions.Count(); //Move the wall row one down in both the tiles array and grid. foreach (Tile tile in tiles[height - 2]) { tile.SetValue(Grid.RowProperty, height - 1); } tiles.Add(tiles[height-2]); //Create a new row that will be inserted in the old wall row. List<Tile> row = new List<Tile>(); for (int i = 0; i < width; i++) { //Walls left and right. The rest is floor. if (i == 0 || i == width - 1) { Wall wall = new Wall(); wall.SetValue(Grid.ColumnProperty, i); wall.SetValue(Grid.RowProperty, height-2); row.Add(wall); levelGrid.Children.Add(wall); } else { Floor floor = new Floor(); floor.SetValue(Grid.ColumnProperty, i); floor.SetValue(Grid.RowProperty, height-2); row.Add(floor); levelGrid.Children.Add(floor); } } tiles[height - 2] = row; }
private void horizontalPlus_Click(object sender, RoutedEventArgs e) { if (levelGrid.ColumnDefinitions.Count() >= maxGridWidth) { return; } //Add a new column to the grid. ColumnDefinition GridColumn = new ColumnDefinition(); GridColumn.Width = new GridLength(levelModel.CellSize); levelGrid.ColumnDefinitions.Add(GridColumn); //Get the new total width and height. int width = levelGrid.ColumnDefinitions.Count(); int height = levelGrid.RowDefinitions.Count(); foreach(List<Tile> row in tiles) { row.Add(row[width-2]); row[width - 1].SetValue(Grid.ColumnProperty, width - 1); } //Add new tiles to the new column. for (int i = 0; i < height; i++) { //Walls up and down. The rest is floor. if (i == 0 || i == height - 1) { Wall wall = new Wall(); wall.SetValue(Grid.ColumnProperty, width - 2); wall.SetValue(Grid.RowProperty, i); tiles[i][width-2] = wall; levelGrid.Children.Add(wall); } else { Floor floor = new Floor(); floor.SetValue(Grid.ColumnProperty, width -2); floor.SetValue(Grid.RowProperty, i); tiles[i][width - 2] = floor; levelGrid.Children.Add(floor); } } }