Have mine!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| public class TileMap { private int width, height; private Tile[][] map; public TileMap(int width, int height) { this.width = width; this.height = height; initializeTiles(width, height); } private void initializeTiles(int width, int height) { map = new Tile[width][height]; for(int i = 0; i < width; i++) { for(int k = 0; k < height; k++) { map[i][k] = new Tile(); } } } public void setTile(Tile tile, int x, int y) { map[x][y] = tile; } public Tile getTile(int x, int y) { if (x < 0 || x >= width || y < 0 || y >= height) { return null; } return map[x][y]; } public int getWidth() { return width; } public int getHeight() { return height; } } |
The Tile class can be anything you'd want, and it's easy to get the Tile for altering, or you can make an entirely new Tile, in any cell.
I've always designed in a way where the Tile itself doesn't know it's position, but that's personal preference and a design choice.
You can render this fella easily, by simply looping through each cell.