my dog learned polymorphism
The moose likes Game Development and the fly likes Proper class structure Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Game Development
Bookmark "Proper class structure" Watch "Proper class structure" New topic

Proper class structure

brent carter
Ranch Hand

Joined: Dec 15, 2011
Posts: 34
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?

Saif Asif
Ranch Hand

Joined: Aug 11, 2011
Posts: 440

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.

Muhammad Saif Asif Mirza
I agree. Here's the link:
subject: Proper class structure
It's not a secret anymore!