Tuesday, September 21, 2010

I got Worms, but do I GET Worms?

Much better than my previous score of -100...I think.
The Worms game is a little fun while a little annoying.  Likewise, the code for the game is also a little fun while a little annoying.  The gameplay is pretty original, and the logic behind the workings of the worm itself is pretty clever.  However, the code itself is full of issues.

The first major problem that I noticed is the utter lack of cohesion in the WormChase class.  The UI, the game logic, the metrics, and just about everything (other than the worm and the obstacles) is all crammed together into one poorly planned class.  Admittedly, I violate the single responsibility principle myself from time to time.  We probably all do.  But for a program that is intended to serve as a clear example, this one leaves a bit to be desired.

The only complaint I have about the Worm class is the way it handles the directions of movement, the Point2D instantiations, and the probabilities for changing direction.  As I already explained in a message board post, every part that I just mentioned could be encapsulated into an enumeration, which would help greatly to simplify the code.

The Obstacles class, in my humble opinion, is well done.  Everything is synchronized to make it safe for use between the game thread and the event dispatch thread, it encapsulates its functionality neatly, and completely fulfills its well-defined purpose.

I do feel a little disappointed by the FPS/UPS example.  I was hoping for a nice, clean, easy-to-read implementation of UPS, but instead we have an unstructured, poorly documented tangle of variables thrown loosely about this monolithic WormChase class.  I've seen plenty of clearer examples of FPS calculations than the one presented here, so I suppose I shouldn't be surprised by the complexity and confusion in this particular UPS example.  Nevertheless, I am going to try to extract the essentials and implement them into my own code to get the experience of doing so.  If I succeed, I'll post some code snippets in a future blog entry.

No comments:

Post a Comment