I'm making a game in Java and I'm working on the tilemap system for the game. I have a method in the Map class that will create a tile at certain x,y coordinates and I have an abstract Tile class which is then extended in each specific tile (e.g class DirtTile extends Tile
).
The class Map
would look something like this:
public class Map {
int width,height;
Tile[][] map;
public Map(w,h) {
width=w;
height=h;
map = new Tile[w][h];
}
void set(T type) {
// type would be some subclass of Tile
this.map[i][j] = new type(x,y);
}
}
If need be, I can pass in a String or int to signify what the type of the tile should be, but I'd rather not get into an endless series of switch statements (and it would be hell to make changes to).