(Individual Tile Classes vs Method Stacking) and Storing Tile Data

Good day folks,

Individual Tile Classes vs Method Stacking

So I am currently deciding on what route is best to take before I start adding lots more tiles to my game. Would it be best to use individual tile classes (GrassTile.java, MudTile.java, WaterTile.java) or have all tile decelerations made within the Tile.java class?

E.g. Individual Tile Class:


public class GrassTile extends Tile {

	private static final long serialVersionUID = 1L;

	public GrassTile(int type, int x, int y) {
		super(type, x, y);

		// Used to set the texture
		setOffset(0, 0);

		// Sets the name for use in-game
		setName("Grass");
	}

	public void tick() {
		super.tick();
	}

	public void render(Graphics g) {
		super.render(g);
	}

	@Override
	public void onDestroyTile(Level level, int x, int y) {
		// Grass tile becomes Mud tile when destroyed
		level.setTile(x, y, new MudTile(Tile.mud, x * Globals.tileSize, y * Globals.tileSize));
	}

	@Override
	public ItemDrop[] onDestroy(Level level, int x, int y) {
		// When destroyed we drop grass as an item
		return new ItemDrop[] { new ItemDrop(new GrassItem(Item.grass, x, y), 1) };
	}

}

How I would imagine stacked methods would look:


public static Tile grass = new Tile("Grass").setOffset(0, 0).onDestroy(Tile.mud).dropsItem(Item.grass);

What method would you use and what would you change (if anything)?

Storing Tile Data

So for my next question, how would one store tile data? Currently I have a “setMetadata” and “getMetadata” which basically allows you to assign a number to each tile. Is this the best way of storing individual data about a tile? It’s not very friendly in terms of readability since a boolean in metadata would have to be 0 and 1.

Cheers!