Computer Games To Play and Write
Computer Games To Play and Write
DAN ISAAMAN
t pl e
for use with ZJ(-Spectrum, BBC, Electron, VIC
and Dragon computers
A Sparrow Book
Published by Arrow Books Limited
17-2 1 Conway Street . Londo n WIP 6JD
Fi rs t pu blished 1983
Re printcd 1984
© Dan 1saama n 1983
Illustratio ns © Sparrow Books 1983
This book is sold subject to the cond it ion thai it :;hall
no t. by way o f trade or othe rwise. be lent resold .
hired o ut , or o th e rwi se circulat ed with o ut the
publisher's prior consent in any form of binding or
cover other than that in which it is published and
without a similar conditio n including thi ~ cOl1dition
being imposed on the suOseque nt purchaser
ISB N 0 09 33330 9
I would like to thank Eleanor Nabney, without whom
the programs in this book would not have been tested
so thoroughly, and many would not e~en exist. I would
also like to thank my trusty EPSON QX·' a computer,
on which most of this book was written and printed,
and my mother, who had to put up with the computers
all over the house. Thanks are also due to Sinclair
Research and Dragon Data for the loan of their
computers.
To Eleanor
with love
CONTENTS
Foreword 9
Notes for using the book 11
Summary of instructions 15
Game 1: Christmas Time 17
Game 2: Red Alert! 21
Game 3: Spy Codes 24
Game 4: Ring-a-Ring O'Robot 30
Game 5: Nim 33
Game 6: From the Depths of Time 37
Game 7: Galaxy Hitch-hike 41
Game 8: planet Lander 44
Game 9: Animal 49
Game 10: Silo Raid 53
Game 11: Haunted House 58
Game 12: Escape 62
Game 13: Space Dogfight 66
Game 14: Death Raid 70
Game 15: Cowboys and Indians (ZX-Spectrum) 75
Game 16: Cowboys and Indians (VIC) 80
Game 17: Cowboys and Indians (BBC/Electron) 85
Game 18: Cowboys and Indians (Dragon) 91
How to write your own program: Sabotage 96
BASIC and its commands 105
Glossary 112
Appendix 126
FOREWORD 9
I had great fun creating the games in this book. Some are games of
skill, such as Haunted House and Planet Lander; others are mind·
stretchers, such as Christmas Time and Nim; all, I hope, will provide
you with hours of entertainment as you pit your wits against your
computer. The games are designed to be used on five different
computers, but at the end of the book you will find a supergame
created especially for your machine.
Having played all the games in this book you may feel tempted
to write some games yourself- Throughout the text I have put in
tips and explanations on the computers and programs. There are
also full explanations of what the program is doing line by line, and
suggestions for ways in which you can change and adapt the
games.
I do hope this book manages to fire your imagination and induce
lots of midnight sessions at the computer, and I hope everyone
ends up creating games that are at least as good as the ones in this
book.
Happy computing'
Dan Isaaman
r
NOTES FOR USING THE BOOK ,,
The purpose of this book is to provide you with exciting games to
play on your computer. In the course of playing the games you will
find that your skills and knowledge of programming increase. I
hope that you may be inspired to write your own games.
The book is designed for use with five computers:
BBC
Dragon
Electron
VIC
zx·Spectrum
There are slight differences in the way the BASIC language inside
each of these computers works. Because of this, the programs have
changes in some lines depending on which computer you are using.
There are two areas of change:
1. At the end of each program you will see that there is a section
written specially for your computer. When you get to this
section, pick out the box that holds the lines for your computer
and type only these lines into your computer.
2. Lines in the earlier part of the program sometimes need
changing too. When this happens the lines are printed in green.
A letter in the left-hand margin indicates which line you should
type in. The letters are as follows:
b BBC and Electron
5 ZX-Spectrum
d Dragon
v VI C
When you see these letters in the margin, type in only the line that
has the letter corresponding to your computer against it. For
instance, suppose you see the lines:
~d 90 IF H$(Q)()" THEN GOTO 80
5 90 IF HS Q,1l0 THEN GOTO SO
If you own a ZX-Spectrum, then you should type in line 90 as:
90 IF H'(Q,l)()' , THEN aOTO 80
12 NOTES FOR USING THE BOOK
If you own a BBC, Dragon, Electron, or VIC you should type line 90
in as:
90 IF H$(Q)<>" THEN GOTO 80
The programs in this book are written in BASIC. A section at the
back of the book explains how this language works. Once you
know this language you can use it to write simple programs and
games. The game Sabotage shows you how you can create a
game.
To type in and playa game, the first thing you must do is get
your computer ready. Plug the computer and the television or
monitor screen into the mains and connect them using the cable
provided with your computer. Switch them on.
You are now ready to type in a program. The computer knows
that you are typing in a program when each line that you type
begins with a number. The computer sorts the individual lines into
a program, with the lines appearing in numerical order. If you look
at the programs in this book you will see that the line numbers
usually go up in steps of ten. Programs are written in this way so
that if there are any extra instructions to be added this can be done
using the line numbers that are still available between those
already used.
When you are typing in the program, be very careful to get it
exactly right. Type in each line one by one, starting with the line
number and finishing by pressing the RETURN or ENTER key. Make
sure that the commas, semicolons, spaces and confusing letters
and numbers such as a and 0 are typed in exactly as they are in
the book.
If you have a tape recorder or disc drive connected to your
computer, you can store the game program on tape or disc. If you
do this, you will of course only need to type in a game program
once, and you can load it back from tape or disc whenever you
want. Look up the commands SAVE and LOAD in the manual for all
the computers except Dragon. For Dragon look up CSAVE and
CLOAD. This section will tell you how to give the program a name
NOTES FOR USING THE BOOK 13
on disc or tape so that you can load it back into the computer at
any time.
Note that with some tape recorders it may take a little time to
adjust the recorder and the computer to achieve accurate program
storage. Your computer manual should provide full details.
Once you have typed in the program, read the scenario above
the game that tells you what you must do once the game has
started. Then type the command RUN into the computer. This is a
direct command to the computer so it does not need a line number.
Then press the RETURN or ENTER key and the computer will start
the game.
The game should now work perfectly. If it does not, the computer
will usually tell you immediately by stopping the program and
displaying an error such as:
SYNTAX ERROR IN LINE 120
Alternatively, it may be that the computer just does not behave as
you expect. In either case you will have caused a bug (error) in the
program by typing in an instruction incorrectly. You must go
through the program checking every single line against every single
line of the program listed in this book. To get the program
displayed on the screen you use the UST command.
For example for the BBC and Electron,
LIST 10,200
will list lines 10 to 200.
For Dragon and VIC,
LIST 10-200
will list lines 10 to 200.
For ZX·Spectrum,
LIST 10
will list the program to the bottom of the screen.
r
1 : CHRISTMAS TIME 17
111111111111111111111
18 CHRISTMAS TIME
5 19, IF 1$11,11=" TMEN pOIF fDU ALREADY
DELI 'ERED 0 ~E ERE": 60-0 250
200 IF Z<> Q THEN GOTo 230
210 PRINT "PRESENT DELIVERED"
220 LET L=L+l : LET H$IQ)="" : GoTO 250
230 PRINT "THIS HOUSE BELONGS TO ";HIIZ)
240 PRINT "THE PERSON YOU WANT IS "; ABS IZ-O);
" DOORS AWAY."
250 IF L=N THEN GOTO 290
260 NEXT G
270 PRINT "YOUR TIME RAN OUT. YOU TURNED INTO
A REINDEER!"
280 GOTO 4000
290 PRINT "YOU DELIVERED THEM ALL IN ";G;
" GOES, WELL DONE"
300 GoTO 4000
310 DATA "SMITH","JONES","BLOGGS","WILSON"
320 DATA "MILLER","ENGLAND","EDWARDS" •
330 DATA "O ' BRIEN", "CLARKE", "GROT" ....
For the different computers
-----=--------~
70
• TO END) : "
INPUT W$
80 IF ~j$="iu THEN GOTO 210
90 LET M$=M$+W$+ "
100 GOSUB 500
110 GOSUB 2000
120 PRINT "CODED WORD IS: J(
130 PRINT xt
ep·p' e sdsyoc·ocesdyps·
. . . . . . . . . .. .. . . .. . . . '. . ~
26 SPY CODES
For the different computers
ERe Electron Oragon ,,
1000 DEF FNR IXI=R ND IXI 1000 DEF FNRIXI=RNDIXI
1010 RETURN 1010 RETURN
2000 CLS : RETURN 2000 CLS : RETURN
3000 LET U=INKEY$(\I 3000 LET U=INKEH
3010 RETURN 3010 RETURN
4000 END 4000 END
,;~"., , p5p~~ L ~
' ..
Line 200 repeats the process by going back to
line 60, where you will enter a new word (or a
) .
Lines 210-240 display the final decoded message,
and the original message that you wanted to
send.
Lin. 250 checks whether you got it all right. If
s o, it displays a message and stops the
program.
Line 260 checks if the length of the two
messages is the same or not. If not, the
computer will go to line 320 and print a
suitable message.
Lines 270-300 go through the two strings,
checking each letter. Each time a letter is
wrong, the variable N is increased by one
(starting at zero), so it will contain a count
of the number of your mistakes.
28 SPY CODES
Line 3 10 displays a message telling you how much
you got ~irong .
Lines 320-3 30 display a suitable message, and
stop the program.
Lines 500 - 580 contain the subroutine to code and
decode a word. Th e first time it is used, it
will code the string in W$ and put the result
in XS. The next time, it will decode the
string in WI and put the result in XS . It does
this by changing the sign of the secret cod e
number, C, in line 570. If effect, each letter
is moved through the alphabet C times to get
i t s coded version.
Lines 1000-400 0 contain the standard routines .
p·pe·idsuoc·:oce·idUps:~
......... ....... ....... ~.
30 4 : RING-A-RING O'ROBOT
Androids surround you. They have stolen the time key without
which you cannot leave their planet. They are teasing you, passing
the time key around the circle between themselves, constantly
changing the direction it goes in. They've told you that if you can
touch the android who holds the key, you can have it back. Each
android is represented on the screen by a letter.
From the glimpses you get of the key as it goes round, try to
touch the person holding it by typing in his letter as quickly as
possible. If you aren't able to touch the android holding the key
after a certain time, you'll just have to accept you'll never see the
planet Earth again.
d
vs
60 FOR N=O TO 11
70 LET P$=CHR$(65+N ) : GOSUS 210
80 NEX T N
90 LET N=FNR ( 12)-1
100 LET D=1
11 (I IF FNR ( 10 » 4 THEN GOTO 170
120 LET P$;;U4 : GOSUB 210
U
..
..
NIM 35
\:l ~
You have been abandoned in the far reaches of the galaxy, and you
have vital information about an underground organization
planning to overthrow Galactic High Command. You must return to
Earth in time to warn them of this plot. Your only hope of getting
back is to hitch lifts from passing trade spaceships.
There are many passing ships, but can you manage to plan your
way back to Earth in time to save the Empire. You have a limited
amount of money with which you can try to bribe the captain of a
ship to take you nearer to Earth, but you may just have to rely on
luck and intuition ..
10 GOSUS 1000 : GOSUB 2000
20 PRINT 'GALAXY HITCH-HIKE'
30 PRINT
vbd 4
5 urI
50 LET M=2 : LET T=O
60 FOR 1=1 TO 10 READ S$(I)
70 NEXT I
80 LET S=8+FNR(2)
90 FOR 1=1 TO 1000 : NEXT I :
GOSUB 2000 : GOSUB 500
100 PRINT 'YOU ARE ON ';S$(S)
110 LET T=T+I
121) LET P=FNR (S)+FNR(10-S)'(FNR(2)- I)
130 IF P=S THEN GO TO 110
140 PRINT 'THERE IS A SHIP GOING TO'
150 PRINT S$(P)
160 PRINT "00 YOU WANT TO TAKE IT"
170 FOR 1=1 TO 500 : GOSUB 3000 : IF I$ ()"
THEN LET 1=500
180 NEXT I : IF 1$=" THEN PRINT 'IT LEFT"
GOTO 90
190 IF I$='Y' OR II=' y' THEN LET S=P
200 IF S=1 THEN GOTO 300
210 IF M= O THEN GOTO 90
2 GALPJrf HITCH-HIKE
220 PRINT "DO YOU WANT TO TRY TO BRIBE
THE CAPTAIN?"
230 FOR 1'1 TO 500 : GOSUB 3000 : IF I$ () ""
THEN LET 1=500
240 NEXT I : IF 11= "" THEN PRINT "TOO LATE'"
GOTO 90
250 IF I. () "Y" AND I. ()"y" THEN GO TO 90
260 IF FNR (10 1( 7 THEN PRINT "DIDN ' T HELP! "
GOTO 90
270 LET 5=5-1 : LET M=M-I
2BO PRINT "YOU ARE NOW GOING TO"
290 PRINT 5$(51 : IF SO l THEN GOTO
300 PRINT "YOU MADE IT TO EARTH !"
310 IF T) 12 THEN PRINT "BUT THE
REVOLUTION HAS STARTED"
320 IF T<=12 THEN PRINT
"YOU GOT THERE IN TIME'"
330 PRINT "YOUR JOURNEY TOOK" j Tj" WEEKS"
340 GOTO 4000
500 PRINT' '";TAB(201;"'"
510 PRINT "CENTRUS ' " jTAB(161;"DELTAR"
520 PRINT TAB(BI; "V EGA"
530 PRINT "1 ";TAB(15);"* "
540 PRINT "TRALIN";TAB(131;"SIRTEP'
550 PRINT TAB(IOI;"+"
560 PRINT TAB(9); "EARTH ."
570 PRINT TAB(4)j"'"jTAB(16);"FROP"
5BO PRINT" GRAPLOR"; TAB (131; "."
590 PRINT TAB(12); "DORF ."
600 PRINT TAB (17) ; "PLOT"
610 RETURN
700 DATA "EARTH","SIRTEP","FROP " ,"GRAPLOR'
710 DATA "VEGA", "TRAUN", "DORF" ,"DELTAR"
720 DATA "CENTRUS","PLOT"
GAlAXY HITCH-HIKE 43
ZX Spectrum
1000 DEF FNR(XI 1000 DEF FNR(XI
=INT(RND(1)*X+ll =INT(RND*X+ll
1010 RETURN 1010 RETURN
2000 PRINT CHR$(147l; 2000 CLS : RETURN
: RETURN 3000 LET 1$= I NKEH
3000 GET U 3010 RETURN
3010 RETURN 4000 STOP
4000 END
44 8: PLANET LANDER
You are on a secret mission for High Command in a prototype
spaceship. After a live·month joumey, you have come into orbit
around the planet that is your destination. You must now try to
land on it. Your instruments give you readings about the planet,
telling you how strong the gravity is and what the atmosphere is
like. You must land safely on the surface.
At each stage of the descent you type in how much you want
your engines to thrust, in order to slow you down. As you get closer
to the planet beware of going too fast. To land safely you need to
go very slowly. But if you thrust too much you will start going
upwards, towards sure execution by Higr' Command who will not
tolerate the failure of missions.
You only have a limited amount of fuel. You are able to burn from
o to 40 units of fuel on each go.
In this game the computer will try to guess what animal you are
thinking of. The fun of the game is teaching the computer to ask
more and more questions about different animals.
On each go, you are asked to think of an animal but not to tell
the computer what it is. Then it will ask questions about the animal
to which you must answer 'Yes' or 'No'. After a few questions, it will
take a guess at the animal. If it is right, you will be glad you have
such a clever machine. If it is wrong, you must teach it how to
recognize the animal you were thinking of, so that next time it may
be able to guess it correctly.
. ~•. ~ .
ANIMAL 51
ZX-Spectrum '
1000 DEF FNR(X) 1000 DEF FNR(X)
oINT(RND(I)*X+l) °INT(RND*X+l)
1010 RETURN 1010 RETURN
2000 PRINT CHR$(147); 2000 CLS : RETURN
: RETURN 3000 LET !$o!NKEY$
3000 GET It 3010 RETURN
3010 RETURN 4000 STOP
4000 END
How the program works:
Lines 10-30 clear the screen and display the
title of the game
Line 40 sets up three array variables, Q$ holds
the questions, N holds the references to the
next question each time, and a$ holds the
different animal types,
Line ~O reads in the number of items in the
question array, and the number of animals
( into Nl and N2 respectively)
Lines 60-100 read in all the data in line 900
onwards into their respective arrays.
Line 110 clears the screen and prints the
message: ' THINK OF AN ANIMAL ' ,
tt I1
-1
I
52 ANIMAL
Line 120 sets the current question to number 1.
Line 130 prints the question
Line 140 gets an answer from you - either ' Y' or
'N' •
Lines 150-160 calculate the position of the next
question or solution, from your answer and
from the value stored in the array N,
Line 170 checks to see if there is a solution
(ie the computer has run out of questions. If
not, the computer will go back to print the
next question.
Lines 180-190 gets the animal number and print
' ISlTA .... '
Line 200 gets your reply, either 'Y' or 'N '
Line 210-230 checks if if you answered ' N', and
if not, prints a message and goes back for
another game.
Lines 240-250 ask you to input the animal you
were thinking of, and store it in TS,
Lines 260-280 ask for a question that would
distinguish the two animals, and stores it in
5$
Lines 290-300 ask you whether the answer to your
question would be yes or no. If it is yes,
then Z is set to (I, if no, Z is set to 1-
Lines 310-370 update the arrays and counters, so
that the new animal is learned by the
computer.
Lines 380-390 tells you that the computer has
learnt the animal, and is ready to play again,
which it does by going back to line 120.
Lines 800-830 accept a single key input from
you, ~~hi[h can either be ' Y ' or ' N' , and print
it on the screen.
Lines 900-930 contain the starting data for the
program.
Lines 1000-4000 contain the standard routines.
1 0 : SILO RAID 53
You are sailing over enemy waters and you have been ordered to
bomb and destroy all the underwater silos containing the enemy's
newest and most dangerous weapons. Your ship contains twelve
guided depth charges which will land on the sea bed at the spot
you choose by giving co·ordinates.
You also have the use of a sonar but, unfortunately, it is not
functioning correctly. The picture it gives is muddled and slightly
incorrect. Can you make some sense from the display it gives to
help you find the exact location of the silos you must destroy?
3 4 5 7
5
I- +
6
7
+
8
,,
20 DIM 8(8,8)
30 LET N=6
40 LET H=i)
v
" T .
,
bds c TO
60 FOR 1=1 TO N
70 LET X=FNR(S) : LET Y= FNR(S )
80 IF B<X,Y)OO THEN GOTO 70
54 SILO RAID
90 LET SIX,Y ) =-I : NEXT
100 LET Q$="SILO RAID"
110 FOR G=I TO N*2
120 GOSUS 2000
130 PRINT Q$
140 PRINT "YOUR MAP";TABIT);"SONAR "
150 LET F=FNR(7)
160 FOR Y=I TO 8
170 LET Z=O : GOSUB 400 : PRINT TAB IT) ;
180 LET Z=I : IF Y+F >8 THEN LET F=F-8
19 0 GOSUB 400 : PRINT
200 NEXT Y
210 PRINT "X-POSITION" INPUT X
220 PRINT "V-POSITION" INPUT Y
230 IF X( I OR Y( I OR X) 8 OR Y) 8 THEN GOTO 21 0
240 IF BIX, Y) =9 THEN GO TO 210
250 IF BI X,Y ) =O THEN LET BIX,Y)=9 : LET
Q$="MISS"
260 IF BI X,Y ) =-I THEN LET BIX,Y)=I : LET
H=H+I : LET O$="HIT"
270 IF H=N THEN PRINT "ALL SILOS DESTROYED!"
GOTO 4000
280 NEXT G
290 PRINT QS
300 PRINT "YOU RAN OUT OF DEPTH CHARGES"
310 PRINT "YOU HIT ";H;" SILOS"
320 GO i O 4000
400 FOR 1=1 TO 8
410 LE T V=BIX,Y+FIZ )
420 IF '1=0 OR IV =-I AND Z=O) THEN LET PI=", "
430 IF V=I OR IV=-I AND Z=I ) THEN LET P$= "S"
440 IF V=9 THEN LET P$=","
450 IF Z=I AND FNRIIO)4 THEN LET PI= ","
460 PRINT P$,
470 NEXT X
480 RETURN
SILO RAID 55
,,
, ,
56 SILO RAID
How the program works:
Line 10 clears the screen and sets up the random
number generator.
Lines 20-50 set up the various variables In the
program. The map is held in an array called B,
which is a grid, eight by eight in size. N
holds the total number of silos, H the numb er
you have hit, and T and S$ are used for
printing out the map on your screen.
Lin.s 60-90 put the silos in random positions on
the map.
Line 100 puts the title of the game into OS,
which is printed in line 130. Q$ is then used
to print the HIT and MISS messages.
Line 110 is the start of the loop giving you a
number of goes equal to twice the number of
silos you have to bomb.
Lin.. 120-140 clear the screen, prints the
message in Qt (s ee line 100 and lines 250-260)
and prints the heading for the two maps.
Line. 1~0-200 control the priRiing of the two
maps on the screen, al ong with the subroutine
at line 300. F is used to muddle up the sonar
map.
Lines 210-230 get the coordinates of your bombin ,
position and check whether it is valid.
Line 240 checks whether there already is a bomb
there, In which case you have to try somewhere
else.
Lines 250-260 check if It is a mIss or a hit,
and change the numbers stored in the map array
accordingl y . If It is a hit, the count in H IS
increased. Q$ is set to a message that wlll be
printed out ne xt go! in line 130.
Line 270 checks if all the ships are hit, and jf
so tells you and stops the game.
SILO RAID 57
5
"
1 (, NT
i: ..... 1
PRINT
H
@
, ..
. . · ::1'"C .
u u
Ij
;
d J. .. ..) 0
y 110 PRINT CHR$(19 ) ; :FOR 1=1
TO Y:PRINT:NEXT I :
PRINT TAB ( X) : "0 0'" ,
120 NEXT G
b .. :(, Pc I IT CHF:$130' :
FR , HT ..
5
d 1'
y
1::0
-. )
.J f' h,
',lilT
.j
~T
T
;~ l.
C~~S{l:f
.. ':
HAUNTED HOUSE 59
zx Spectrum
1000 DEF FNRI X) 100 0 DEF FNRIX )
=INTIRNDII ) *X+I ) =INT IRND*X+1)
1010 RETURN 1010 RETURN
2000 PRINT CHR$(147 ) ; 2000 CLS : RETURN
: RETURN 3000 LET I $= I NKEY$
3000 GET It 3010 RETURN
3010 RETURN 40 00 STOP
4000 END
60 HAUNTED HOUSE
How the program works:
Lines 10-3 0 clear the screen and print the title
of the game.
Line 40 sets the count of the number of ghosts
that are not banished forever to zero (in T).
Line SO 15 the start of the loop giving you ten
roams .
Lines 60-70 clear the screen and display the
current room that you are in .
Lines 80-12 0 choose a random number of ghosts
far this room (beb~een one and eight), and
displa y this number of ghost·s eyes on the
screen at random posItions.
Line 130 sets the cursor to the top left hand
corner of the screen again .
lines 140-17 0 glve you a certaIn time to press a
key, and, if it is a number key, put its value
into K .
Lines 180-190 display messages if you got the
number wrong ( ei ther too small or too l arge i.
Line 200 add the number of ghosts left in the
room to the total count of ghosts left in T.
Lines 210-220 delay a wnlle, and then rep.at the
loop for the next room.
Lines 230-240 dlsplay a message telling you how
man y ghosts were left in the house after you
ha ve gone through all ten rooms.
Line 250 check It vou banIshed all the ghosts,
and if so diplays a suitable message and ~tops
the program.
Lines 260-280 tell vou that you 11 have to try
again, since you didn ' t get all the ghosts,
delays a whilE, and restarts th~ program from
line 40.
HAUNTED HOUSE 61
45 RESTORE
62 12 :ESCAPE
You have been taken to a high-security prison for crimes you did
not commit. You are determined to get out and put the real culprit
behind bars. You plan to escape by digging a tunnel out of the
prison. A fellow prisoner draws you a map of the prison and its
surroundings. From where your cell is positioned you must decide
in what direction you want to dig your tunnel and how long it
should be. Your cell is marked by a # sign. If you dig too far you
will collapse from exhaustion and be discovered. If your tunnel is
too short you will come up inside the prison. And of course there
may be problems when you get out. _..
mm~~<~:~:~~::-~:~:~~~:~~--" IIII!
910 LET 19-(1 : LET Y9-0
;
920 INPUT Df
930 IF O$;;IIN OR 0$;;110" THEN LET Y9--!
U
zx Spectrum
1000 DEF FNRI X) 1000 DEF FNRIX)
;INTIRNDII)*X+I) ;INTIRND*X+I)
1010 RETURN 1010 RETURN
2000 PRINT CHR$11471; 2000 CLS : RETURN
: RETURN 3000 LET 1$;INKEY$
3000 GET 1$ 3010 RETURN
3010 RETURN 4000 STOP
4000 END
NEXT I
560 IF I$="X" OR I$="x" THEN LET 0=D-2 : GOTO
800
570 IF (1$="E" DR l$="e") AND FNR(10) ( 8
THEN LET 0=0+2 : GOTO 800
580 PRINT "YOU LOST THE ATMOSPHERE' '"
590 GOTO 4000
800 FOR 1=1 TO 100 : GOSUS 3000 : IF IS="" THEN
NEXT I
810 IF ( l$ ="F" DR H ="f") AN D (0=0 OR 0=1) THE N
PRINT "HE'S DESTROY ED!" : GO TO 4000
820 IF 0) 0 DR FNR(10) ( 5 THEN GOTO 860
830 PRINT "HE FIRES , ","
840 IF FNR(10) ( 4 THEN PRINT "AND HITS YOU"!!"
GOTO 4000
850 PRINT" " , BUT MISS ES,"
860 IF Deo OR D)3 THEN GOTO 900
870 IF FNR(IO) ( 4 TH EN PRINT "HE DIVES AND LOOPS
UNDER" : LET 0=-0
900 GOTO 80
SPACE DOGFIGHT 69
2 3 4 5 6 7
r
T
2
~
3
4
t
5
1'"
6
T
zx Spectrum
100 0 OEF FNR (X ) 1000 OEF FNR (X)
=INT(RND(I)fX+I ) =INT ( RNO fX +I)
101 0 RETURN 101 0 RETURN
2000 PRINT CHR$ ( 14 7) ; 2000 CLS : RETURN
: RETURN 3000 LET 1$= I NKEY$
3000 GET 1$ 3010 RETURN
30 10 RETURN 4000 STOP
400 0 END
ZX-Spectrum
A whole village depends on you. You, Wild Bill, are the only
person left who can defend the village from a group of advancing
Indians. You have got your trusty six-shooter, and you use it to kill
the Indians hiding behind the cacti, shooting one bullet at a time.
But you have to keep pausing to reload every six shots, in which
time the enemy will creep forwards and dead Indians will be
replaced with live ones.
The Indians will only come out of hiding for a few seconds - so
be quick! If you do not shoot, they will once again come closer. Let
them creep too close and you will be overwhelmed.
To move up and down press the A and Z keys respectively. To
fire, press the RETURN or ENTER key.
260 8E=0
270 FOR J=! TO 3
280 IF MIJ)=O THEN 340
290 C=l:GOSUB 1800
300 HIJ)=l··HIJ):MIJ)=1)
310 IF IIJ)=O THEN G05UB 2400:GOTO 340
320 GOSUB 2300
330 C=3 : G05UB 1800
340 NEXT
350 GET Jj"
370 IF IS="" AND BE=O THEN Z=Z+l : GOTO 4~O
380 Z=0
390 IF I.="A" AND CR=(i AND CY)2 T~EN CM=-l
400 IF I$="Z' AND CR=O AND CY<19 THEN CM=l
4]0 IF U=CHR$I]3) AND CR=O AND BE=O
THEN GOSUB 2500
420 IF Z=40 THEN 440
430 CR=CR+SGNICR) : IF CR(20 THEN 460
440 MX=MX-3:IF MI=l THEN GOSU8 2800:END
450 CR=O:GOTO 80
460 FOR J=l TO 3
470 IF IIJ)=l AND HIJ)=I) AND RND(1) \ ,Ol
THEN MIJ)=l
480 NEXT
490 FOR J=l TO 3
500 IF HIJ)=O OR IIJ)=O THEN 520
51(, liJ,=IIJ)+i:P' I(J)=MX +l0 THEN MI.JI =l:
IlJ)=1
521) NEXT
530 IF !ll)+1121+11})=0 THEN GOSUB 2600 : END
540 GOTD 110
1000 REM INITIALIZE
lOll) MX=16 : S=O : BN=O
1020 DIM V(3) , 1(3) ,H(3) ,M(3)
1030 POkE 36879,25
104,) RETURN
1200 REM DISPLAY TITLE
1210 PRINT eHRS(147)
82 COWBOYS AND INDIANS
1220 PRINT TAB(8) jCHR$(159) j "COW80YS'
1230 PRINT TAB(IO),CHR$(30),"AND"
1240 PRINT TAB(8)jCHR$(28)j"INDIANS"
1250 PRINT,PRINT
1260 PRINT CHR$(144)
1270 PRINT A TO GO UP·
1280 PRINT Z TO GO DOWN"
1290 PRINT "RET TO FIRE"
1300 FOR 1=1 TO 2000:NEXT
1310 RETUf\N
1500 REM SET UP VARIABLES
1510 CX=2:CY=18:CR=O:CM=1
1520 BX=O:BY=O:BE=O
1530 Y(I)=5:Y(2)=12:Y(3)=19
15401(11=1:1(21=1:1(31=1
1550 H(!I=I:H(21=I:H(31=1
1560 M(II=I:M(21=I:M(31=1
1570 ;X=5:K=0:Z=0
1580 RETURN
1600 REM DISPLAY GAME SCREEN
1610 PRINT CHR!(147Ij
1620 C=I:GOSUS 2100
1630 C=2:GOSUS 2100
1640 C=3:S0SUS 2100
1650 RETURN
1700 REM DRAW COWBOY
1710 P=CX+CY*:2+7658
1720 POKE P,254:POKE P+I,252:POKE P+22,225:
POKE P+23,126
1730 POKE F+44,225:POKE P+45,97:POKE P+66,225:
POKE P+b7, 126
1740 POKE F+88,225: POKE p t 8?,I23
1750 FOR X=O TO I:FOR Y=0 TO 4:
POKE P+X+Y'22+30720,C:NEXT:NEXT
1760 RETUR~
1800 RE~ DRAW INDIAN
1810 P=MX+!).+i\ (JI-H (J ; f31<22+7658
1820 POKE F,B5:POKE P+22,81:POKE P+44,91:
POKE P+66,113
COVVBOYSANDINDU\NS 83
BBC/ Electron
A whole village depends on you. You, wild Bill, are the only
person left who can defend the village from a group of advancing
Indians. You have got your trusty six·shooter, and you use it to kill
the Indians hiding behind the cacti, shooting one bullet at a time.
But you have to keep pausing to reload every six shots, in which
time the enemy will creep forwards and dead Indians will be
replaced with live ones.
The Indians will only come out of hiding for a few seconds - so
be qUick! If you do not shoot, they will once again come closer. Let
them creep too close and you will be overwhelmed.
To move up and down press the A and Z keys respectively. To
fire, press the RETURN or ENTER key.
2170 ENDPROC
2200 DEF PROCBANG
2210 SOUND &10,1,5,10
2220 ENDPROC
2300 DEF PROCPING
2310 SOUND &11,2,200,5
2320 ENDPROC
2400 DEF PROCDEAD
2410 SOUND &12,3,200,35
2420 ENDPROC
2500 DEF PROCFIRE
2510 BE=I :B I=CI+80 : BY=CY-30 : BN=BN+1
2520 IF BN=7 THEN 8N=0 : BE=O : CR=1:ENDPROC
2530 PROCCOW80Y ( C~,CY,O,CL,OI
2540 PROCCOWBOY (CI,CY,3,CL, II
2550 PROCBANG
2560 PROCCOWBOY(CI , CY,O,CL, 11
2570 PROCCOWBOY(CI,CY,3,CL,01
2580 ENDPROC
2600 DEF PROCWON
2610 VDU 4,12 : COLOUR J
2620 PRINT ' "THE REST OF THE"
:630 PRINT . 'INDIANS HAVE RUN"
2640 PRINT . "AI~AY , YOU SAVED"
2650 PRINT "THE VILLAGE,"
2660 <FI12,O
2670 ENDPhOC
2700 DEF PROCSCORE
27!(1 VDU 4,30
2720 PRINT "INDIANS KILLED: " ; S
2730 \lDU 5
2740 ENDPROC
90 COWBOYS AND INDIANS
2800 DEF PROCLOST
2810 VDU 4,12 : COLOUR
2820 PRINT ' ' "YOU HAVE BEEN"
2830 PRINT' >"OVERWHELMED BY"
2840 PRINT ' '"THE INDIANS"
2850 SOUND 1,-10,16,8 : SOUND 1,-10,0,10
2860 *FXI2,0
2870 ENDPROC
3000 DATA 60,60,2~5,60,60,60,56,254
3010 DATA 140,146,146,146,186,154,138,138
3020 DATA 130,159,130,130,130,130,130,130
3030 DATA 138,254,40,40,40,40,44,48
3040 DATA 138,254,40,40,40,40,56,12
3050 DATA 0,0,0,0,0,4,14,14
3060 DATA 14,14,14,14,14,15,7, I
3070 DATA 0,0,8,28,28,28,28,28
3080 DATA 28,28,28,28,28,28,28,31
3090 DATA 15,7,0,0,0,0,0,0
3100 DATA 56,124,124,254,254,254,254,254
3110 DATA 254,254,254,254,254,254,254,254
3120 DATA 255,255,255,254,254,254,254,254
3130 DATA 0,0,0,0,0,0,0,32
3140 DATA 112 , 112 , 112 , 112,112,112,112,112
3150 DATA 240,224,192,0,0,0,0,0
3160 DATA 0,0 , 0,0,0,0,0,0
3170 DATA 0,0,0,192,192,248,252,255
3180 DATA 254,255,~55,254,254,255,255,255
3190 DATA 254,248,240,224,192,0,0,0
3200 DA TA 4,8,8,60,60,60,60,28
3210 DATA 124,68,68,68,68,68,68,68
3220 DATA 124, 40,40,40,40,40.104,24
18: COWBOYS AND INDIANS 91
Dragon
A whole viDage depends on you. You, wild Bill, are the only
person left who can defend the village from a group of advancing
Indians. You have got your trusty Six-shooter, and you use it to kill
the Indians hiding behind the cacti, shooting one bullet at a time.
But you have to keep pausing to reload every six shots, in which
time the enemy wiD creep forwards and dead Indians wiD be
replaced with live ones.
The Indians wiD only come out of hiding for a few seconds - so
be quick! If you do not shoot, they will once again come closer. Let
them creep too close and you will be overwhelmed.
To move up and down press the A and Z keys respectively. To
fire, press the RETURN or ENTER key.
260 BE=O
270 FOR J=1 TO 3
280 IF M,J)=O THEN 340
290 C~2:GOSUB 1800
300 H(J)=I··H(J):M(J)=O
310 IF I(J)=O THEN GOSUB 2400:60TO 340
320 GOSUB 2300
330 C=3:GOSUB 1800
340 NEXT
350 1$=INI EVt
370 IF 1$=" AND 8E=0 THEN Z=2+1:GOTO 420
380 Z=0
390 IF II='A' AND CR=O AND CYi5 THEN CM=-1
400 IF I'='Z' AND CR=O AND CY<160 THEN CM=1
410 IF I$=CHR$(13) AND CR=O AND BE=(I
THEN GOSUB 2500
420 IF Z=4V THEN 440
430 CR=CR+SeN (CIi) : IF CR 20 THEN 460
44v MX=MX-50 : IF MX=O THEN BOSUB 2800 : END
450 CR=O:GO·O 80
460 FOR J=I TO 3
470 IF I (J)=1 AND H(J)=O AND RND,(»)' .01
THEN M(JI=1
480 NUT
490 FO~ J=1 TO 3
500 IF H(J)=O OR I(J)=O THEN 520
510 I(J)=l i JI+I:IF I(J)=hX/5 THEN H(J)=I:I(J)=l
520 NE Xl
530 IF 1111+1(2)+1(31=0 THEN GOSUB 2600 : END
540 GOTO 11')
1000 REM INITIALIZE
1010 MX=200 : S=O : BN=O
1020 DIM VI3), 113! ,H(3) ,~1(:,)
1030 RETURN
1200 REM DISPLA\ TITLE
1210 CLSO
1220 PRINT @77,'COW80YS",
1230 PRINT @143,'AND' ,
1240 PRINT @205,'INDIANS';
COWBOYS AND INDIANS 93
4. If the player doesn't find the bomb after three tries, print a
message saying that the ship has blown up, and stop the game.
5. If the player guesses the position of the bomb in time, print a
message saying that he has found it.
6. Defusing the bomb:
(a) Print a question asking for the code number to defuse the
bomb.
(b) Get an answer from the player.
(c) Check if he got the correct code.
(d) If not, print a message telling him if his guess was higher or
lower than the actual code.
7. Give the player six chances to guess the code. Make a loop that
starts just before 6(a) and finishes just after 6(d). This loop
should give the player six guesses at the code to defuse the
bomb.
8. If the player doesn't guess the code after six tries, print a
message saying that the ship has blown up, and stop the game.
9. If the player guesses the code, print a message telling him so,
print 'WELL DONE', and stop the game.
It may take several tries to get a plan like this. You must practise
the process of converting an idea into very simple steps that you
know the computer will be able to understand. If you are not sure
whether the computer can do something, see if you can split that
thing into even smaller stages.
98 SABOTAGE
Once you have a plan like the one above, the best thing to do is
to try to convert each step into a few lines of BASIC. Try to do this
on paper first. You will find that you are constantly moving around
the program and changing things, and this is much easier on paper
than on the computer itself. You might find it easier to go through
the steps and change them into a mixture of BASIC and English. For
example, you might write
Loop 10 times
(you would put the part of the
program that you want inside the
loop here)
End of·loop
You can convert this into a FOR. .. NEXT loop at a later stage. You
should try to foresee the things that could happen during the game,
and try to cater for them all. For instance you must make sure that,
when there is an input from the player, your program checks that
whatever he typed in is actually allowed by the game and is not
too big or too small.
Here is a listing of a program that will play the game described
above. Each section below corresponds to the step with the same
number in the list above. Each section has been written separately,
so the line numbers are not all in numerical order. This doesn't
matter when you are typing a program into the computer, because
the computer will sort the lines automatically into the right order.
Section 1
Explanation
line 10 sets up the random number generator and clears the
screen. This is the same as in all the other programs in this book,
SABOTAGE 99
Section 2
60 PRINT 'WHI CH SECTI ON TO LO OK IN (1- 8)'
70 INPUT S
80 IF S( 1 OR S>N THEN GOTO 70
9 0 I F S=P THEN GOT O 200
Explanation
Line 60 asks the player which section he wants to look in.
Line 70 gets his answer and puts it in S.
Line 80 checks if the number that he typed in is allowed. If it is
less than 1, or more than the total number of sections in the
spaceship, it is not allowed, so the program will go back and ask for
another number.
Line 90 checks if the number that the player typed in is the same
as the random number that the computer chose at the beginning of
the program . If it is, then the player has found the bomb, so the
computer will go to line 200 (see later).
Section 3
50 FOR 1=1 TO 3
100 NEXT
Explanation
Line 50 is the start of the loop giving the player three chances to
find the bomb. It is put just before line 60, which asks the player for
his guess.
100 SABOTAGE
Line 100 is the end of this loop, and will make the computer go
back to line 60 until the player has had three guesses.
Section 4
110 PRINT 'THE SHIP HAS BLOWN UP!'
120 GOTO 4000
Explanation
Line 110 prints a message telling the player that the ship has blown
up; he has had three guesses and has not found the bomb in time.
Line 120 then stops the program by going to line 4000, which
has a STOP or END instruction in it (according to the type of
computer).
Section 5
200 PRINT 'YOU FOUND THE TIME BOMB!'
Explanation
Line 200 prints a message telling the player that he has found the
time bomb.
Section 6
220 PRINT 'GIVE A CODE TO DEFUSE I T II
230 INPUT C1
240 IF C1<1 OR CI >IOO THEN GOrO 230
250 IF CI=C THEN GoTO 400
260 IF C1<C THEN PRINT nTOO LOW n
270 IF CDC THEN PRINT 'TOO HIGH'
Explanation
Line 220 prints a question asking the player for a code to defuse
the bomb.
Line 230 gets an answer from the player and puts it in Cl.
Line 240 makes sure that the answer is allowed - that is,
between 1 and 100. If it is not, the computer will go back to line
230 and ask again.
SABOTAGE 101
Section 7
210 FOR 1;1 TO 6
280 NEXT 1
Explanation
Line 210 is the start of a loop, just before the question asking the
player for a guess at the code. The loop will give the player six
chances to guess the code.
Line 280 is the end of the loop, and will make the computer go
back to line 220 until the player has had six guesses.
Section 8
290 PRINT "YOU TOOK TOO LONG"
300 PRINT "THE SHIP BLEW UP"
310 GoTo 4000
Explanation
Lines 290-300 come after the end of the loop giving the player six
tries at the code. If by that time he has not guessed it, the computer
will print a message to tell the player that he has taken too long
and that the ship blew up.
Line 310 will stop the program. ....
~/I I~"I'
•
102 SABOTAGE
Section 9
400 PRINT "WELL DONE. YOU GUESSED THE CODE"
410 GO TO 4000
Explanation
Line 400 prints a message if the player has guessed the code
correctly (see line 250).
Line 410 stops the program.
The last part of this program is the same as all the other programs
in this book. You do not need to put a section like this at the end of
your program, but it is useful if you want to make the game work
on a different computer from your own.
Dragon
1000 OEF FNR (X)=R NO(X)
1010 RETURN
2000 CLS : RETURN
3000 LET U=INKEY$ ([)
3010 RETURN
4000 END
SABOTAGE 103
VIC
1000 DEF FNR(X)
=INT(RND(I)*X+l)
1010 RETURN
2000 PRINT CHR$(147);
: RETURN
3000 GET U
3010 RETURN
4000 END
ZX·Spectrum
Once you have written the BASIC program, type it into the
computer, and SAVE it to tape or disc straight away. You should
always do this, because you will probably change the program
while you are testing it, and it is useful to have a copy of the
original somewhere. Testing a program is a difficult and lengthy
business.
How you do this testing depends on what sort of program it is.
You should always try to get the computer to execute every section
of the program, and try to make happen all the various things you
have anticipated. For instance, when the program waits for an
input from you, type in numbers or strings that you know are not
!'Uowed. If the program is written properly, the computer should
notice that these are invalid, and should tell you or at least ask for
the input again.
104 SABOTAGE
When the program is complete you are ready to write the
scenario. For Sabotage, it could be something like this:
Someone has sabotaged your spaceship! You are just about to take
off in your commander ship to save the empire, and you only have
time to check three parts of your ship for the hidden time bomb. If
you manage to find the bomb in time, you must use your expertise
to defuse it while your ship is warming up for the flight - but be
quick .. ..
BASIC AND ITS COMMANDS 105
BASIC is the name of the computer language that your machine can
understand. It isn't like English, since you have to write everything
very precisely and carefully. The smallest mistake would probably
make the computer misunderstand you, and do something
unexpected.
When you want to tell the computer to do something, you
usually write a program . A program is a series of simple, logical
steps that you want the computer to follow . Each step is written
using words from the BASIC language, and you store them in the
computer by giving them line numbers at the beginning of each
instruction. Usually you use line numbers that go up in steps of ten,
so that if you decide to put an extra line between two others, you
can give it a line number that goes between the other two. Unless
told otherwise, the computer goes through these lines one by one,
starting at the first and working through in order of increasing line
numbers.
To understand the programs in this book, you must remember
that the computer is VERY stupid. In fact, it is so stupid that it
needed a very good programmer to make it understand BASIC in
the first place. So we have to ask it to do lots of simple things
which, when put together, make it do what we want.
First, you must know how the computer remembers things. You
use the word LET Isee glossary) to tell it to put something into its
memory. The place that holds this 'thing' is like a box. You give the
box a name, and the computer will use that box whenever you use
its name in a program. If the box holds a number it is called a
'numeric variable', and is given a single·letter name such as B.
Some computers allow more complicated names, such as B1 or
even Box. If the box holds a string of letters, digits or any other
characters it is called a 'string variable'. As before it is given a
name, followed by a dollar sign - hence N$ or P1 $, for example.
So
LET g-12
puts the number 12 into the numeric variable Q, whereas
LET N'-"DANIEL"
106 BASIC AND ITS COMMANDS
puts the word DANIEL into the string variable N$. Notice that when
you use string variables, the string itself has quotation marks
before and after it.
You can also use LET to do maths on numbers and other
variables. For example,
LET W-Q+S
will make the computer fetch the number stored in the variable Q,
add five to it, and save the result in variable W. As well as +, you
can use - for subtraction, * for multiplication, / for division and /I
for powers of a number. You can also use + with string variables.
'Adding' two strings means putting the second one on to the end of
the first. For example:
LET A.="HELLO'
LET 8.-' THERE'
LET C.-A'+9$
would make ($ hold the words HELLO THERE.
Doing things like this with variables is only useful if you can ask
the computer to show you the results on the screen. The PRINT
command is used for thiS, and can do two things. It can display
messages on the screen, for example:
PRINT "HELLO THERE"
and it can be used to show you what numbers or strings are stored
in variables, for example:
PRINT A
PRINT N.
You can combine these by putting more than one item in a PRINT
command. To do this, you separate each item with a semicolon or
comma. Usually a semicolon will display the items with no spaces
between them, while a comma will space the items neatly across
the screen.
BASIC AND ITS COMMANDS 107
Dragon
The simple command to make a sound is
SOUND P,D
where P and 0 are numbers or numeric variables that tell the
computer what note you want to play, and for how long,
respectively. P can be between 1 and 255; a value of 89 will cause
the computer to play the note middle C. 0 can also be between 1
and 255: each unit is 1/ 16th of a second, so that a value of 8 will
make the note last for half a second.
You can combine lots of SOUND commands to make more
interesting noises. The best way to do this is to put them in a loop,
and use the loop variable to change the note or the length of the
note or even both. For example:
10 FOR 1-20 TO 50
20 SOUND 1,1
30 NEXT 1
If you want to send everyone totally mad, try the following:
10 LET P-RND(255)
20 LET O-RND(4)
30 SOUND P,O
40 GOTO 10
The Dragon also has a more sophisticated way of playing music.
The PLAY command lets you use note names instead of numbers,
and has several powerful features. If you are interested, read about
this command in the Dragon manual.
108 BASIC AND ITS COMMANDS
zx-Spectrum
The ZX-Spectrum has a command BEEP, which produces a
particular note for a chosen length of time:
BEEP D,P
You must use numbers or numeric variables for 0 and P. 0 is the
length of the note, and each unit is one second. P is a number that
gives you a particular note, and each unit is one semitone above
middle C. (It can be negative. Thus 3 gives three semitones above,
and - lone semitone below, middle C) Experiment with different
BEEP instructions to see what it can do. For example:
BEEP 1,12
BEEP 0.5,-2
You can put the BEEP command into a loop to make more
interesting sounds:
10 FDR 1-0 TO 24
20 BEEP 0.05,1
30 NEXT I
or
10 FOR lei TO 25
20 BEEP 1/500,12
30 BEEP 1/500,19
40 NEXT I
BBC
The BBC computer has a very complicated system of producing
sounds. In fact, you can have three notes all playing at once.
together with 'white noise', which can sound a bit like a gun shot or
explosion. The Simplest way of making a noise is:
SOUND C,E,P,D
You must give a channel number in C. This tells the computer which
of the four channels (three notes plus noise) to use. It can be either
o (for noise) or 1 to 3 (for notes). E should be a minus number,
BASIC AND' ITS COMMANDS 109
which tells the computer how loud to play the note. The quietest is
·1 and the loudest is ·15. P is the pitch, and must be between 0 and
255. This chooses which note to play. Finally, D is the length of the
note, and must be between 1 and 255 . Each unit of length is
1/2Oth of a second, so that D = 20 will give a note one second
long. Try the following examples:
SOUND 1,-10,100,20
SOUND 2,-10,40,10
SOUND 3,-15,150,40
SOUND 0,-10,5,20
For the more complicated types of sound, read your manual about
the SOUND and the ENVELOPE commands.
Electron
The Electron uses exactly the same command to produce sounds
as the SBC, but it can only play one note at a time. Therefore, you
should always put the channel number as 1:
80UND 1,-I~,IOO,20
SOUND 1,-10,40,10
SOUND 1,-15,200,25
V1C
The VIC computer does not have simple instructions to make
sounds. However, using the POKE instruction you can produce
three channels of notes and create noise, and you can set the
volume of the sounds. The instructions to use are:
POKE 36878, X to set the volume (0 to 15)
POKE 36874,X to set note 1 (128 to 255)
POKE 3687~, X to set note 2 (128 to 255)
POKE 36876, X to set note 3 (128 to 255)
POKE 36877, X to set 'noise' (128 to 255)
110 BASIC AND ITS COMMANDS
Try the following example of making more complicated sounds on
the VIC:
10 POKE 36877,220
20 FOR LoiS TO 0 STEP -I
30 POKE 36878,L
40 FOR 10 1 TO 100 I NEXT
50 NEXT L
60 POKE 36877,0
70 POKE 36878,0
ZX-Spectrum
To change the colour of text being printed, use the INK command;
for instance:
INK 2
gives red text. To change the background colour, use PAPER; for
instance:
PAPER 5
gives a pale blue, or cyan, background colour.
number of different colours you can see on the screen at once, and
also the number of characters across the screen.
The following examples will work on both the BBC and the Electron.
We will use mode 5, which gives you four colours and twenty
characters on a line. First, type in the instruction:
"ODE 5
Then try the following examples:
COLOUR 1
give red text. The other colours, yellow and white can be used by
giving the numbers 2 and 3 respectively in the COLOUR instruction.
COLOUR 131
give a white background to the text. The background number is
obtained by adding 128 to its foreground number, so that 129 and
130 give red and yellow backgrounds respectively.
Dragon
The Dragon cannot easily produce text of different colours,
although it can draW' pictures using its colour graphics. If you wish
to try the Dragon's graphics commands, then look them up in your
computer manual.
VIC
The easiest way to get colour on the VIC, is to use the keys on the
keyboard marked with the various colours. Pressing Control along
with a number key will make the computer display text in that
colour from then on. Thus:
PRINT 'tHELLO THERE'
where the # sign signifies you pressing Control-3, will make the
message appear in red. You can put these control characters
anywhere in your text. You can use control-9 and control-o to
get reverse characters.
112 GLOSSARY
This glossary gives explanations and examples of most of the
common instructions that make up the BASIC language. You can
use it to check against the games in this book and to find out more
about how they work. In some cases different words are used for
the same function on different machines, in which case the
alternatives are given.
There is a separate section for BASIC functions, which are not
instructions in their own right.
In each section the words are listed in alphabetical order.
BASIC instructions
CLS is a simple command that clears the screen of all the
computers except VIC. On VIC you must use:
PRINT CHR$( (47);
DATA is used with the READ command. It tells the computer that
the following numbers or strings are just pieces of data that will at
some point be READ by the program. You can put more than one
item on a DATA statement, by separating each one with commas.
Examples
DATA 'JAN',30,'FES',28,'MAR',31
DATA 'ONE'f"TWO',"THREE'
DATA 9.8,3.2,77.99
DEF FN .. . is used to define your own mathematical instructions or
functions . You will probably have noticed that in most of the
programs in this book there is a line that looks like:
1000 DEF FNR(X)·RND(X)
or
1000 DEF FNR(X)·INT(RND(l)fX+I)
or
1000 DEF FNR(X)=INT(RNDfX+I)
depending on which computer you are using. The right-hand side of
this, after the equals sign, is the normal expression for working out
GLOSSARY 113
random numbers, but what about the left-hand side? This is called
a function definition, and it lets you make up your own
mathematical instructions and give them names. Once you have
done this, you can use them throughout the program, using the
name FNv where v is any normal variable name. The letter X inside
the brackets on the left-hand side is not a real variable, but a way of
telling the computer what to do with what it finds inside the
brackets when you actually use the function. In the above case,
typing
PRINT FNR(lO)
will display a random number between 1 and 10. On some
computers, this would save typing
PRINT INT(RND(I)*lO+I)
every time you wanted a random number.
Examples
DEF FNV!XI.X*1.15 (A function to add
VAT to the number)
DEF FNS(XI-SIN!X1180*3,1411
DIM tells the computer to reserve memory for a special type of
variable called an array. These variables are really like a lot of
boxes in a row; each box can itself hold a number or string_So, you
get a lot of places in memory to store numbers, but all the places
have the same name. To tell them apart you must put a number in
brackets to tell the computer which box you want to look at. You
must also decide beforehand the total number of boxes that you
want. You put this number in brackets in the DIM statement.
DIM A(251
makes an array called A, with twenty-five boxes to put separate
numbers in_ A(1) is the first, and you could use it like this:
LET A(I)=1999
A(2) is the next, and could hold something else:
LET A(21=2001
114 GLOSSARY
You could use aU the boxes, or elements, in A to store different
numbers, aU the way up to A(25)
You can use a loop to print out aU the boxes in an array (see the
entry under FOR). To do this, you should put the loop control
variable inside the brackets after the array name, so that each time
the loop is repeated, the next box will be printed. For example:
FOR 1=1 TO 10
PRINT All)
NEXT I
DIM can be used to create a grid of boxes, instead of a simple row.
This is called a two·dimensional array, and you must give two
numbers inside the bracket in the DIM to specify the array's size.
You must give two numbers to specify the box whenever you wish
to use this array. For example:
LET AI2,4)-5
would store the number 5 in what may be thought of as the second
box in the fourth row of the grid. You can also create an array of
strings instead of numbers, by using a string variable name in the
DIM instruction.
Examples
DIM C(52)
DIM BI8,9)
DIM 8$120,5)
END will tell the computer to finish running the program and wait
for another command, such as RUN. You can put more than one
END command in a program, but too many get very confusing.
The ZJ(-Spectrum uses STOP, not END. See the entry under STOP.
FOR marks the beginning of a set of instructions that you want the
computer to go through a number of times. This repetitive
operation is called a loop, because of the way it goes round and
round. You must use a variable to control the loop, and a beginning
GLOSSARY 115
and end number for this variable. The computer will start with the
beginning number, and add one each time it goes round until it
reaches the end number. Then it will carry on with the rest of the
program. To show the computer where the end of the loop is, you
must put a NEXT command. For instance:
FOR I-I TO 5
the part of the program that you want to loop
round goes here
NEXT [
This loop is controlled by the variable I. It starts at one and
increases by one until it reaches five, so the instructions within it
will be repeated five times. You can change the amount that the
loop control variable increases each time by putting the word STEP
into the FOR instruction. Put the number that you want to increase
each time after STEP.
Examples
FOR J=IO TO 20
FOR Kal TO 10 STEP 2
FOR FOR
NEXT FOR
loop
FOR
NEXT
NEXT
NEXT
The latter is called 'nesting'.
,,6 GLOSSARY
Note that the control variables must be carefully specified. Each
of your loops will usually use a different control variable name.
AND is used if you want to decide if both one thing AND the other
are true
OR is used if you want to decide if one thing OR the other OR both
are true.
If the final decision is that the condition is true, the computer will
then go on to the instructions following the word THEN. On the
other hand, if the condition was false, it will simply go on to the
next line of the program .
Examples
INPUT is used to get answers from the person using the computer.
It is a bit like a LET command, except that it obtains the value to
put into the variable from you instead of from the program. You
can INPUT values for numeric or string variables, according to the
type of the variable you use. For instance:
10 INPUT Z
118 GLOSSARY
will expect you to type in a number, which will be stored in variable
z. You must always press the ENTER or RETURN key so that the
computer knows that you have finished typing in the answer and it
can carry on with the program.
Examples
INPUT Z
INPUT Q$
LET Q-4S
LET 61=10
LET R2(Z+L)/(4+P)
LET X-SIN(f)
LET W$-'HELLO'
LET S$'"THE "+C$
NEXT is the command used with FOR (see entry FOR). It tells the
computer where the end of the loop is. Each time the computer
comes across a NEXT statement (followed by the name of the loop
control variable. e.g. NEXT I) it increases the loop variable by one
and jumps back to the line with the FOR command in it. unless it
has reached the tenminating number.
Examples
NEXT W
NEXT
The second of these examples is NEXT without the control variable.
Provided that the program has the same number of FORs and
NEXTs, and that these are placed correctly, the computer will know
which FOR to return to. The omission of the control variable is not
allowed on the ZX ·Spectrum.
PRINT 1
PRINT 'HELLO THERE 'IN.
PRINT FtV,G/2
RANDOMIZE is used to get around a problem with random
numbers generated by the computer. You may notice that the
computer always gives you the same random numbers just after
switching it on. To stop this happening, use the following
commands, right at the beginning of your program :
10 RANDOMIlE for the BBC and Electron
10 RANDOM for the ZX·Spectrum
10 LET R-RND(-TI) for the VIC
10 LET R-RND(-TIMER) for the Dragon
These make sure the random numbers start off completely
randomly.
READ is used to copy DATA you may have stored in the program
into chosen variables. It behaves like INPUT, but instead of stopping
and asking the person using the computer for something, it gets
that something from the list of items that you should have put into
the program beforehand. These items are put in DATA statements.
Each time you execute a READ command, the next item (starting
with the first item when you run the program) is read into the
variable whose name you give. If you give a numeric variable it will
GLOSSARY 121
expect to read a number from the DATA statements, and if you give
a string variable it will expect to find a string in quotes. These
commands are useful if you want to have a lot of data in a program
which is unchanging - for instance, the names of the months and
how many days each one has.
Examples
READ P
READ H$,A,8
RE11IRN tells the computer that it has reached the end of a
subroutine, and that it should return to the program line that the
subroutine was called from . It will then continue with the next
instruction after GOSUB.
BASIC functions
Now we come on to various 'functions' that BASIC understands.
These can be used together with variables in LET and IF ... THEN
commands. Most of them produce a result depending on
something in brackets. For the functions that are not described,
look up what they do in your computer manual.
ABS ignores any minus sign in front of a number, and always gives
you the absolute value. For example:
ABS(42) gives the answer 42, and
ABS(-42) also gives 42
122 GLOSSARY
CHR$ converts numbers into single letters or other characters. It
uses a special computer code called ASCII, in which each number
(normally between 1 and 127) corresponds to a particular letter.
For example, the letter A has a code number of 65, so that
PRINT CHR$(65)
would print out an A.
Examples
CHR$(147l
CHR$(64+I)
SIN. COS. TAN. ATN are all maths functions that you can use in
your programs. Remember that the computer normally works in
Radians. not Degrees.
Examples:
SIN(3.142)
COS(A)
TAN<T/2)
ATN (F+U
SQR is a useful function that gives you the square root of a number.
Examples:
SQR(16)
(would give the answer 4)
SQR(T*2)
j
124 GLOSSARY
Examples:
VAL (. 4~') (would give the number 45)
VAl( N$)
LOAD is used to recall programs from tape or disc back into the
computer. The Dragon uses CLOAD to load programs from tape.
Look up this command in your computer manual to find out how
to use it.
RUN tells the computer to start running the program in its memory.
It will always start at the very first line of the program. Before
running the program , the computer clears any variables that have
been used previously, so that it's memory does not become full up_
GLOSSARY 125
SAVE is used to store your programs onto tape or disc. The Dragon
uses CSAVE to save programs onto tape. Look up this command in
your computer manual to find out how to give the programs
names on the tape or disc.
126 APPENDIX
Here is a list of some of the ASCII' codes. Each character has a
Hexadecimal or Decimal number next to it, which is its
corresponding code:
sp 20 32
21 33 > 3E 62
22 34 ? 3F 63
£ 23 35 @ 40 64
$ 24 36 A 41 65
Yo 25 37 8 42 66
~ 26 38 C 43 67
27 39 D 44 68
28 40 E 45 69
29 41 F 46 70
• 2A 42 G 47 71
+ 28 43 H 48 72
2C 44 I 49 73
2D 45 J 4A 74
I 2F 47 L 4C 76
0 30 48 M 4D 77
31 49 N 4E 78
2 32 50 a 4F 79
3 33 51 P 50 80
4 34 52 Q 51 81
5 35 53 R 52 82
6 36 54 5 53 83
7 37 55 T 54 84
B 38 56 U 55 85
9 39 57 V 56 86
3A 58 W 57 87
; 38 59 X 58 88
< 3C 60 V 59 89
= 3D 61 Z 5A 90
*ASC11 stands for American Standard Code tor Information Interchange. Most
computers use this code to represent the various different letters, numbers, and
symbols used by the computer.
l
SOFIWARE ORDER FORM
computer Games
The programs listed in this book are available on cassette direct
from the publisher.
There is a cassette available for each machine, price £4.95 (plus
£1 .00 postage and packing). The cassettes are only available on a
cash·with·order basis.
Fill in the form below, making sure you state clearly which machine
you have. Send the completed form with your cheque or postal
order to:
Sparrow Software
Hutchinson House
17·21 Conway Street
London W1 P 6JD
Please send me one cassette at £4.95 (plus £1.00 p+p) for the
following machine:
zx ·Spectrum
D Electron
D J
VIC
D Dragon
D
BBC
D (tick box where applicable)
Name
Address
postcode
ISBN 0-09-933330-9
Children 's
Non-fiction
U.K. £1 .50