The absolutely most basic text adventure that can be written in Alan would name one location and specify that the adventure starts at that location. The Alan source code for such a basic adventure would look like this:
LOCATION ItsAPlace END LOCATION. START AT ItsAPlace.
This would be a very boring adventure game. No descriptive text would appear on screen. There would just be the word Itsaplace
displayed and a >
symbol on the next line prompting the player to enter a command. However there are no commands the player could use as none have been specified in the source code. There is not even a command to exit from the game. Pressing the Ctrl and C keys simultaneously will crash out of it on most versions of Alan. On the Apple MacIntosh version use Command-Q.
So lets elaborate the source code for our example text adventure a little before we look at how to compile and play Alan games.
Firstly we can add a second location so we can at least move between two places. We'll call it AnotherPlace
. (Note that the names for items in the Alan language cannot have spaces in them. You might want to use underscore characters in location names, eg: Another_Place
, to make them easier to read.)
LOCATION AnotherPlace END LOCATION.
We can decide that "AnotherPlace" will be to the north of our "ItsAPlace" location. To allow the player to move north from "ItsAPlace" to "AnotherPlace" we would add an EXIT
specification to the section of source code describing the "ItsAPlace" location:
LOCATION ItsAPlace EXIT north TO AnotherPlace. END LOCATION.
So the player can move back from "AnotherPlace" to "ItsAPlace" we could add an EXIT south
specification to the source code for "AnotherPlace"
LOCATION AnotherPlace EXIT south TO ItsAPlace. END LOCATION.
Someone playing this game would now be able to type north when they are at "ItsAPlace" to go to "AnotherPlace" and then south to move back from "AnotherPlace." However the player would not know this. The game needs to provide some information to the player about where they are. This is done by writing some descriptive text in a location DESCRIPTION
section such as this:
LOCATION ItsAPlace DESCRIPTION "You are at one particular place. From here you can go north to another place." EXIT north TO AnotherPlace. END LOCATION.
The text within double-quotes will be displayed on screen when the player moves to the location. A similar DESCRIPTION
section can be added in the code for "AnotherPlace:"
LOCATION AnotherPlace DESCRIPTION "You are now at another place. From here you can go south to the first place." EXIT south TO ItsaPlace. END LOCATION.
Try compiling this game with Alan. The source code is included with this tutorial in the file lesson1.ala
- so the command to compile it is
alan lesson1
You can then try playing it with Arun though remember you'll need to use ctrl-c to exit from the game. The command to play the compiled game is
arun lesson1
You could also write your own little two-location game with north and south 'exits' to go between the locations. You can write the game in any text editor or wordprocessor program. A wordprocessor is not the best as you must remember to save the file in plain text format and automatic word wrapping may mess up the layout of your source code.
If your game doesn't compile look for missing full-stops ('periods'). Just like sentences, all blocks of Alan code need a full-stop to mark the end. So EXIT
statements need to finish with a full-stop and the END LOCATION
lines need full-stops as well.