Virtual Maze Generator for TADS 3

Chapter 3: Initializing the TADS 3 Component

Step 1: Creating a room

In your program, you need to create a room that will "contain" the virtual maze. Here's an example (from the "Maze Example.t" file in the "TADS 3 Component" installation folder):

AnyRoom: Room 'Maze Crawl'
    "\bUse the commands 'mwest', 'meast', 'mnorth', and 'msouth' to crawl through
    the maze.\b
    \b
    Use the command 'mvisited' to see a map that includes only those areas of the maze
    you have already explored (which may or may not include the maze's exit).\b
    \b    
    Use the command 'mreveal' to see a map of the entire maze, including your current
    position and the location of the maze's exit.\b
    \b
    Now, find the exit!\b\b"   
;

+ myMaze: Maze
    /* mazeGrid = new Vector( */

    randomStartFinish = nil
; 

The room's description (in double quotes from "\bUse the commands..." to "Now, find the exit\b\b!") provides a nice "help" facilty to inform the player about the maze's special commands. However, you can modify this description as you wish.

"+ myMaze: Maze" creates a "Maze" object and associates it with the room. The name of the object in this example is "myMaze", but you can use any name. The object's name is very important; you must use it when you modify the special verbs for the "Maze" class. (See below.)

We will discuss the "mazeGrid" property in the next section (Step 2: Initializing the "mazeGrid" Property).

"randomStartFinish = nil" By default, the "Maze" class sets the property "randomStartFinish" to "true", meaning the initial locations in the maze of the character and the maze's exit will be random. If you want, you can override this property with "randomStartFinish = nil" in your object definition. Consequently, the character will start at location "1,1", and the maze will have its exit in the last cell.

Step 2: Initializing the "mazeGrid" Property

The JAVA component of the Virtual Maze Generator for TADS 3 produces a file that contains a TADS 3 "Vector" statement. Here's an example:

mazeGrid = new Vector(100,[[9,5,5,5,1,3,13,1,5,7],
[10,13,3,9,6,12,3,12,1,3],
[12,3,10,12,3,11,12,3,14,10],
[11,12,4,3,10,8,3,12,3,10],
[12,5,5,6,10,10,12,3,12,2],
[9,5,5,5,6,10,11,8,7,10],
[10,9,5,5,5,4,6,8,3,10],
[10,12,5,5,3,9,7,14,10,10],
[10,13,5,5,6,12,3,9,6,10],
[12,5,5,5,5,5,6,12,5,6]])

The "Vector" statement includes information about each cell in the maze. Copy this statement from the file.


In your "Maze" object definition, find the "mazeGrid" statement. Here's an example:

+ myMaze: Maze
    /* mazeGrid = new Vector( */
;

Replace the "mazeGrid" statement in your "Maze" object definition with the "Vector" statement that you copied from the file produced by the JAVA component. Your "Maze" object definition might now look as follows:

+ myMaze: Maze
mazeGrid = new Vector(100,[[9,5,5,5,1,3,13,1,5,7],
[10,13,3,9,6,12,3,12,1,3],
[12,3,10,12,3,11,12,3,14,10],
[11,12,4,3,10,8,3,12,3,10],
[12,5,5,6,10,10,12,3,12,2],
[9,5,5,5,6,10,11,8,7,10],
[10,9,5,5,5,4,6,8,3,10],
[10,12,5,5,3,9,7,14,10,10],
[10,13,5,5,6,12,3,9,6,10],
[12,5,5,5,5,5,6,12,5,6]])
;

Step 3: Modifying the special verbs for the "Maze" class

The "MazeClass.t" file in the "TADS 3 Component" installation folder contains the special verbs (i.e. commands) for the "Maze" class. Here's the definition of the "mwest" special command:

function MazeOnlyVerb()
{
    "You can only use this command in the maze.\b";
    return;
}

/*
 * The player entered the 'mwest' command
 */
DefineIAction(mWest)
  execAction()
        {
        if (me.isIn(AnyRoom))
            {
            myMaze.ProcessMaze('west');
            }
        else
            {
            MazeOnlyVerb();
            }
        }
;

VerbRule(mWest)
  'mwest'
  : mWestAction
  verbPhrase = 'moving west'
;


In every special verb for the "Maze" class, find the "me.isIn" statement:

DefineIAction(mWest)
  execAction()
        {
        if (me.isIn(AnyRoom))
            {

Replace "AnyRoom" with the name of the room where your maze is located.


In every special verb for the "Maze" class, find the "ProcessMaze" statement:

DefineIAction(mWest)
  execAction()
        {
        if (me.isIn(AnyRoom))
            {
            myMaze.ProcessMaze('west');
            }

Replace "myMaze" with the name of your maze.


Your TADS 3 program is ready to run with the maze. That simple!