JayZee's Maze: Technical stuff

The game isn't particularly complicated to build. The only part of it that required some innovative thinking was the construction of the maze. It is semi-random, with one unique way out. This is how I do it:

I start with an array whose size is given by two of the applet parameters, "mw" for maze width and "mh" for maze height, plus an extra column on each side.

<param name="mw" value="10">
<param name="mh" value="6">

Then I randomly pick one of a set of applet parameters named "path*", where "*" is a number starting from 1. For example

<param name="path1" value="3ruurrdddrrdrruulluururrddrr">

The initial digit is how far down to start in the leftmost column. The following characters indicate the solution path ("r" for right, "u" for up, etc.). The program follows that path, knocking out walls as it goes along. (Since the first step will always have to be to the right, it's not even mentioned in the parameter string.)

Next, it's time to add dead ends. For as long as there are still some array elements with all four walls closed, the program picks one of them at random and proceeds from it along a random path, until it reaches an already open element.

If you think about it for a while, you realize that these new paths will never connect in such a way that a shortcut is formed between two parts of the true solution.

When there are no more closed-off elements, the program adds some decorative obstacles (rocks, bushes, etc.) to random elements belonging to dead ends.

Then it loops through the array and draws the corresponding graphical structure in an offscreen image buffer. (Shown here is a slightly different random result.)