Autocrazy: Technical stuff

The preparations are done in the init method. All the animation -- moving cars and explosions -- is timed and handled by the main thread (i.e. the run method). The rest is operated by way of events, like mouse clicks, key presses and button selections.

There are five different "states" of the game. The first four correspond to the buttons down below and the associated screens. 0 = introduction, 1 = help screen, 2 = settings and 3 = playing. The fifth is reserved for the completion of a game -- when the target car rolls out and the player is shown the congratulations screen.

The actual animation is carried out by having the run method call repaint after every completed cycle. If a flag variable is set to true, then a specified image is drawn at its given co-ordinates by the update method. A special case is the "Moves: XX" text, which has its own flag. There is also one for re-drawing the whole applet graphics area, which is done, for example, when going from one game state to another (involving a change of most of the screen).

All throughout, the applet has a set of choice lists at the top of the screen and four buttons at the bottom, but they are only activated (and thus visible) on the screens where they are needed.

Autocrazy has a double set of image buffers the size of the applet area, offImage and farImage. The former maintains an up-to-date copy of the contents of the screen and can be used to restore it, for example, when the browser window needs to be redrawn. All things that are supposed to remain on the screen for more than a moment (unlike explosions) get copied to offImage. The latter image buffer, farImage, contains a copy of what the screen looked like before mobile or changing objects (like cars and bomb symbols) were drawn onto it. When a car is to be moved or a bomb symbol deleted, the applet needs to be able to restore the underlying background, and that data can be fetched from farImage.