private void loadMap() { //Reset the grid. levelGrid.Children.Clear(); levelGrid.ColumnDefinitions.Clear(); levelGrid.RowDefinitions.Clear(); tiles.Clear(); //Create the grid columns. for (int i = 0; i < levelModel.ColumnLenght; i++) { ColumnDefinition GridColumn = new ColumnDefinition(); GridColumn.Width = new GridLength(levelModel.CellSize); levelGrid.ColumnDefinitions.Add(GridColumn); } for (int i = 0; i < levelModel.RowLenght; i++) { RowDefinition gridRow = new RowDefinition(); gridRow.Height = new GridLength(levelModel.CellSize); levelGrid.RowDefinitions.Add(gridRow); } List<List<String>> map = levelModel.StringList; for (int y = 0; y < levelModel.RowLenght; y++) { List<Tile> row = new List<Tile>(); for (int x = 0; x < levelModel.ColumnLenght; x++) { Tile newTile = new Tile(); switch (map[y][x]) { case "#": newTile = new Wall(); break; case "x": newTile = new Target(); break; case "o": newTile = new Box(); break; case "@": newTile = new Forklift(); break; default: newTile = new Floor(); break; } newTile.SetValue(Grid.ColumnProperty, x); newTile.SetValue(Grid.RowProperty, y); row.Add(newTile); levelGrid.Children.Add(newTile); } tiles.Add(row); } }