Sign in to follow this  

Need help organizing code... its a complete mess.

Recommended Posts

alphster    122
I was hoping someone might know a good book or resource for me to study up on that'll teach me how to better organize my game code. I've been working on Pacman and it feels like the code is all over the place. I've resorted to using Global variables everywhere and i'm not sure if i've created the most optimal classes.

Anyone know a good book? Generally, the examples in most of these XNA books are simple games and they put all the logic into the Game1.cs file. I'm looking for a better structure than that...

Share this post

Link to post
Share on other sites
Dawoodoz    461
Learning pure functional programming is a good way to learn how to divide a giant routine with side effects into many small well defined functions that are thread safe and can be tested out of context.

Share this post

Link to post
Share on other sites
rip-off    10976
Forcing yourself to remove global variables will be part of it. Applying the Single Responsibility Principle will help too. Reducing dependencies is another powerful tool. Inverting the dependencies or introducing some kind of pure abstract "mapping" layer (often in the form of callbacks, or delegates).

Personally, this is something I learned by writing bigger and bigger programs, to the point where I couldn't maintain my older style so I was forced to abandon globals and really start separating things out into smaller units. Even then, it wasn't until I was working where I learned the value of unit testing, and totally minimising the dependencies so everything can be tested in isolation.

That is my excuse for not having many good resources to point you to. However, here are some excellent articles on programming design principles:
[*][url=""]Single Responsibility[/url]
[*][url=""]Open Closed[/url]
[*][url=""]Liskov Substitution[/url]
[*][url=""]Interface Segregation[/url]
[*][url=""]Dependancy Inversion[/url]

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this