Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Proper class structure

 
brent carter
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whenever I make a game I always run into the same problem. I create a hero object, but after doing a few things with it I run into scope problems. For example: I will create a dungeon class to make dungeons. I am not sure how my hero object should interact with this class that makes dungeons. Do I have to pass my hero object as an argument to the dungeon class? Do I forgo a dungeon class and just create a dungeon method on the same scope as where I created my hero object?

What is the best way to structure a simple game that has a hero that traverses through a dungeon?

Thanks.
 
Saif Asif
Ranch Hand
Posts: 440
Eclipse IDE Hibernate Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about making an interface like "traversable" with a method ( lets call it traverse) and write the implementation code for how to traverse a dungeon. You can pass the Hero object to this method , although I would favor the use of abstraction and pass an object of Entity ( Hero extends Entity ) and then write the implementation code of how the hero ( Hero instaceOf Entity ) would traverse the dungeon right there.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic