BASIC code examples

 

HomeProjects & InfosCommodore16Bit ComputerCP/M ComputerCP/M Software
Kermit 
CP/M Commander 
Microshell 
DOS/65 
ADA 
BASIC 
BASIC code examples 
C compiler 
FORTRAN 
Modula 2 
PASCAL 
UCSD Pascal 
PL/I 
Adventures 
Power (Shell) 
CP/M-86 

 

BASIC code snipplets for vintage computers

Code example(s)

Because BASIC is such a popular computer language, I decided to add some famous code examples on an extra page (Super StarTrek can be found at the first BASIC page).

One of my first BASIC books was "34 MORE Tested, Ready-To-Run Game Programs in BASIC" from Delton T. Horn (published 1981, TAB BOOKS INC.).
Here's my favorite program from this book:

There's Gold In Them There Skyscrapers

The directions for playing this game are included in the pro­gram listing, steps 450 to 520. You may omit these steps from the program along with steps 15, 20, and 525 to 575 if you want to save program space.

The building layout is included in the array. A(1) to A(100) are set to 0,2,3, or 4. Obviously each array position stands for a room. If a given array position is equal to 2, that's the room holding the gold. This can be any room from #2 to #100 (step 145). Room #1 is the room the game starts in, but it would be a very short game if the gold was found there.

If the array position is equal to 3 that room has an exit from the building. Three of the rooms from 1 to 10 have an exit. These are designated as the ground floor since an exit on the 8th floor wouldn't be too good an idea.

Any of the upper rooms (from 11 to 100) might have a trap door (designated by a 4 in the array position). If you enter one of these rooms, you will fall to the room immediately below it. For exam­ple, room 73 would drop you to room 63. Since each array position can hold only one number, the gold won't be in a room with a trap door.

A zero in the array position is just a space holder with no particular meaning.

If the room has the appropriate doors, you can move to the room on the immediate right, left, above or below the room you're in. The doors are set in array positions A(101) to A(500). A(101) to A(200) determine which rooms have doors to the right (room 38 would correspond to A(138). A(201) to A(300) are the doors to the left. A(301) to A(400) are the doors to the rooms above, and A(401) to A(500) are the doors to the rooms below. A 1 in any given array position indicates the presence of that particular door, while a 0 signifies its absence. (NOTE: you can't always get out of a room the way you came in).

In step 30 all the doors are set to 1, then the impossible doors are removed (steps 40 to 60). These are the doors along the perimeter of the building. There is no room to the left of room 41, for instance, so there shouldn't be a door there, either.

Finally up to 250 of the remaining 360 doors are randomly moved. It's theoretically possible for you to find yourself in a room with no doors at all. If this happens you have to hit the 'BREAK' key to get out of the dead-ended program. I haven't included any protection against this kind of thing because it would take a great deal of program space, and the odds are the problem will never come up anyway. It's possible, but unlikely.

Your moves are limited to Right, Left, Up, Down, or Exit (you can use just the first letters or type out the entire word). Any other entry is an invalid move, but the number of moves will still be incremented by 1, worsening your score. If you try to use a door that isn't there, you'll receive the error message from step 355, and it will be treated as an invalid move.

The only way to end the game is to either BREAK the pro­gram, or leave the building via one of the exits either with the gold (you win) or empty-handed (you lose). After playing a few games you can determine for yourself what kind of score to consider "par." I've seen scores of 150 add up in this game, and once I lucked out and left with the gold in a mere 5 moves.

You can alter the odds by changing step 75. This step begins with the command Y=RND(250). Y is the number of doors to be randomly removed (the number might be reduced if the computer decides to remove certain doors more than once). If you want an easier game you can change this command to Y=RND(100). Or you might try Y=RND(150)+150. There could be up to 300 doors removed (out of 360!), and at least 150 will be removed (except where the computer gets redundant and gives you a break). If you alter this command, be sure to re-enter the rest of step 75 as it is written in the original program. See here for the flowchart.

There is an option to get a secret passageway. Listings below.

Sample Run (Excerpt)

 
GOLD IN THEM THERE SKYSCRAPERS
MOVE #1
YOU ARE IN ROOM #1
YOU CAN MOVE IN THE FOLLOWING DIRECTIONS — RIGHT UP
YOUR MOVE? RIGHT
MOVE #2
YOU ARE IN ROOM #2 THERE IS AN EXIT
YOU CAN MOVE IN THE FOLLOWING DIRECTIONS — LEFT UP
YOUR MOVE? UP
MOVE #3
YOU ARE IN ROOM #12
YOU CAN MOVE IN THE FOLLOWING DIRECTIONS — RIGHT LEFT UP DOWN
YOUR MOVE? RIGHT
MOVE #4
YOU ARE IN ROOM #13
YOU CAN MOVE IN THE FOLLOWING DIRECTIONS — RIGHT LEFT DOWN
YOUR MOVE? RIGHT
MOVE #5
YOU ARE IN ROOM #14 TRAP DOOR!
MOVE #6
YOU ARE IN ROOM #4 THERE IS AN EXIT
YOU CAN MOVE IN THE FOLLOWING DIRECTIONS — RIGHT LEFT UP
YOUR MOVE? EXIT
YOU HAVE JUST LEFT THE BUILDING WITHOUT THE GOLD IT TOOK YOU 6 MOVES

The original listing contained several errors (thanks to Tom Lake), e.g. Z(X) was a mistake, instead A(X) should be used. Also, 'E' was set to 20, but has to be 3.
Seems that TAB BOOKS had published a lot of errors also with the listings.

If you want to run this program with a standard BASIC interpreter, take this file.
If you want to run it with TRS-80 BASIC, take this version.
You have to modify the source to add the secret option or delete the text if you dislike the secret option.

The MBASIC (BASIC-80) version can be downloaded here.

Work still in progress...

 

HomeProjects & InfosCommodore16Bit ComputerCP/M ComputerCP/M Software

Copyright (c) 2005-2014 Peter Dassow. All rights reserved.

peter.dassow@NOSPAM.z80.eu (remove NOSPAM. for a proper mail address)