Classic Computer Magazine Archive COMPUTE! ISSUE 38 / JULY 1983 / PAGE 92

The Fortress Of Adnil

George W. Miller

"The Fortress of Adnil" is an adventure game for the Timex/Sinclair 1000 using the graphics mode. The program is entirely in BASIC and includes several routines you'll find useful in other programs. It requires the 16K RAM expansion module.

Your objective in this game is to accumulate points by gathering energy pellets and recovering the treasure, while avoiding obstacles on the display. Each move costs you one unit of energy; using the laser sword costs more, depending on the range and the object you use it on.

Each move you make is accompanied by random placement of "NAWS" (defined as guards) on the screen. If this random placement puts a guard in the space you intend to occupy, you are captured. If your energy level is greater than 1000, the computer will allow you to pay a ransom, deduct the ransom from your score, and allow you to continue.

You can use your laser sword to cut a hole through any barricade and to oppose the guards. But be warned: the odds are even in any battle with the guards, and you may lose.

Since this game is written in BASIC, don't expect fast-paced action. The game began as a learning exercise in PEEKing and POKEing into the display file.

PEEK And POKE Programming

Enter lines 50 to 120 into your computer. They will print a border around the display and will provide a boundary limiting later POKE commands to the display file.

Now enter lines 220, 250 - 355, 510, and this line:

520 PRINT AT 21, 0; PEEK (PEEK 16396 + PEEK 16397*256 + S)

Then enter lines 530 and 610.

This will allow you to move a character around the screen and also find the CODE of the character stored in that address.

SAVE this before you try it, because if you POKE outside the display file, the program will crash. You'll have to turn off the power and start over.

Now add the missing lines to print a variety of characters on the screen, but don't change line 520 yet. Move around the screen and look at the codes returned from the different locations.

Lines 400 to 430 limit the movement to areas in the display file. Lines 450 to 500 check for the code at that address.

If this is new to you, just remember that POKEing is putting a value into an address, and PEEKing is looking at the value in an address.

Now change line 520 to the line as shown in the program listing. Enter the rest of the listing, and you'll have the complete game The Fortress of Adnil.

If you find the game too challenging, you can change the level of difficulty by changing the 2000 in line 525 to some lower value.

Line 9999 is a utility routine I use to keep track of the length of my program. Enter GOTO 9999, and the screen should say, "LENGTH OF PROGRAM 7456". Since I'm using a 16K RAM, with 16,384 bytes available, I'm well within the limits of memory. Note that line 9999 indicates all memory used, and includes the memory required for the variables, the display file, and the program.

Programming Hints

Now for some hints on making your programs look a little more professional.

The routine starting at line 9991 is self-starting. To SAVE the program, start your tape recorder and enter GOTO 9991. When you load the program again, you won't get the usual 0/0 display, but the program will begin to run, printing the title on the screen. To use this routine, change the program name in line 9995 to the name of your program, and the line number for the GOTO command to the first line in your program.

The Fortress of Adnil-an adventure game for the Timex/Sinclair 1000

This is especially useful in working with files. You can store the data in variables, and when the program comes up it automatically begins, preserving your data, and going a long way towards making the program user friendly.

I have placed this function in the menu of my program "ZX-81/TS-1000 Data Management" (COMPUTE!, March 1983) and saved the data by a step in the program. This makes it a subroutine and it becomes very easy for even the most inexperienced user to save and run the program correctly.

A further step in making other programs user friendly is using INKEY$ instead of INPUT whenever possible. This keeps control of the program in the computer, and the computer will wait for the command it wants to see. (See lines 8020 to 8040.) INPUT permits any number of possible incorrect (or program-stopping) entries.

Attractive Displays

In some versions of BASIC, the command FLASH will cause the display to print normal and inverse characters. The Sinclair computer doesn't have this function, but you can get the same result by a routine similar to lines 8203 to 8205 in the listing. This makes your display a little more attractive, and adds a professional touch to your programs.

When building a display, make use of the graphic mode and the various commands for printing, such as TAB and PRINT AT.

Check each line by entering a GOTO command in the immediate mode after entering the line. If you don't like what you see on the display, press EDIT.

The upper portion of the display will remain unchanged, but the bottom part of the screen will now display your last line entered. Use your edit functions to move the cursor about the line and make any necessary changes. Hit enter, and execute another GOTO command in the immediate mode to recheck your work.