Hey guys. I am trying to make a 4x4 (16 room) cave for a mock rpg I am making. What would be the best way to work out the travel mechanism. I am surely going to make every room its own class. I could do it by making a whole bunch of if else statments (if selection.equals("north") run room A3 etc.) I was just wondering if there is a better way to go about doing this. Thanks
No. Don't make every room into a new class. This is not going to scale. Instead, you should think about a way to describe a room in some data format, and then use the description when you create a new instance of the Room class.
Part of this description could be which other room a room passes into in a certain direction. You can make an enum Direction which contains constants like NORTH, EAST, etc. The Room class could have a method that takes a Direction and returns an adjacent Room.
Joined: Dec 15, 2011
thanks stephan. this was great advice and set me in the right direction