Hello, I have written a map generator for a game and I read in some book that inheritance should be right way to get away from the switch statement. So I write something like this:
Then I have map:Code:class Tile {...}; /* Abstract base class */
class X: public Tile {...};
class Y: public Tile {...};
So when I draw it on the screen I do something like that:Code:Tile* map[W][H];
Looks like good runaway from switch statement, but when I generate that map I do it iterative way: first i set every tile to ocean, then randomly generate island, on island I place mountains, near mountains I place forests and so forth.Code:for (i=0;...) for (j=0;...) map[i][j]->draw();
So I generate another array of integer numbers, generate map on it and convert them to Tile descendants. And it is made with huge switch statement. Can you point me some way to escape this last switch? Can OOP and inheritance be useful here?
English is not my first language. Sorry for mistakes.