Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to go about making a mock dungeon

 
brent carter
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Stephan van Hulst
Bartender
Pie
Posts: 5893
63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
brent carter
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks stephan. this was great advice and set me in the right direction
 
Stephan van Hulst
Bartender
Pie
Posts: 5893
63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm glad it helped. Let me know how the project turns out.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic