Class organization for my RPG game

Posted 11 January 2014 - 07:44 PM

Hello everyone.
I am making a RPG game, but today I have realized that my code is a mess, so I decided to create a new project, plan it correctly and then add the code I already have.
My question is about inheritance, I am thinking about the class organization, a diagram, here I have an image:

The idea is that:
- Game is a base class, the parent of all of them, will manage the system variables, game render and update
- The State class manages the game states, the menus are its children
- The are also some classes that inherits from Game.

Now my question is, based on my image and ideas, is this approach correct? I mean, is it logical what I am doing?
Thanks

Replies To: Class organization for my RPG game

Re: Class organization for my RPG game

Posted 11 January 2014 - 07:57 PM

that's not quite how I would have it.. I mean there's no good reason to have the 'game class' be the parent of a the player.. Personally I would have a 'generic game object' class that the player, item, npc all inherit from.. you know. .something to hold an ID, location, name, type, etc.

Re: Class organization for my RPG game

Posted 11 January 2014 - 08:18 PM

Yeah, I also thought about that, the Player really has nothing to do with the Game class.
I like the idea about the Game Object class, should it be the parent of all the possible objects in my game? I mean, the Player, NPC, Item and all that stuff?

Re: Class organization for my RPG game

I don't really care for the uber base game class. Rather than even think in classes, think in interfaces.

You have Item, given. What basic properties should an Item have? I'd think "usable" would be one of those, btw. How does the Item get interacted with?

If you have an NPC class, then it's probable that Player can be an extension of that. Or that NPC contains an object like Mob and so does Player.

I like to have a "Game State" object. This State object will essentially hold everything that you'd load or save in your game. The State object is passed to other objects that interact with it. If you have the concept of Player, then a Player instance will be in State.

Indeed, isUsable might also take State, if an item is only usable by a given player type, etc.

The idea behind any OO design is to make the objects know only as much about the rest of the program as they have to. Sometimes you see every object in a game storing a reference to state! Instead, every object should react to a state given to it, so it needn't be locked to some global mess.

Re: Class organization for my RPG game

Well, I made it like that because the "Game" class also loads some fonts so they can be used in derived classes...

GUI and inheritance... shudder.

The objects that make up your game should be data objects. That is, they store information about the game being played. Mixing that with display will cause confusion, pain, suffering, and dead kittens.

If GUI controls need to share fonts and other resources, either pass them from the main GUI object or setup a singleton with shared resources.