ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Basically am developing a game and am not too sure about my structure. I developing this using java and swing. I was wondering would it be better to have my main class do just the gui stuff. For example the event handling and building the menu etc. Then have a game engine to do all the instantiating, timer collision detection etc. Right now I have my main class do the gui as well as some input validation and some instantiating. It caused my main class to be 12pages long!
The good thing about OO is that you can use it to break a program down into bight sized morsels. The problem is how to do this?
My initial suggestion would be to have a class that controls the GUI another class that manages the game engine, and have you main instantiate instances of those two objects. This means that you main is now just a couple of lines and the twelve pages of intricate code gets split (appropriately) into GUI or game engine code.
Next look at the GUI and split the code further, have a menu manager, a window manager, a dialog manager, each splitting off and hopefully simplifying the code.
Repeat for the game engine although you may need to be more carful with you division of labour here because of the interactions within the engine but it should be possible to extract out a timer class, a class for each of the objects and then a management class that avoids collisions etc.
That should give you code that is easier to understand, if you have a particular area that is, shall we say, a little complex then that to could be scope for breaking down into different classes.
well for the sake of easy browsing, it would be beneficial to break up the code into smaller chunks..
a concept of OO is that pieces be as small as possible, and specialized. in that a method does what it says it does, does it well, and thats it.. the smaller the methods the less binding your design will be.. when they grow and do more and more, then you have problems estending your design as well as a harder time debugging..
i would a design in which you make a threaded drawing panel that you use with a class that manages the objects on the screen..
one could write a book on this.. well actually people have.. i would suggest a good book on game design that i started on a while back but never got to finish.. Oreilly book, 'Killer Java Game Programming' (or somthing to that effect).. if i remember correctly that guys designs were pretty decent..
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.