Structure of a game in Java
Members - Reputation: 106
Posted 14 June 2012 - 05:16 PM
Having just finished my first semester of programming with Java at Uni, I decided to try and program a MUD-style text-based RPG to further increase my skills over the summer. My only goal is to (hopefully) learn much more about Java programming and game design, so I'll leave out the internet aspect and develop it as a single-player conceptual game.
I've been doing some brainstorming and have been reading up about game development the past days, and so far I figured out how to create the game world using map objects and exit objects to connect them, and how to split up my entities into sub-classes with inheritence. The part that I'm stuck with is the structure and hierarchy of the program, like where to implement the game logic, for example battles with an enemy. First I thought I would add all the relevant methods of battle to the character class, and to add a variable of character class as a reference to an opponent with whom the character is currently battling. This idea didn't work quite well, and it made my code very messy too. Now I'm thinking I should probably isolate all the battle mechanics in a seperate class, but I'm having problems figuring out how to do this.
Another thing I am unsure about is how to define all my entities such as enemies, items and spells. Do I create an enumeration for all of them, and write down the details for each item seperately? Or should I use databases to store all the information?
Just to be clear, I'm not asking for any code or a step by step walkthrough. It's just that this whole "thinking in Java" thing is new to me, so I'm not sure how to tackle these problems yet, and we haven't had any classes about design patterns or strategies yet either. The topics I've dealt with are: The basics, exceptions, associations, inheritence, interfaces and the Liskov-substitution principle.
Members - Reputation: 892
Posted 15 June 2012 - 12:20 AM
Initialize Components -> Load resources -> Update -> Draw -> Update -> Draw and so on...
I think this will help you to structure your game in a more organized manner and many questions should be answered.
Concerning your Item and Enemy class problem. You can have a simple Enemy class which could be made serializable.
For Example you could create a typical Orc Enemy which can be saved as an XML file to your local drive. You can read the data from it and create new Objects from it.
Follow my hobby projects:
Ognarion Commander (Java/LIBGDX): https://github.com/OlafVanSchlacht/ognarion-commander