Jump to content
  • Advertisement
Sign in to follow this  
ryandebraal

[java] Spagetti Code

This topic is 4259 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

omg! so much code, how am I supposed to package things in different classes, when the things in the subroutine refer to variables needed by other sections?? I see this "package" declaration at the beginingg of some java files, how does this work? Please, how can I just use variable in one file, in another, instead of having this frickin enourmous hunk of code as an example, Input - what a perfect thing to put in a seperate 'module' - but of course when I query if((keyState & FIRE_PRESSED) != 0) <--------------------- { spriteEnemySelect.setFrame(1); <----------- selectionMode = "CONFIRM"; } it refers to variables needed by the sprites - am I just a crappy programmer?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by ryandebraal
I see this "package" declaration at the beginingg of some java files, how does this work?


Quote:
Java In A Nutshell
A package is a named collection of classes (and possibly subpackages). Packages serve to group related classes and define a namespace for the classes they contain.[...]
Every class has both a simple name, which is the name given to it in its definition, and a fully qualified name, which includes the name of the package of which it is a part. The String class, for example, is part of the java.lang package, so its fully qualified name is java.lang.String.

Quote:

Please, how can I just use variable in one file, in another, instead of having this frickin enourmous hunk of code

Check out Object Oriented Programming In Java (Chapter 3 of "Java In A Nutshell", 2001, O'Reilly & Associates).

Designing modular code can be a difficult task, so don't worry if your first try to separate functionality into packages (modules), interfaces or class hierarchies fails. Modern IDEs such a Eclipse support refactoring pretty well, e.g. you can just select "extract method" or other refactorings and have the IDE do most of the work for you.

The first step to cope with increasing complexity, however, is to review your design. From just four lines of code, nobody is able to provide a suitable solution for you, I presume.

HTH,
Pat.

Share this post


Link to post
Share on other sites
first I was mad, cause you didnt hand me a snippet now I realize your right, I just need to review my design, I can have seperate getKeystates, for every seperate section of my game

thanks!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!