LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-02-2006, 07:58 PM   #1
linuxmandrake
Member
 
Registered: Sep 2004
Distribution: debian sarge 64bit (AMD)
Posts: 709

Rep: Reputation: 30
OO advice


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!
 
Old 04-03-2006, 01:21 PM   #2
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
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.
 
Old 04-03-2006, 01:27 PM   #3
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
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..

edit> oops didnt see graeme's post

Last edited by xhi; 04-03-2006 at 01:28 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
too much advice- need more. howlleo Linux - Software 11 11-17-2005 07:48 PM
What To Do...Need Advice ryld Linux - Certification 9 10-28-2005 02:29 AM
I need advice alrave Linux - Software 4 07-04-2005 06:17 PM
New PC advice Alan Lakin Linux - Hardware 3 05-30-2005 01:58 PM
some advice please gnu noob Linux - Software 7 03-26-2003 05:44 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration