This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
My friend and I have started a project together that will be evaluated in our final exams in early May. We've decided to create a simple Space-Invaders-inspired little game.
We've done a bit of coding (and I should inform you now that we're not allowed to use any special programs or functions in our code; only what is supplied by a certain Java file given to the class, containing simple scanners and basic maths functions, among other tools).
Now the main issue we've been facing was the inability to move our ship while shooting; we knew this was probably because we didn't put in a "while" loop anywhere in the code which meant that the game would only process one sub-program at a time. So basically if the shooting sub-program was running then the moving sub-program would be muted. We found a rather 'makeshift' solution to the problem by increasing the speed of the projectile so that the player wouldn't be bothered by waiting for the projectile to disappear. However our aim is to have this fixed but we simply don't know what to do!
We also want to eventually get the enemy aliens (on top) to move; with the program we have now, we'd have to mute absolutely everything else while the enemy aliens moved around. Is there any way we could resolve this?
The standard way to make multiple things (appear to) happen simultaneously in your program is to make your program multithreaded and have each action performed by a separate thread.
It might be possible to simulate this in a single thread by having a class for each action that maintains the state of the action and then have a loop that calls each class in turn to perform a short piece of each action, but i think this would be more complex than using threads.