The following blog post, unless otherwise noted, was written by a member of Gamasutra’s community.
The thoughts and opinions expressed are those of the writer and not Gamasutra or its parent company.
So this has been an interesting week. The good news is that my software still works more or less the way I want it to work. The bad news is it took a lot of coding to maintain the status quo. Basically, the way I wrote my code was that the entire bank of networked computers would only have to cope with one centipede at one time. This was in the spec (multiple centipedes was an option for a higher score, but I wanted to get my baseline in early) so I figured it would be easiest to get a simple solution in and build on it later. However, I encountered a bug in my code when a centipede would leave the screen, hit an object on the next screen over, and return to the original screen before it's tail had fully moved off. The problem being that they both use the same object to controll the positions of the tail piece. Practical upshot was that two centipedes tried to exist within the space of one and instead just dissapeared all together.
So, I had to rewrite my code to deal with a linked list of centipedes rather than just one. Honestly this is the way I should have done it to begin with. It doesn't take a genius to figure out that this kind of problem was gonna occur. It's not a massive issue either because when doing so I figured out a way I could listen for new centipedes and handle existing centipedes exiting the game space at the same time, where before it was an either/or deal. Either I had a centipede on my screen and I was waiting for it to leave OR I had no centipede and was waiting for one to arrive. The next task will be to implement a class (probably a pair of daemon threads) that can do both.
Ah yeah, threads. So locking is fun! Seriously, I'm learning much more about how to program in Java now than I did during my Java lecture module. It's kind of a live fire excersie. A lot of problems with my code randomly throwing hissy fits was fixed when I figured out the correct way to use locking in my classes. Even now there's probably better ways to go about doing it, but I've cleared up my main problems.
Deadlines are looming! 22nd of March is when this has to be complete by. I've come a long way but there's still a lot to get done.