Question about oop

Hello everyone, I’m new to Java and need a little help. Most of the programming I have done has been in QBasic and C, so OOP is a whole new beast for me. I’m going to make a simple little text adventure just to get the basics of the language down but I’m not really sure how to split it up into seperate objects. These are the seperate objects I’ve though of so far :

rooms (store the info for the rooms)
items (all the info for the items)
commands (go, get, look etc.)
monsters (stuff that bleeds)
npcs (people who want you to find lost puppys)

Am I going in the right direction or am I thinking of this all wrong? Anyone have any suggestions to get me started off right? Thanks!

-gunder

Yes, as a rule of thumb, you organise objects by behaviour. Then when you come to code, you implement the behaviour by writing methods for the objects.

If you haven’t looked at it already, check out the tutorial at http://java.sun.com/docs/books/tutorial/index.html

And don’t forget important objects like “thePlayer (the guy that’s doing everything)” :wink:

Make sure you write a class for every object.

IE:
Door, DoorFrame, DoorHandle, DoorPaint, DoorSticker, DoorLight, DoorRoom, etc… :lol:

Maybe not but you get the point. :wink:

Don’t forget to use packages…

Door
door.Frame
door.Handle
door.Paint
door.Sticker …

:wink:

Kev

Although this may seem obvious, take half an hour (or more) to sit down and draw ON paper, your basic design. Drawing things on paper does wonders when it comes to identifying potential problems before you sit down and code.

Don’t forget about abstraction. Break down your classes into subclasses.

Start with a monster class that contains variables and methods common to all monsters. Then create more specific monster subclasses that can extend the functionalility of the more abstract monster class.

So you start with a monster class, then create specific classes like Rock Monster, Demon Monster, Vampire monster and so on.

Later on if you decide to add another monster to the game. All you need to do is create a new class for that monster extending the original monster class and not destroying any functionality

This process can be used with all the classes you create.

TMP72