Download "user manual"

Transcript
FIrst published in
Great BritaIn In J984 by
'Franklin Watts
12a Golden Square
London WI
First published In"the
United States In J984 by
Gloucester Press
Copynght © Aladdin Books Ltd 1984
Printed In Belgium
ISBN 0-531 -0348~6
Library of Congress Catalog
Card Number 84-81108
WRITE YOUR OWN PROGRAM_-
ANGMAN
Mike Duck
~~Oy~~~~6~oRNPTRoESS
·1 9 8 4 - - - - -
One of the most exciting things about computers is the
ics effects they can display on your TV screen. Most
ready-bought games programs allow you to control what's
happening on the screen, whether It's movmg a spaceshIp to
aVOId ailen attack or steermg a racing car around a
dangerous Grand Prix track The programs that produce
these effects are very complicated, but you can use sImple
graphics commands to create an mteresting and satisfying
computer game of your own
The program given m this book builds up the Hangman
game. In thIS game, the computer chooses a mystery word
and asks the player to guess what It IS, letter by letter. You
have only ten guesses, and for each wrong guess the
computer builds up a section of the Hangman graphics.
The program is broken down mto a number of logical
stages, so that you can clearly understand what each sectIon
does. Givmg programs a logIcal step-by-step structure not
only makes them easier to write, it also helps other people to
see how they work when they come to use them at a later date,
The first sectIon of the book deals with the mam program
which controls how the game works. A second section
explams the graphics that w1l1 make up the screen display
Contents
8
Introducing Graphics
Color
Better programming
10
1 THE MAIN PROGRAM
11
APPLE IIe
COMMODORE 64
2 THE GRAPHICS
12
APPLE IIe
COMMODORE 64
Program listing
Glossary
Index
9
19
27
28
34
40
42
44
,
Introducing graphics
The graphics commands used in the BASIC computer
language vary considerably from one model of computer to
another. Graphics are positioned on the TV screen by
plotting them in the same way that you can plot positions
on graph paper. The graphic commands in the Apple are
followed by two figures which give the horizontal coordinate
(the x coordinate) first, followed by the vertical coordinate
(the y coordina te). Commodore 64 can also position graphics
on the screen as a series of PRINT statements. Type in the
graphics commands below and then RUN them to see the
result.
APPLE IIe
o
o
<:)
7:510
7520
7!:';30
754 0
7550
7560
7570
HCUL.ClF(:::3: FTlR I .HPLOT 1,49 TO 1,30
,~'?~.;;
o
TO 24:=;
o
NEXT 1
HCClLClR == (I
HPL.OT 230,45 TO 240,45
HF'L. OT ~2 2t1 ,34 TCl :;'30, :~; 11· :
HPLDT 234,38 TO 236,38
"~? 'I'<@':'1fitdPM'#\"¢:¥P4'1!i1"'''ti«¥<,
'' 'iV .,
HPL.DT :::' 40, :::'4 TO 24 '2,
:~A
o
~-._-------.. ,;--..,--------;-----.--~-,{"f"'=,
' !:
COMMODORE 64
f'--J
o
~
? 5 1 0 F' PItH " !=i~r.~l~rI!lWI."i~"
o
I" . t~E;:<T
o
,
Color
To obtain colors, a number of dIfferent commands are used.
In HGR mode of the Apple, colored graphics are produced
usmg the HeOLOR command followed by a figure from 0 to
7. The exact color depends on the TV and its adjustment.
The background color IS black. On the Commodore 64 both
graphics and text are colored by the CTRL or C= key held
down with the appropriate number key from 1-8. Each color
control will display a unique graphic code which will not be
visible when the program is RUN. The background color is
blue. Tryout the commands given below, and experiment
with the figures using the values given in the chart.
N.B. Colors on the Apple lie may
vary from those given below
depending on T.V . used.
Commodore 64 keys used with the Commodore logo key
appear with a stroke above them in the text. Thus the
Commodore logo shifted E is printed as E.
Commodore control codes
rl = CLEAR SCREEN
I) = CURSOR RIGHT
I§I = HOME CURSOR
II
= CURSOR LEFT
61 = CURSOR DOWN
m
[ ] = CURSOR UP
!!!!!! = REVERSE OFF
= REVERSE ON
COLORS
APPLE lie
HCOLORO
HCOLOR4
OTHER
COMMODORE
COMMODORE COLORS
ORANGE
~
1
BROWN
~
2
000
LIGHT RED
~
3
000
DARK
GRAY
MEDIUM
GRAY
LIGHT
GREEN
LIGHT
BLUE
LIGHT
GRAY
~
4
~
5
~
6
~
7
~
8
000
CTRL1
CTRL4
000
000
000
[100
CTRL8
HCOLOR3
HCOLOR7
CTRL2
9
Better programming
The fust stage of writing any program is to break down the
task whIch the computer IS to perform mto its logical steps.
Each of these steps can be made mto a separate stage wlthm
the program, called a subroutine in the Applesoft BAS[C
used on the Apple computer and in Commodore 64 BASIC.
The mam program for the game wJlI call up and execute
each of these subroutmes as they are reqUIred One of the
maln advantages of writing programs in this way is that it
shows exactly how the program works, and it also means that
you can use the same subroutme more than once in the
program. In fact, m the program in this book, the graphICS
that are aVailable from the graphics section are used in thIs
way to gIve an attractive title display and separate displays
when the game is won or lost. Usmg subroutmes also means
that the mam program IS much simpler. In fact, the main
program which places the subroutines m their logical order
takes up less than twelve lines of program.
THE
MAIN PROGRAM
In this section, the separate subroutines which describe the Hangman game are
explained. First, the main program is given, with each stage of the program
placed in its logical order. The sections of program that follow set up the title
screen and then ask the computer to choose a word at random from the list given
it. The player is then asked to guess letters, and these guesses are compared
with those in the mystery word.
Let t et"'S
Chosen
The Co (l'\p ute ..... ,;
wor'd
S
IS
•• -*****
Please choose a
11
letter
"e
~~~-----------------------------------------------,
9.Q.
~
The breakdown for the Hangman game shown on the
previous page almost gives the main program. By changing
each step into a subroutine, and by placing those
subroutines into their logical order, you can arrive at the
main program for the game, as shown below. Once you
obtain a main program like this, all that remains is to write
each subroutine in turn.
HUI"1E
Bosun 1000: REM
GELECTWORD
Bosun 2 000: REM TITLE
IF WO - 1 OR LO = 1 THEN 80
5 ()
BO GUB 3 0 00 : REM CHOO SELETT ER
60
IF CO
0 TH EN GOs un 7000: REM
70
buro i lO
80
IF WO = 1 THEN Bo s un 400 0: RE M
90
IF LO = 1 THEN BOSUS 500 0 : REM
100 BO S US 6000: REM PLA Y AGAIN
1 ':)
o
o
o
o
11 0
Hem:
l;J I I'J
L_C) ~3 F~
~; TUF
The first stage of the program is to introduce a subroutine
which allows the computer to choose the mystery word. It
will do this from DATA stored at the end of the program.
Once the computer has run through this subroutine it Will
return to the mam program to the next one - m thIS case the
titles subroutme. This subroutine gives the initial title
display. Lmes 40 to 70 form a loop which is repeated until the
condition in lme 40 is met - that is, until the game is WOn or
LOst. Line 60 tells the computer to go the hangman
subroutine when a wrong guess is made during the
chooseletter subroutine. In line 80 the program is sent to the
win subroutine, if the g ame is won. Line 90 of the
program goe s to the losing display. Line 100 calls up
the subroutine which asks if the player wants another game ,
and at line 110 the main program ends.
The subroutines are written separately. It is a good idea to
check each section to see if it works. Before doing thIS,
it IS necessary to include the DATA statements at the end
of the program. Because the computer automatically puts
line numbers into sequence, they can be added at this p oint.
You can have as many words as you like, but at this stage it's
better to limit them to eight and add extras when you've
finished the program.
o
C.7000
9010
DATA
DATA
APPLE,ANGLE,ALPHABET,ASTEROID
BOTTLE,BOOK,BUFFALO,BEACH
12
o
,e
RV<V'~--------------------------------------------------~
~
o
o
o
I
1000
10 1 0
1020
F<E:t'1
L.E~T
hE:l.. FCf I;JUI;:D
I,J "
U
1:;:r:::3TUF:E
10~:O
LET CH =
lOq·(l
1U50
1.0bO
1070
10BC>
FUh: L. 0.-=
RF(cID l,j$
N f:~)(T L.
L.ET L.E:
F:ETUF<I\I
INT ( RND (1)
l
fU
LEN
*
W)
+
1
C li
(W$):
L.ET 0$ = W$
The first subroutine selects the word to be guessed. All
subrou tines are first defined as in j ne 1000 - REM SELECT
WORD. In line 10 10, the value of W is set to the number of
words stored in the DATA. RESTORE mline 1020 tells the
computer to begin at the flrst word in the DATA each time
the subroutIne is run. W ithout it, the computer would begin
reading where It stopped last time. Line 1030 selects a
random number between one and the number of words
stored in the DATA. The computer will run through the DATA
to thlS point, using a FOR. .. . . .NEXT loop with L as its loop
variable. If the random number generated is four, then the
computer will read through to the fourth word. This word is
then held in the stnng variable W$ and is the mystery word.
Line 1070 defines the length of the word as the length of the
word string (LEN counts the number of char acters held in a
string) ; and also stores the word selected in the vanable
dummy D$. The LEngth is used to display the number of
letters to be guessed, and D$ is used to display the mystery
word if the player fails to guess it. RETURN directs the
computer back to the main program.
TO TEST SUBROUTINE
SELECTWOItO
Q) APP LINE :
lOTS PRINT W$
b) TYPE HOME
PRESS RETURN
c) TYPE GOSUB 1000
PRESS RETURN 0
DELETE LINE 1075
BEFORE PROCEEPING
TO THE NEXT SECTION.
0
13
The next subroutine calls up the title screen. This uses some
of the graphlcs created later in the hangman subroutine.
These graphics appear on the right-hand side of the screen,
so this should be kept in mind when placing text instructions
on the screen.
279
Oy
~L--------------------
o
o
o
::000
:':;01 ()
2()~?()
R E lvl
TITLE
H(3R : HCJl'lE
FIJF, L. ~, 4 TU
:?O::!;O
ON L -
:::: 040
l\jr:~
:. :O~50
2060
o
10
4 BOSUS 7500,7600, 77 00,7800, 7 900,8000
X T L.
VTAFI 2 j :
'vlTAB 2 :::;:
1·IT?iB
HTAB
j 4:
1 (>:
PF< I I'~T
I NF'UT
"H (\ N
II
PRE ~:; ~:,
, A :$:
The titles sequence has two parts: firstly to give the initial
screen, secondly to give the screen for the beginning of the
game. The section above achieves the first task. Line 20 10
selects HGR and HOME clears the screen. Lines 2020 to 2040
sends the program to the appropriate section of the
hangman subroutine. This wlll become clearer when you
come to that section of the program. In brief, the hangman
image is built up in ten stages. For the title screen only, the
graphics created by stages four to ten are used. Line 2050
positions the word "HANGMAN" on row 21 beginning at the
fourteenth column across. The player is then instructed to
press the RETURN key to start
14
[3
()
1'1 A 1\1"
F~FTLJI~N
TO
~:;Tr:~F-n
II
o
,',
0
",
0
';:'() "7()
..... -
I
..
2090
7: 100
. ~:"l 1 ()
O~
.. ..
2120
21.30
02150
2160
HOI"''':: : /-1(3[-:;; : \jH1H 24: HT(iH 1: F'F;: I NT "L. t:rrEF:!3
CHO!:'';E:I\J: " ;
\,JTr~B
' -:'".1"
HTPIU :?H: [-='/::;; 1 NT II CUr/IF'UlEr< '!3 II
\,JT ?'IF<~':: ::; :: HT {iF< ::::0: F' I:~: I 1\1 T II lfJURD I !::l II
'viTr~)B;:4:
HTPIU ~:.o
F(lh: L. :: 1 TCl I.E:: F'F( I NT "it-":;: NEXT L.
\,iTPIH ~21: HT(\IB 1:: P/:;:l/ '~T "F'L.F(\~)F: CHDfJUE (\ LETT[R "
LET WO = 0: LET LO = 0: LET 1.1 = 0: L.ET Be - 0
F:::C::TIJRN
Lines 2070 to 2160 complete the title subroutine, The
consIderations to take into account are to display the number
of letters in the mystery word and to show the letters that the
player has guessed, The text "LETTERS CHOSEN" and
"COMPUTER'S WORD IS" are displayed at the bottom of the
screen in the text area (lines 21-24). Applesoft graphics
leaves four lines for text on each graphics screen. The
instructIOn "PLEASE CHOOSE A LETTER" is dlSplayed on
line 21 starting in column one.
At Ime 2120, an asterisk is printed for every letter in the
selected word. This is done using FOR. , , , , ,NEXT loop with
L as its loop variable, with values ranging from 1 to the value
for length obtained in LE earlier, Fmally, line 2150 sets
the initIal values for the other vanables used in the game at
zero. SC will be used to deCIde whether or not the game is
won. L1 checks that the player hasn't used up ten guesses
and builds up separate sections of the hangman graphICS for
each incorrect guess, And the values of WOn and LOst are
set at zero (that IS, the game has been neither won nor lost)
70 TEST SUBROUTINE TITLE
Q) ADO A REM TO THE START OF LINE :2030
b) ADO l..INS " 211S LE= 8
c) TYPE HG/t: GO$UB 2DDO
d) PRESS RETURN ~
{)ELETE THE ADDITIONS BEFORE PROCEE()ING TO NEXT SECT/ON,
15
~e
~~~-------------------------------------------------.
~q,
~
The nex t subroutme really does all the work m the program i
It allows the player to choose a letter and checks to see if
that letter is part of the mystery word. According to whether
the guess IS right or wrong It makes the appropriate changes
to the values of SC, and checks to see if the player has won.
As you might expect, it's also the most difficult section of
program.
Once again, the subroutine is defined. Line 3020 asks for a
letter to be INPUT, to be labelled as C$ by the computer. A
question mark will appear on the screen to prompt the
player, followed by a flashing cursor. Line 3030 prints the
letter chosen on the 24th row down the screen in the
seventeenth column following the words "LETTERS
CHOSEN:" at a position determined by the value of the
vanable LI. In fact all this means is that when the value of LI
is 1 then the letter will be printed m the seventeenth column,
and when life becomes two (on the second mcorrect guess)
then the letter chosen will be in the eighteenth column and
so on for the ten guesses allowed in the game. At lme 3040
the variable CO is set at zero so that the program goes to the
hangman subroutme if a valid letter is not chosen. (Look
back at line 60 of the main program to see why.)
()
~; ooo
:'01
(j
o
302 0
:::: 030
o
:;040
5U50
I NF·I.JT C t :
o
o
o
IF
L.EN
(Cl)
::
lfHEN
:~; o
10
VTAS 2 4: HTAR LI + 16: PRINT [$;
L_ET eLl :::: 0
f~- (] f;: j=' ::::
1 T iJ L.. I::
I F Ct
1'1 I D: i:~ ( vJ :*: , P , 1) T HF I'~ ~:':I. (> 0
LE T vJ J :.f
" ": l...E T vL::: :;t:: =:: " "
> 1 THEN Wlt
IF P
:::06h
o
REM CHOOSE LETTER
\/TPIB :,: 1 ~ HT(iD :::4
=
P THEN W2$ =
IF LE
LET CO
:I.~
:::'08U
L.ET
I~J:I.
3090
VTAB 2 4: HTA8 P
W:')::
LEFTt (Wt,P - l )
RIGHT$ (wt,LE - P)
LET Be = Be + :I.
J:
+
" ":) "
~
+29:
vr!,~
PRINT
[$;
~:::
1 OU
3 110
IF LE
:~ i. 2 0
r":;:FTI.JRI'·J
= Be THEN
LET WO =
:I.
Lines 3050 to 3100 make a FOR. .... .NEXT loop which
compares the letter INPUT with each letter in the mystery
word in turn. For example, suppose that the mystery word is
BOOK and the letter guessed K. MID$ IS used to copy part of
a string. For the first value of P it would be the first letter, B.
Since B is not equal to K, the computer runs through for the
next value of Position, until P equals 4.
16
o
o
o
o
o
o
- - - - - - - - - : , - - - - --
- - -- ----------- -- ----
-
~e
~~,~------------------~~----------------------~
R
~
At this pOint, the value of MID$ will be K Since thIs is equal
to the INPUT, the computer goes to line 3062, where the
mystery word is changed. Applesoft will not allow LEFT$ or
RIGHT$ to be zero as it will ifPO= lor PO=LE. To avoid this
line 3062 sets up temporary string variables Wl$ and W2$.
The amount of the string copied again depends on the values
of P and LE in brackets, In this example, line 3070 would
change BOOK to BOO?, This makes sure that the player will
lose a life if he or she guesses the same letter a second
time, This is also why the original W$ has to be stored as D$
in line 1070 in the select word subroutine. Finally, the value of
CO is changed to 1 and SC is increased. In line 3090 the valid
letter is printed on the screen overprinting an asterisk. Line
3110 checks if the value of SC is the same as the length of the
word, in which case WO is given the value of 1 and the game
IS won.
IN ORf)ER TO TEST
S UBROU TINE CH(,}OSELE
IT MUST 13£ RUN WITH THE
R EST OF THE PROGRAM .
a) AD!) RENt AT THE 5TART
OF LINE 60 AND LINE 2030
b) T YPE RUN PRESS
RET UR N
D EL E TE THE ADf)ITIONS
ABOVE WHeN YOU ARE
R EADY TO PROCEED.
0
The next subroutine, Win is much simpler. It clears the
screen and line 4030 calls up part of the hangman graphics,
The congratulatory message is printed at the bottom
0
()
4000
F<EI"I
4010
HClMI:::: :
4020
Fm~
"+0-:::;0
ClN L NE XT L
0
4040
0
4060
4070
4050
()
I)J 11\1
HCif<
L,:: 4
TCI 10
4 BOSUn 7500 , 7 600, 77 00,7800,7900,8000
\,,'T {-)B 21: HT ('lB 1: F'li 1 r\IT "I)JEI...,I..., DUf\JE,
E::< ECUT I (]f\J"
F'F< 11\IT "H{i~; BFT'" POSTF'ONED"
F,ETUF,I\I
"""
17
YD UF<
o
()
o
,''II
N~r--------------------------------------------------r
~~
~
5UOO
05010
5020
()
~;O ::'O
1::;:[1'1
HUI"1E
~
FUI:;: 1_
l_lJ::-;[
HL::if;:
'co
1 TU 10
ON L BOGUE< 7100,7200,7300,7400.7500,7600, 7 700,
7f:300, 7900, 1:l000
() 5040
NEXT L
~5070
\')T ('~B? 1: HT r~B 1::
F'R I NT "YUU UJ:::;T I
pr~ II\1T " THE [,JDHD
~50UO
H[TUr~I'"
=.;()~jC)
5060
F'r;: J I\j T
" 1< 1\1 P, tv' I
~31'1
F:(](JI ....
I
o
o
"
"
~~PI H
c
"; Dt
The subroutine for losing the game, comes mto play after
value of LO is set at I - this actually happens in the
hangman subroutine later on. Again, the graphics which will
be produced during the hangman subroutine are called up
to give a good display. NotIce that line 5070 also pnnts the
original word selected at random by the computer, which
was stored as D$ in the selectword subroutme,
The final subroutine in this section of the book enables the
player to play again. Line 6040 allows the "Y" key to be
pressed. If the computer does not receive this INPUT the
program runs through to line 6050, the screen will clear and
the "BYE BYE" message will be displayed.
The program is now complete apart from the graphics
sectIon which is contained in the hangman subroutIne, This
is treated separately in the second section of the book. For
those users without a disk drive at this point it is a good idea
to save this section of program on tape, Connect the tape
recorder up as instructed by the manual. Then type SAVE
and press the play and record buttons, Then press RETURN,
Make the recordings at different points on the tape, just in
case the first recording doesn't work, as sometImes happens
with programs stored on tape, Keep a note of the positIons
on the tape using the counter on your tape recorder,
o
hOOO
r;:EI'j
bOlO
VTP,D
l=tJCtY nC;A I N
6040
24:: HT,~H 1:: F'r;:INT
14(3(:\ I I"~ Y / N :'" ;
I I\lF'UT ,'~t.
IF' ,:\:l ::, "Y" THf::I\1 10
h050
HOME: VTAB 21: HTAB 16: PRINT
()
h050
-
18
"DO YflU j,Jlf:;I·ITO
F'L.AY
o
"F)'y' E
BYE"
o
The main program for the Hangman game is very similar to
the breakdown given in the introduction. Each logical step In
the game is made into a subroutine. When the subroutines
are placed In their logical order, and tests are included to
see if the game has been won or lost, the main program is
obtained.
1 (1 F'f': ItH":1"
20 GOSUB 1000 : REM SELECTNORD
0=:0 CiO::;UB 2000 : PEt'l TITLE
40 IF NO=i OR LO=1 THEN 80
50 C~O:::;IJE: 3000: REt'l CHOO:::;ELETTEP
60 IF CO=O THEN GOSUB 7000: REM HANGMAN
o
0·"
o
70 CiOTO 40
IF loJO= 1 THEt·j UO::;IJB 4000: F:Ei'1 ~,j I t·~
90 IF LO=i THEN GOSUB 5000: REM LOSE
100 GU:;UB 60tH,3: F:Hl F'LA'r' ACiA I t·j
11 (j ::;TOF'
:;:::0
Let's look at the main program in more detail. It begins by
going to a subroutine which allows the computer to choose a
word at random from those stored in the DATA at the end of
the program. Next a title screen is displayed at the
beginning of the game. Line 40 tests to see if the game has
been won or lost - this only comes into operation after a
guess has been made. Line 70 returns the program to this
point for another guess to be made. The subroutine called up
in line 50 - chooseletter - allows the player to make a
guess. At line 60, the program goes to the hangman routine
which contains the graphics for the game. The value of CO is
set at zero if an incorrect guess is made in the chooseletter
routine. Finally, there are routines which come into play if
the game is won or lost, and another which asks the player if
he or she wants another game. In eleven lines you have the
complete program for the game. All that remains to do is to
write the routines - and that's when the hard work begins!
Before you begin on these, add in the data statements below,
so that you can test the program at various stages as you type
it in. The computer will choose a word at random from this
list during the course of the game. Of course, you don't have
to use the words given here, but at this stage it's better to
keep the number of words down to eight - you can add extra
when the program is complete.
() 900'.:1 DATA APPLE) AtKiLE) ALPHABET) ASTEF.:O I II
9010 DATA BOTTLE)BOOK)BUFFALO,BEACH
.-.
19
o
o
o
o
PEt1
::;ELECT~JOPD
1005 UD$ ="i:ilf{lf{l!Il~~~t~J:r.Q)nm:r~11!l1!11~1~m~m!ll~1~tlf{~l"
o
o
o
lOH)
~'J=8
1020 F.~ E::; T[I F.: E
1030 CH=INT(RND(0)tW)+1
1040 FOF.: L= 1 TO CH
1050 READI.U
1060 t'~E>::T L
107(1 LE=LEN(WS): D$=WS
RETUF.:t-~
The first subroutine allows the computer to choose a word
from the list stored m the DATA. Line 1010 sets W to the
.number of words in the data list. RESTORE instructs the
computer to READ from the begmmng of the data each time
it selects a word. Line 1030 generates a random number
between one and W. The Commodore 64 generates random
numbers between 0 and 1. so after this has been multiplied
by the number of words in the DATA, it must be made a
whole number usmg the INT command. The 1 is added to
prevent the number ever being zero. The FOR. .....NEXT
loop oflmes 1040 to 1060 gets the computer to READ through
the DATA to the point indicated by the random number. For
example, if the random number generated were four, the
computer would READ through to the fourth word. This word
is held in W$ and is the mystery word. Line 1070 finds the
length of the mystery word and also stores the mystery word
under D$. D$ is used if the game IS lost when the computer
displays the mystery word. Finally, RETURN sends the
computer back to the main program.
GOSUB 1000
ASTEROID
READY
•
TO TEST SUBROUTINE
selectword :
W$
I. TYPE 1075 PRINT
PRESS I RETURN'I eLR
.2. PRESS ISHIFT/ HOME.
3. TYPE GOSUB 1000
PRESS / RE.TURN ,
I
DELETE LINE 1075
WHEN YOU A~E READY
TO PROCEED TO THE
NEXT SECT/ON.
20
title screen. This will use
The nex t sub rou tine calls up the
r In the han gm an
some of the gra phi cs cre ate d late
ear on the ngh t-ha nd side of
subroutine. These gra phi cs app
t in min d whe n dec idin g
the screen, so this should be kep
s.
whe re to pla ce the text instruction
o
39
0
~'"
~
~
I'\,
+
~
:
2.if
ts. The first section, gIv en
The title seq uen ce has two par
en, the sec ond gives the
bel ow, gives the init ial title scre
game. Lin e 2010 clea rs the
scr een for the beg inn ing of the
the pro gra m to the
screen. Lines 2020 to 2040 sen d
ava ilab le in the han gm an
app rop riat e sec tion of gra phi cs
s will be exp lain ed late r in
subroutine, stages four to ten. Thi
f, the hangman ima ge is
that sec tion of the pro gra m. In bne
h wro ng guess or "life" lost.
bui lt up in ten stages, one for eac
the Word "HA NG MA N" ten
The PRINT com ma nd positions
ing at the twe lfth colu mn
row s dow n the screen, beg inn
ted to pre ss the RETURN
across. The pla yer is then inst ruc
key to start the gam e.
200 0
o 201
0
20
20
o 203(1
o
F:EJ'1 TIT LE
F'F.: I tH" :J"
FOP L==4 TO 10
90 0!S 00 0
GO SU B7 50 0,7 68 0,7 70 0J7 80 0,7
ON L-4
L
t'~f::<T
' "'HAt'~Gr'1AN"
F'F.: I t-n LEFT$ <UD$; ., 10::' SF'C':: 12; PRESS ENTER"; A$
:tq!!r~r~r!ll~r~[~It'.[~l
I t··/F'UT" ~~I.'1
A- ..
21
o
o
F'F.: I tH :,,)::(!llO.LETTEF.:::; CHO:;Et.~
F'F.: I tH
1-------------PF.: I tH :il~lrl~l~l!!l!!l!!JI .. rrHE COt'1F'UTEP:::;·r S
2HH) PP I tH :!!JI ...... ldOF.:D I::;;"
2110 F'P I tH :!I,) • • • • I" ;
FOF.:L= 1TOLE: PF.: ItH""" ; : t'~E>nL : F'F.: ItH
F'P I tH ;J:!!JI.F'LEA::;E CHOO::;E"
PR I tH :!!JI ••• FI LETTEF.:
2150 WO=0: LO=0: LI=0 : SC=0
2160 F.:ETIjRt·~
o 2070
2080
2090
o
II
o
II
II • •
II
II
II
II
II
II
II
o
o
II
o
Lines 2070 to 2160 complete the title sequence. First the
screen is cleared of the imtial title screen and PRINT
commands are used to display the next set of Instructions.
The letters chosen during the course of the game wIll be
displayed under the heading at the top of the screen. The
computer's selected word wIll be displayed half-way down.
At line 2120, an asterisk is printed for every letter in the
mystery word. This is done using another FOR. .....NEXT
loop, with figures ranging from I to the value for length
obtained in the selectword subroutine. Finally, the initial
values for some of the other variables used in the game, WO,
LO, Ll, and SC are set at zero. WO and LO are used in the
main program to call up the appropnate subroutine for
winning or lOSing a game. SC IS used during the game to see
if the mystery word has been correctly guessed, and Ll is
used to limit the game to ten guesses and to build up the
hangman graphics in stages. Once again, you can check to
see if you've got this part of the program right by following
the instructions In the box below.
TO
-reST
SUBROUTINE
=
es :
/. TYPE LE
8
PRESS IRETUJOlN I
:2 . AOO RENt AT THe STAfl.T OF I-INe 2030
3 . TYPE GOSUB .2000
PRess I AETuJOlN I
...
Del-ETE THE RENt
IN NEXT
I-INE 20
30 8EFO"....
R=E~ _ _ _ _ _~!!!!!~
PROCEEDING
TO THE
SECTION.
LETTERS CHOSEN
HANGMAN
THE COMPUTER ' S
.............
WORD IS
PRESS RETURN?
PLEASE CHOOSE
A LETTER
22
The next subroutine does all the work of the program. It
allows the player to choose a letter and checks to see if the
letter is part of the mystery word, Appropriate changes are
made to the value of SC and a check is made to see If the
game IS won, As you mIght expect, it's also the most difficult
sectIon of program.
Line 3010 moves the cursor to lme twenty-three and changes
the color to yellow, Three blank spaces cover over the old
mput and the cursor is moved back three spaces to the start
of the Ene, 1NPUTC$ causes a question mark and flashing
cursor to appear on the screen to prompt the player, The
second part of lme 3020 makes sure that C$ only contains
one character. Line 3030 prmts the guess on the flfth row
down the screen, The vanable L1 IS used so that the first
guess IS pnnted m the flrst space across, the second m the
second space, and so on,
:3000 REM CHOOSELETTER
0
0
0
0
3010
3020
3030
3040
II
II
C:0=0
FOF.: F'= 1 TO LE
3060 IF C$()MID$(N$ . P . l) THEN 3100
3070 CO= 1: ::;C=::)C+ 1
:30:::0 l,J$=LEFT$ 0:: ~J$.' P-l ::. +"?" +F:: I GHT$ UH .. LE -F'::O
::::09U F'F.: I ~HLEFT$ (. UII$ . 1::::) "3 ....... 1" :::::PC r:: P-l ::0 (:$
3[15~3
310~:::1
0
PF.: I tHLEFT$ <UII$ . 2:3) ~
.111" .;
INPUTC$:C$=LEFTt<C$,l)
PI? I tH i:m~rl!!r~r~).I" :;3F'C (L I> C$
t'~E::<T
:::: 1 10 IF SC=LE THEN NO=l
::::120 F.:ETUF:t·~
Line 3040 sets the value of CO at zero, so that the program
goes to the hangman subroutme If a valld letter IS not
chosen, (Look back to line 60 of the main program). Lmes
3050 to 3100 are a FOR. ..... NEXT loop whIch compares the
letter guessed with each letter of the mystery word in turn,
Let's take an example, Suppose the mystery word is BOOK,
and the letter input "A". P would have values from one to four,
the length of the word selected. MID$ IS used to copy part of
the stnng, The instructions in brackets say which string and
which part of the string to copy, For each of these, line 3060
would find that C$ was not equal « » to (W$, P, I) so the
program would run through to the end of the loop and return
to the main program. If the guess was K, the program would
run through the loop until (W$, P, 4). Since this IS equal to the
mput guess, the program would go on to Ene 3070 where the
values of CO and SC are changed.
23
Line 3080 places a question mark inside the mystery word in
place of the letter correctly guessed, so that if the player
makes the same guess again he or she will lose a life. Lme
3090 prints the correct guess in the correct place of the
mystery word, and in line 3110 the computer compares the
value of SC to the length of the word. If they are equal then
the value of WO is made I and the computer returns to the
main program Line 80 of the main program wlll then operate
the winmng subroutine.
LETTERS CHOSEN
THE COMPUTER "S
WORD IS
BltEFFALO
TO TEST SUBROUTINE
chooseletter J IT MUST
13£ RUN WITH THE REST
OF THE PROGRAM .
I. ADD REM AT THE
STAR.T OF LINE 60
AND LINE 2030 .
.2 . TYPE RUN
PR.ESS IRETURN I
DELETE THE REM's IN
LINE'S 60 AND 2030
BEFORE PROCEEDING
TO THE NEXT SECTION .
PLEASE CHOOSE
A LETTER
The hangman routine and the graphics it containS are gIven
in the final section of the book. The graphics are used in the
winning and losing subroutines that follow.
The win routine is very similar to that used to get the initial
title display. The screen is cleared and the appropriate
graphics - the man, in fact - are called up from the hangman
routine. The congratulory message is printed on the seventh
line USing LEFT$(UD$,7) and the color white, You will
remember that UD$ was set up in line 1005 to move the
cursor down by the number of rows given after the comma;
in this instance 7.
0
0
0
4000
4010
4020
4030
412140
412150
4060
4070
.
F.:Et1 l·J! t·~
P~:ItHI:J"
FOP L=5 TO 10
ON L-5 GOSUB751210,7600,7700,781210,7900,8000
t'~E;n
PF~ItHLEFT$(UD$)
PRINT"
7)
II
::t.JELL
DDt'~E,
HAS BEEN POSTPONED"
F.:ETUPN
.,
24
'r'C/UP
E::~:ECuTIOtr
o
o
o
0
0
0
50121121 F:D'1 LOSE
5[110 F'F.: an ":1"
0
5020 FOF.: L= 1 Tel 10
5030
Ot·~
L CilY3UB71 'Jt1 .. ?2~X1., 7300 . 74121[1) 750121., 76[H3) 7700.,
7:::00 ., 7900 .. :3~)OO
5040 t'~E::<T
5050 F'F.: I tH" ~=:~!!r~rl~r!!r!!] f::J'Hi',/ I ::;H FOOL !"
'T'OI..l LO:3T
5060 F'F.: I t-H :!lJ
5[170 F'F: I tH" :~tqI •• rrHE ~,lOF.:D ~'JAS:!!l": F'F: I tH::;F'C 0:: 5::0 D$
II
0
50:::0
II
0
0
0
F.:ETUF:t·~
The losing routine follows almost exactly the same structure
as that for winning. In thIS case the whole of the hangman
graphics appear on the screen. The original word selected
by the computer and stored as D$ In the seleclword
subroutine IS dIsplayed on the screen by line 5070. Notice
that when you ask the computer to display a string vanable,
there is no need to place it in quotation marks.
The last subroutine is the one whIch asks the player if he or
she wants to play another game. ThIS is a routine whIch you
could include In any other program that you mIght write. The
INPUT asked for in line 6030 is checked In line 6040 to see If
it is a "Y". If so, then the program returns to the beginning of
the main program -line 10 - and the game begins again.
Otherwise the screen clears and the computer says "ByeBye" in light red.
0
0
0
REt'1 PLA'T' ACiA I t·~
P PItH" :t!.I!I] DO 'T'OU ~J I :3H TO"
PLA'T' AOAIt·j" .;
F'R I tH"
INPUT A$
IF LEFT$(A$) 1 >="'T'" THEt·~ 10
B'T'E B/T'E"
605~3 PP I tH :[email protected]:~!!I~
606[1 F.:ETUF.:t·j
6000
6010
6020
60:30
604(1
II
0$:,'<-"
,:~";';;i-N::'
~
.-,
0"
.-
.;/
Apart from the graphics contained in the hangman
subroutine, the program is now complete At this point it is a
good idea to save the program on tape. Connect the tape
recorder as Instructed in the manual. Then type SAVE
'llANGl" and press the RETURN Key. The Commodore 64
will respond by displaying the following message: "PRESS
PLAY AND RECORD ON TAPE". To check that the program
has been safely recorded, rewind the tape and enter
VERIFY "HANGl" and then press RETURN. If the recording
is good, the computer will report "VERIFYING 0. K.". If there
are any errors, SAVE the program again.
25
0
0
0
r
,
r
Improve your program
Once you've typed in the program, you'll probably know the
list of words in the DATA off by heart. Get a friend to type in
a new set of data, or beller sill!, take turns m typing in words
while the other Isn't watching. Keep a note of the number of
words typed m and change the figure for the number of
words in Ime 10 10 accordingly.
Adding sound
Apple
The Apple is capable of producing many vaned sounds, but
this reqUIres more extensive explanatIOn, and is beyond the
scope of thlS book However, a simple buzz or bell noise can
be easlly produced. In the additIOn below the computer IS
PEEKmg the memory address (-16336) a total of 300 tlmes.
ThIS memory location is partIcular to the Apple loudspeaker,
and the noise is added to the lose subroutine when the game
is lost. Further additions are gIven in the fullllSting at the
back of thlS book
o
5072
5074
5076
FOF~
S =
LET T
=
1 TO ::)00
PEEK ( - 16336)
NEXT 5
Commodore 64
The Commodore 64 contains a powerful music synthesiser
but to get the best from It is beyond the scope of this book In
the additIOn shown below the vanable in the
FOR. ..... NEXT loop is being POKEd mto the HI frequency
regIster to make the pitch change (POKE 54273, I). The sound
falls when the game IS lost and rises when It IS won. Both
addItIons are given m the fullllSting at the back
Consult your manual for more details.
o
4063 FORI=0T024·POKE54272,0~NEXT
4067 POKE54277,15:POKE54278,240POKE54296,15
4~36::: F'OKE54276., 33 : FOR I =OT0255 : F'CWE54273, I : t·jE;:.::T
F'mO::E54276) 32
26
o
THE
GRAPHICS
All that remains to have the complete Hangman game is to add in the Hangman
graphics. These use all the graphics commands mentioned in the introduction to
build up an image like the one shown below. In addition, there are hints on how
you can make changes to the program to get a different result. The full listing for
the game, including suggested additions is given at the end of this section.
Let t et... s
The
Chosen
COMput et....... s
wo ...... d
IS
+**+.***
choose
27
.a
1 et t e ..'"
~e
N~~---------------------------------------------'
~~ All the graphics in the program are contained in the
~
hangman subroutine, The graphics screen has a grid of 280
coordinates horizontally, and 160 coordinates vertically,
These coordinates are used to plot the position of the
graphics charac ters on the screen and are known as pixels,
279
o
o
1HE GRAPHICS 5CRE.fN
HAS R GRIO OF
280 COOP..OINflT£5
HOR/ZONfRLLY; RNO
/60 COOROINflf£S
VERTlCflLLY
160 L _ - - - - -
The hangman image is built up m stages, one for each time
the player makes an incorrect guess Line 7010 does thlS by
increasing the value of LI by one each time the subroutme is
called up, Line 7020 sends the program to the relevant
section of graphics for each life lost. On the flISt life lost, the
upright post of the gallows is drawn. HeOLOR sets the
graphiCS color - in this case green on a black screen, A
FOR. .... NEXT loop used HPLOT to place an element on the
screen at the given X, Y coordinates and draws a line from
this pomt to the second set of coordmates,
o
o
o
0
7000
7UIU
F:;: E ,,,'
H ~\I r·j Cj 1'1 (:i 1',1
LET , ] " L, 1 + I:: IF L.1: 10 THEN ID " 1
CJ I',j I , I Ci ur i( / 1 0 'J 7.: U 0 , / :'00 'J 7 40 U " /' ~,) U" 'J / {. 0 U ',' II I) U ','
'/~]()() '! '79()() .,
7 100
/1 10
] 1 :?U
71::;,)
714(1
'j
fJ()()tJ
r;:U'1
briLL ,UW3
HCULUI;: ;; 1
FOR R
HPLOT
J
180 TO 190
R,14
R~16urn
N[ XT H
28
o
o
The gallows image should be on the nght-hand side of the
screen. The coordinates used place the gallows in the
posItion shown in the diagrams below. The HPLOT
command is used to draw the lines. The loop variable R
gives the first X coordinate across - in this case 180 - to
determine where it shall appear horizontally. A line IS drawn
from this positIon to R, 14. This system of line drawing is
repeated in mcreasing values of R in a FOR. ... .NEXT loop.
The diagram on the left, above, shows the first part of the
gallows. The second part of the hangman subroutine uses
the same set of commands to draw the second part of the
gallows. ThlS IS shown m the diagram on the right. The bar is
a five line loop placed on top of the first stem. It's a good idea
to note down the vanous positions on graph paper, so that
you can keep track of where you are on the screen.
U
7200
/.? 1 0
REM
GALLOWS 2
HCOLOF(== 1
F~m~ R ==
lO TCl 14-
HPLOT lBO,R TO 2 50,R
NEXT r:;:
RETURN
When the third life is lost the computer draws the third
section of the gallows. This is the cross-bar between the fIrst
two beams. It is made up of a single diagonal usmg the
HPLOT instruction.
7::::;00
REI'I
7 :~; 10
HCLJLOR= 1
/ ::;20
7T:::O
RETURN
[JALl..OW~:;'~
HPLOT 190, 3 0
TCl 206,14
29
,e
RV<V'~------------------------------------------------I
~
/'100
I::;:EI'1
F<CiFE
7410
7420
HCOLDF(:o: :.~
HPLOT 234,29 TO 234,15
--; 4:::;0
RETIJRI\l
o
Next, a rope is added for the fourth life lost. This is sImply a
Ime drawn from the middle of the gallows extending
downwards for 14 vertical coordinates. To test the graphics
written so far, follow the mstructions in the box below.
TO T£ST THE GALLOWS
SECTION OF GRAPHICS
Q) ADD REM AT THE
START OF LIN£S 7150,
7250 AND 7330 .
b) TYPE HGR: GOS{JB 7100
c) PRESS RETURN
TAkE OUT THE ADOITION
BEFORE YOU PROCEED
TO THE NEXT SECTION.
0
The next stage of the hangman subroutme will draw the man
himself. In HGR, there are only eight colors available: we will
use SlX. The man will be drawn up as shown in the box
below, but you could plan out your own design. To complete
the ten lives for the game, the hangman is built up in six
stages.
30
~
I
--
-_._---------------- - - - - - - - - - - - - - - - - -
~~~~e----------------------------------~
R
The first stage of drawmg the man is the face, This is a block
of color made up of straIght vertical lines drawn close
together using a loop mImes 7510 to 7530, The color IS
changed to draw the eyes sttll using the HPLOT command,
Line 7550 draws a straight line for the mouth and line 7570
draws the nose, The eyes are drawn m line 7560 as two
straIght lmes,
o
RE:~M FACE:
HCOLOR= 3:
7::.iOU
7510
FOR
HPLOT 1,49 TO
7:~i70
~~E XT I
HC[lLClR:::: (>
HF'UJT 2:::0 ~ 4~) frJ
HF'LO T 22Ei ,34 TTl
HF'UJT 2::;4, :38 TD
7:~i!30
F~FTUF(N
7560
o
=
1,30
I
o
225 TO 245
o
~:~40, 4~.:i
:~~30,::::A:
T~:'6,
HPLOT 240,34 TO 2 42,34
38
0 '
The body of the man IS drawn in red. HCOLOR= 5 gives red
on certam TVs, Values of I from 220 to 250 set the X
coordinates for the HPLOT command to act upon, fIllmg in
with the color already specified, To add a bit more detail,
the man is given coat buttons, The color is set at black, the
same used for the details on the face, Line 7650 places the
buttons hOIlzontally on coordinates 235 and vertically on
coordmates 65 and 85, You may wish to add more buttons,
or give the man pockets, It is easier to draw the effect on
graph paper first to see WhICh pixels to choose before
programming, The pixels dre those small squares similar to
your graph paper, An accurate plan can be made to scale
by counting 0-279 horizontally and 0-159 vertIcally,
0
S
10
IS
.20
2S
J.>
~
0
40
)
S"
10
o
7600
7610
~ 7620
\J 7630
7640
o 76~jO
7660
L_ __
REI"!
o
BODY
He (J L. Cl F(:::
~::j
F(JR I = 220 TO 250
HPLOT 1,90 TO I~50
o
NEXT I
0 -
HCOLOR= 0: HPLOT 235,65: HPLOT 235,85
RETURN
31
~e
~~r--------------------------------------------------.
9.~
~
The next section of graphics draws the man's arms. These
are again in red and are boxes with hands on the end. The
posltlon is chosen, then a loop sequence is set up to fill in the
rectangle. The hands are represented in the same color as
the face. Lme 7760 draws in the hands usmg the HPLOT
command.
o
o
o
7710
7T20
7730
7740
7760
77'70
HCC)UJF:= 5
FOR 1 = 213 TO 218
HPLOT 1,55 TO 1,105
I\lE:X T I
HCOLOI=<= :3
HPLC)T :~ 14, 106 TD 214, 1 1 (> TD ~J 1 f) , 1 10 TU 218, l06
o
()
0
F~ETlJRN
The second arm is built up in exactly the same way as the
flrst: only the honzontal coordinates change to posltion the
arm on the other side of the body. HCOLOR m Ime 7810 sets
the graphics color back to red.
o
o
o
7HO!)
7!310
7El:~0
71:'330
7FJ40
78::)0
/Fl60
7870
REI"I
{~I::;:M2
HCm.ClF(= ~5
FOR I = 252 TO 257
HPLOT 1,55 TO 1,105
I\IEXT I
HCOUJR:=:3
HPLOT 252,106 TD 252,110 TO 256,110 TO 256,l06
RETlJRI\I
o
The flrst leg and foot are built up by the next section of the
graphics, which are displayed for the ninth life lost. First the
color of the trousers is chosen - in this case HCOLOR= 6.
Then the loop is set up using FOR. ... .NEXT and HPLOT
draws in the color. The shoe is bUllt up in the same manner.
0
0
()
7(100
7910
7920
/930
7(140
7<i50
7960
7'-1'70
()
7980
7990
I=<EI'1
LEG1
HCDl._OR= 6
FDR I := :2~20
HF'LDT 1 'J 100
I\IE:XT I
HCDLOR'-= 7
FOR I -- 141
HF'L.DT 212 I
NE:XT I
,
i~
TO .. :.:.. .. .:...;;.
TD I 140
r.·-;rr\
,
TO 148
Hi 228 , I
0
0
0
0
F~ETURN
"'""
10"
32
''::
~;..":.
:;;
0
UOOO
REI1
flOl!)
HCClLOH c-;= 6
o
U=:G::;!
0
E3020
FOR I = 238 TO 250
f:3!)~::'O
HPLOT 1,100 TO 1,140
0
13040
NE::XT I
ElO~iO
0
8U60
8070
8080
8090
HCOLClR= 1
F'OR I =: (1::2 TCJ <:)iE)
HPLClT 220,1 TO 250,1
0
0
;
0
£il0!)
81 10
8120
Ell ::::0
8140
Ell :=.'iO
!"-IEXT
I
HCOLlJR= 7
=
FOR I
141 TO 148
HPLOT 24 2 ,1 TO 258,1
NEXT 1
REI'"I
DELAY
FOH 0 = 1 TO 1000:
NEXT D
F\ETLJRN
The final life lost gives the man's other leg and also adds a
belt. The second leg follows exactly the same steps as the
first, with only the coordinates differing, The belt is made by
drawing a series of seven straight lines using the
FOR. .... .NEXT loop, You will see that the man receives hIS
belt which is the same color as the gallows, before his foot is
drawn. All that remains in this section is to add a small delay
so that the computer doesn't run straight back to the main
program, and this is achieved in lines 8130 and 8140.
The hangman program is now complete and ready to run.
You should have the hangman graphics on the title screen
and when you win or lose the game. At the end of the book
the listing is gIven in full and there are some suggested
additions you can make to your program.
WH£N 77-1£ PI<Q:{RAM 5 RUN 77-IE SCRGers ShOULD 370W
AS ~ WHEN YOU "
STRRT
WIN
LOSE
33
The Commodore 64 text screen is divlded into 40 rows
across the screen and 25 vertical columns. To move the
printing position around the screen use UD$ (or parts of it) to
move the cursor down. To move the cursor across the screen
use Spc.
-.
39
IN THIS PROGRAM
wE MOVE ,HE
PR.INTING cug,50R.
ACROSS tHE SC.REEN
WITH SPC.
THE CUR,SOIl 15
MOVE&> DOWN BY
PRINTING PART5
of UO$.
0
0
~
14
.~
.'
';".~
".,'iii~'
The hangman subroutine is divided into ten stages, each
stage being displayed when a wrong guess is made and a
life is lost. In line 7010 the value of LI is increased by one
each time the routine is visited, and a check is made to see if
it has reached the value of ten, in which case the game is
lost. Line 7020 directs the program to the appropriate section
of the graphics, using the new value ofLI. The first section of
graphics builds the gallows post, using the simple block
graphics obtained by REVERSE ON and two spaces. The
reverse of a space is a block and can be used with any color.
700(1 F.: Et'l HmK;t'lAt~
7010 LI=LI+l : IF LI=H3 THEt·~ LO=l
7020 ON LI GOTO 7100.7200.(300)740O,7500)760O,7700)
7' :::00 790€1 ., 80'J(1
0 7100 F.:Et'l
GALLD~J::; 1
() 71 U~ PP I tH ;:r~,,"
712(1 FOP R=0 TO 21
'? 1:::~~1 F'F.: I tHSF'C 0:: 19> ~~
0 7140 t·.jE>:: T
7150 RETURt·~
0
\
J
II
'.'
II
",,,,*=,,,'*,-*' ,
II
.>y
34
The three symbols on line 7110 first home the cursor, move it
down one and set the color to brown. The cursor home is
represented by the reversed "S". The cursor down is
represented by the reversed "Q" and the brown is obtained
with 2. The FOR. ... NEX'l' loop sets out the row values to run
through from 0 to 21 and prints two sohd blocks starting in
column 19, To check this first sec!ion of the graphics type
GOSUB7100,
The second step of the graphics is to add the horizontal bar
of the gallows. It uses exactly the same method as for
building the post. Lines 7220 to 7240 produced a block
eleven spaces wide covering two rows,
7200 ~Et1 GALLmJ:3 .::.
7210 F'P I tH " i:i!!Z"
7220 FOR R=0 TO 1
7230 PPltHSF'C(21 >" ~
7240 t'~E;<T
7250 ~:ETURt·~
~,
0
()
()
"
0
The third stage is to add the cross-bar which joins the first
two parts together. The FOR. ....NEXT loop creates a
variable m steps of - 1, A parallelogram is drawn from the
top of the cross bar until the upright gallows is reached. The
triangle used to make each half of the parallelogram is a
shifted "£" sign. Line 7350 adds the last triangle.
o
o
o
o .,
PEt'1 GALLm·J:::::::
F'P I tH" !:i!!m!!Z"
7320
FOR R=2 TO 0 STEP-l
7:::::~:(1
PRltH::WC(21+~:)" ~"
7::::40 t'~E;:<T
7350 PRltH::;PC<21::O
7:360
o
",.11
RETUF.t~
" >1"
35
PEt1 POPE
PF.: I tH ~!!m!l""
FOPF.:=OTO 1 : F'f;:: I ~·n::;pc 0:: 29 >" I" : t·IEi<T
II
F:ET'-'Pt·~
The fourth stage is to add the rope. It lS made from one
"shifted minus" graphic on top of another using a
FOR .... NEXT loop. The loop is repeated once and the line
appears In the twenty-ninth column. If you RUN the program
you should have the completed gallows on the screen.
TO lEST TIfE GflLLOW5
SECTION OF GRflPIIIC5
Q ) I9DD REM ftr TH£
STflRT Or LINES 7150
725"0 I1NO 7360.
b) TYPE GOSUB 7100
c) PRESS /R£TuRW7
7RK£ OUT mE f/OOI17CNS
B£FOR£ YOU PROCEEtJ
"1"0 rHE NEX"r 5a::7101\!.
The next section of the graphiCS will draw the man. Before
you begin, it's a good idea to plan out your design as in the
box below. At this stage you can decide which colors you
want to use - there are sixteen available on the Commodore
64, mcluding black and white. The graphics for the man is
built up in six stages.
++
.
---.J
36
The first section of the man is the face. You will remember
that we have chosen to move the cursor round the screen
rather than print the exact posltlomng and colors on the full
graphics chart using POKE. For that we would need to
program both the screen and color memory maps.
The top of the face IS made usmg the graphics on keys U, E
and 1. The cheeks are made by the FOR. ... NEXT loop with
the "shifted minus" key (remember how you made the rope).
The graphics for the bottom of the face are 1. Rand K.
750~3
o
o
o
F.~Et1 FRCE
? 5 1(1 PF.: I tH " ;:{!!l~l~r~l~.rn "
752121 F'F.~ I t'~T~;F'C; (27) ,.----1--.,
75:3(1 FOF~F~=OT02 : F'F.~ I tHSF'C 0:: 27 :'" I
7540 PF.: I tH::WC':: 27::''' "-r-":TIT1"
7550 PF.: I tHSPC':: 2,;::;' + +": F'F~ I tH::::F'C 0:: 29 >" : " :
PF.~ UH::;F'CJ: 2::::) " __ "
7560 F.~E T'-'FJ·~
II
o
o
o
II
II
The details of the face are created by one Ime in the
program -Ime 7550 - which gives two plus's for the eyes, a
colon for the nose and a line for the mouth. To place these in
position the cursor has been moved up four rows at the end
of the 7540. Unless a prmt statement ends with a semi-colon
or a comma, the cursor moves down one Ime. Therefore, in
line 7550, the features of the face appear under one another
even though the commands are on the same line.
The next subroutine bUIlds the body. The color (light red)
and position are set mIme 7610. The FOR. ... NEXT loop
pnnts a rectangle three blocks Wide and five rows deep in
the same manner as the gallows. Line 7630 moves the cursor
up four rows and prints a reversed "0". Another reversed
"0" IS printed two rows below that. This produces two round
buttons on the hangman's coat. If you wanted to, you could
use a similar command to give the hangman pockets by
usmg two subtraction symbols. It's a good idea to run the
program at this point, to check that you've positioned the
body correctly.
o 7600
F:Et'1 BOD'r'
?i'; 1 [1 F'F: I tH" ~flrflrfll~rflrflrflmflr~~"
. 7620
o 76:;:0
7640
PP I tH::;F'C 0:: ~~::::;. ~
t'~E::<T
F'F: I tH II TIn" ::;PC':: 29) " ;:.:1" : F'P I tH::;PC 0:: 29::'
FOF.:F.~=0T04:
II
F.:ETUFJ~
37
II
:
":fll~f
II
For the next life lost an arm IS added to the hangman. This is
made m three parts, shoulder, arm and hand. The shoulder is
made from two blocks (reversed spaces) on top of each
other mIme 7720. To separate the arm from the body a block
with a bit of space mlssmg on the right hand side IS needed.
N produces a line on the right, so by pnntmg it in reverse the
required space is formed. Lme 7730 gives a three line loop
which makes the arm The hand IS represented by an '''0''.
o 771210
7720
F:Er'1 AF:r11
t'~T 'I !:i~l!Il~m~rl!ll~l!Il~rl!l~I'
FOF.:F.:=0TO 1 : F'F.: I t-H:;:WC': :27 >"~ ": t'~E>n
7 ',<7.(_ 1/_1 FOF.:F.:=OT02: F'F.: I t-HSF'C <27::' ":~ I" : t'~E>n
7740 F'F~ I t-H::WC':: 27::' "(I"
7750 F: ET'-' F.: t·~
771El F'F.: I
o
o
o
The next life lost produces the second arm This is created in
exactly the same way as the first. Only the number in
spec ) changes, to place the arm on the right-hand side of
the body. The H is used to separate this arm
F:Er'1 flFJt2
F' F: I !. ~ T " ::I~l~l!l.m~m~l~l~ll!l)]"
FOF:F:=OTU 1 : F'i': I t·n::;F'C 0:: 31>
7::::30 FOPF.:=OT02: F'F: I tH::;F'C 0:: 31 ::.
-;:'::::40 F'F: I t-H::WC 0:: ::: 1 ::. "(I"
7:::00
o 7:::20
7::: 1
~3
o
7:::50
"~~
"~
": t··ID::T
" : t'~Dn
I?ETUF.:t·~
The next part of the hangman to be added is the legs. The
first leg is created by a six Ime loop using REVERSE ON
space and REVERSE OFF K. and is displayed when the ninth
life is lost. These will occupy the one and a half spaces that
are available for each leg - the body is made up of three
spaces and each leg has to be half this width. The command
given Will produce light green legs, but, of course, you can
produce any color that you wish by using another of the color
codes. The legs are drawn starting at row fifteen. Line 7910
could be stated as PRINT LEFT$ CUD$, 16) to place the leg on
the sixteenth row. This IS to avoid counting a large number of
cursor down symbols which could lead to errors. The color
code would have to be placed in inverted commas
38
o
o
0
0
0
F:n~-:-ln PEt'l LEG2
:::f1! (1 F'I~: I tH II !:i~I~I~I~I~II!!I~I~I~I~I~I!!lI~II!!I~:aI"
::;::02(1
: F'F.: I ~H:3PC <28::' ~
:::030 F'F: I I·H::WC';: ;;-::::) ~J I I I I I n~1 :+: "
:::040 F'F.: I tH::::F'C';: 2:;::::' ".~!!Im!!ll~m~r
::'W50 F:Et" DELA'T'
FOf?F.:==f1TO:::~
II
II
:
t··IE;:.:;r
II
()
-II
8060 FOR D=l TO 1000
::::07'0
o
o
NEXT D
,~
F.:ETUF:I··~
The second leg is drawn by overprinting the first leg. The
legs are printed as a large block with a line up the middle.
This line is produced by using the "shifted minus" key.
Remember line 8020 is all in reverse, so the line appears as a
gap.
For this last stage of the graphics, we will also add a belt and
shoes to give the hangman detail. The belt is colored
medium gray. It is produced by using the REVERSE ON
space with the ordinary asterisk, to act as the buckle. The
shoes are printed in brown at the end of each leg by using
the 0 key. Finally, there is a short delay at the end of this
section before the computer returns to the main program.
With this last section, the program is now complete and
ready to RUN. Because the hangman graphics are called up
in the subroutine for the title, the hangman should appear on
your screen when you type RUN. The graphics are also
called up when the game is won or lost. At the end of the
book the program listing is given in full, and there are some
suggested additions to make the game more interesting.
There are noises and mouth movements. For example, when
you win the hangman smiles and when you lose his mouth
rums downward I
WH£N n-I£ P~M 6 RUN THE .5da5"£AS ShOUu:J ShOW
AS ~ WHEN YOU "
STRRT
WIN
LOSE'
t.l:L.l DOHE. 'r'OI.IR ('([ CUTt ON
HAS IUH POSTPONE D
------- --------------------------------------------------------~
39
Improving your program (2)
Now that you have the complete program typed in you
should save it on tape. The method for storing programs is
given in the user's manuaL Why not try to build completely
different graphics?
Apple
Commodore 64
The program listing below gIves the
complete Hangman game. Those program
lines marked wlth an asterisk (*) are
additional to the program given in the main
part of the book
Given below IS the complete program for the
Hangman game for the Commodore
computer. There are additional lines marked
wIth an asterisk (*) not given m the main part
of the book These gIve added detaIl to the
game.
1 C'
:))
30
4 1)
5.)
6 1..1
7('
8('
CjI ,)
I'),)
1 H)
HANGMAN
I F WO '"
I F L O .,
WIN
LOSE
I
I
THE N
THE N
101 0
lO2t)
RES TORE
LE T C H
II)~)
FOR L '"
REA O WJ
1(1 61)
N EX T L
I 07u
11) 81)
::!(lIj(,
LET L E::
L EN
RET UR N
REM
TIT LE
:::0 1( '
2(,20
HGR:
FOR L
:0::;0
ON L -
20 40
2050
"20 60
NE X T L
:20Q( ·
: 1('11)
:::: 11 .,)
:::: 1 : .)
:::: 130
2 15 (!
:::: 161)
"50i)0
3 0 10
302(1
3030
3(1 4 0
305 0
3060
306::::
3064
3(16 6
3 (17 0
308 0
;,(19 0
3 100
3 11 0
::; I :X'
4 (100
4(1 10
40:')
4'):,1.1
'1(14 ( 1
,. 4') 4 5
. 40 4 6
4 (1 5 0
4(61)
., 4',1 65
., 'll) 60
4(107
4 .-,70
REM
REM
F'LA 't AG A I N
WOF.. O
1 .'1:·1)
z
GOSU8 4 ( u)O :
GO SU 8 5 ( u)(' :
REt'
10 4 (1
:'070
*'
GOSU 8 3('(JO: REM CHOOSEL E TT ER
IF CO - I) THE N
GOS U8 7(I( U): REM
GOTO 4 ( .
GOSU8 6(lI II) :
S TOP
REM
S E L ECT
LET W - 8
( 1)('11.1
10 PRnn " :l"
20 GOSUB 1808: REM S EL E C T~J R D
3 0 G05UB 2008 REM T I TLE
40 IF WO= ! OR LO=1 THEN 80
50 GOSUB 31300 REM CHOOSELET TE R
613 IF CO=O THEN GOSU B 78 8 0· REM HANGMRN
70 GO TO 40
80 IF ,10= 1 THEN GO ~: U B 4,) ':'0: F:EI·1 ,I W
90 IF LO= 1 THEt·1 DOSUE: : ,8 88 REI'1 LOSE
1013 GOSUf: 68')0 : ~' EI1 PLR', RGA HI
110 STOP
101313 REI1 S ELEcnIO~: D
1005 UD1= " ~~.m.m'!~'l'!'l~'m~'l~'l!l.III!.!.!'!'I"
1010 ~1= 8
1020 RESTORE
103,,) CH=INTCRND(0ltN)+1
1040 FOR L=1 TO CH
HGR: HOME
GOSUEI 100(.: REM
S E L ECT WOR O
GOS U8 2 1)(11) : . REM
T I TLE
I F WO - I OR Lr '" 1 THEN 80
I Nr
( RN Q
II)
•
!,oj}
..
I
IT O CH
HOME
= 4 TO
4
tW:J ) :
L E T OJ
WI
1050
1('
GOSUB 7 5r"lIJ , 760(' , 77('l' , 7eCH) , 7 9(1(,.8 1)01.1
V TA 8 2 1: HTAB 14 : P RINT " H H N G M A N"
V TA E< :-::"': HT A E! I (! : INF'U T "PRI ',; RETURN TO S TAR T "
;A:t
HOME: HGF.
V TA E! : 4 ~ HT AB I : PR INT "LETTERS
CHOGEN : ":
V TA 8 ::: HTA8 :8: F'RIN T "COMPU TER 'G"
V TA£, :::: 3 : H TA& 3() : PR I N T "WORD IS"
V TA E.< :4: HTA8 3 0
F OR L =;: 1 TO L E: p RIN T .. . .. ;: NEXT L
VTAB 21: HTAB 1: F<RINT " P L EASE CHOOSE A L ETTER"
L ET WO '" 0: LET L O '" (I : L E T l I '" I): LET S C '" (I
RETURN
REM
CHOOSE LETTER
V TAE.<:I: HTAB :24
INPU T C-5: IF
L EN IC'f.)
1 THEN 30 10
vTA B 2 4: HTAB L \ .. 16: PR INT C f;
LET CO '" I)
FOR P = I TO LE
IF C-f
MI D I. (W" , P , I ) THEN 3 100
LE T WI" =- .. .. : LE T w:! 'f. '"
IF' P ..
1 THEN Wl f .
L EF T'I - ( WI,P - 1)
I F LE '
P THEN W:! f. .:
RI GH T-f (W-',LE - P)
LET CO '" I : LET SC • SC .. 1
LE T loiS := WI -f ... .. ..... " .. w:::: 'f.
V TAe 24: HTA8 P ... 2 9: F<F.' INT Cf;
NE XT P
I FLE - SCTHEN
L£TWO= I
RETURN
REM
WIN
HOME : HGR
FOR L = 4 TO I t.'
ON L - 4 Bo sue 7 5(11) ,76(11),7 7 '.)(',7 8 0 1) , 79(1(I,80l)')
NE X T L
HeOLOR= 0: HP L O T 2::::7, 4 0 TO ::,(1, 4 5 :
HP LOT : 40,4 5 TO : 4 :: ,4 0
V TAS 2 1 : H TA 8 I: PM' I N T " WEL L DONE, YOUR
EXECU T ION "
F'R I N T " HAS BE EI\I F<05 TF'QN ED "
FOR 5 ';" I TO :'5
F'R IN T
CHRI ( 7 );
NEXT 5
RE TURN
READ~I$
1060 ND:T L
10713 LE=LEW ,IJ;> D$=,I:1:
Ij
1080 RETURN
)I 20013 RErl TITLE
213113 PRun":l"
213213 FOR L=4 TO 113
• 21)3 0 ON L -4 GCI'::UB7500 ~ ? r; l10 , 7 70 8 7:::80 7900, 800 ~1
2040 NEXT L
PRINT LEFT:t:(UDt. If) 'SPC ( 12 ) "'HRIIG~1Rtl"
@ ~~~g INPUT" :l!mru~IIlIllIll'l,W'l
PF:ESS ENTE~:", R$
2070 RR I NT" :l:Ql,,.LETTERS CHOSEtl"
2080 PR I fn" ••1------------- -"
:2090 PR I fn" "'lIlmrumru~l!,.fTHE COMPUTEW,:' S"
211313 PR ItH .. •, .. . . . I-IORD I S "
2110 PRItH .. O . . . . I" :
21213 FORL= I TOLE : PRI NT"~" ; HEXTL PF: lilT
2130 PR I NT" ;n,.PLEHSE CHOCr,E "
2140 PRlm " O ••• Fl LETTER "
Ii
J
?
21513
21613
3000
31310
30213
31330
3040
3050
3060
31370
313313
WO=0
I
LO=O : LI=0: SC =@
RETURfl
REM CHOOSELETTER
PRHHLEFT :t :(UD$. 23;,":;1
'111" .:
INPUTCS : C$=LEFTS.CS,I )
PR I NT" ~mllllllllll!"I" SPI~ ( L I ) C$
CO=0
FoR F'= 1 TO LE
IF C$ ()MIDS(NS , P, 11 THEN 3 108
CO=I · SC=SC+l
W$=LEFTt ( WS,P-l ' . "? ".RIGHTS ( W$ , LE-P )
3090 PRHlTLEFT ! ( UD:L 1:,:) ",;)I . . . . I"$F·C( F·-l ) I~S
3100 NE;-;T P
31113 IF SC =LE THEN NO=1
3120 RETURN
401313 REM ,JI fl
4010 PRINT":l"
4020 FOR L=4 TO 1[j
40313 ON L-4 GO S UB?:,O~3., 7600, 7 7 0 ~ , 78l10/7900 .:3000
413413 f !EXT
045 PR HIT "l:'fi1J1.IIl.!IIl((~mlll" SPC 0::23) " '._ ' "
413513 PPIIHLEFT H UDS , n " ~ I ELL DOHE , '~OUR Ei:ECUT lOW
r-r------------~--~----------------~~~~I~r-~~~~~~--~--~~~~--~~~=-~--~r_
5(,,)(1
....,.1 11.
f-·'Er'1
HOI'lE
St, .:.-"
FOR L =
~,i'-.',
5_)5·"
506(1
5·,7(,
• 511 7_'
11'" 51. 7'1
,, 5(176
"
~ 1.!7 8
. 5079
5"811
lOSE
HGR
I
i
!
TO J'-'
ON L GOS UB 7 ! •.'t) . 7::'_"', 7-.,.t.I • .' 4'_"),7:-,I)O , 76C1(.', 7 7 ('ti .
7 FhuI , .'9'11 ' , 8' )1)'"
NE " I l
'V TAB :' 1: H TA& I: PR INT " INA V I S H F OOL ' "
PR I N T " YOU LOST'"
PRINT " T HE WOR D WAS "; 0-'
FOR 5 - I TO :-.1)(,
LET T ==
PEEl
( - 1 6:·:-·<,;,)
NE r.T 5
H eaL OR=- ( , : HF"lOT ::-:8 , 4 8 TO :':-. o.'l~J :
H F'lOT :: 4 u . 4 ~ TO :' 4 : ,4 8
FUR I:;;
foJ E X r I
IIl I
H CO l OR '"
7:
ru
14 8 :
f=.O R I o=c
NE t. T !
FOR J :
TO ::':'8 , I :
HFt .CJ T:'I ::' , 1
Ill"1
H COLOR: 1):
14 1
TO :58,J : NE \ T J
I-l COLI1R == 7 : FO R J "" 1 4 q
TO ::sn , J : NEXT .J
RE TUR N
T(E M F-'L AY AGI--'I J N
V TAE! : ~ : H T AB I: P R JN T
A GAIN Y /N ~ ":
I NF'UI
TO 1 5 6 :
~ ::~~~
I! .. 4069
I"
5000
, '_ " ,1
TO
1 48 :
HF"L O T
;'" ~i l , . J
TO
1 ~,6 :
H f-'LLJ I
.' ll :' , J
HTAB
FORI=0T024
PCWE5 4 2if.
"(jO
16 :
7 11'1 0
71 1l'
7 1 :,...
! 1 -·fl
71 4(1
7 15.,
7 '200
":' 10
7 :::::=0
' :':.0
7: 4 (,
1': 50
7::'6(1
1 :'(11,'
731(1
7 :·20
7 : ·30
7400
74 1 I)
74 ::'(1
74 3(,
750(1
7 5 1[.!
7 5:'('
7 5:0
7 5 4 '.I
'/ 550
7 560
1:5 7 ')
7580
" 6 (11)
76 1('
1 6 -:')
7 6:·0
7 64 ,',
F'OK E 5 4 ~ 7 ':; . :~:2
F'R I IH " ,::roW'\'i'\'\'\'\'\'\" ~:, F'C ' 2 :,: ," ,-, "
F'F' I en " ,\,l,",\,\.\,\,\o!.m'I" ',;1" (, 0: 28 ..' " Po:.1 II
RETU RI·l
F:Ei'1 F'LA', AC' A I t l
F'~: I HT " o:I['\'\'\'l'l,101'\'\'\'\'"'\'['\' \,[,1 DO ','CIIJ ,I I '"H
PRIH T "
PLRY AG AIN",
It·W UT RX
IF LEF Tt'RJ.. I>~"','" THEIl 10
F'F: li n " :1'\,,'l,\'l'!!'l'\N,>!'
B','E I:',E "
6(16 ~3 F:ETURI·l
7000 F'EI'I HAH GI'IHH
IF LI= I O l HE H LO= I
70 10 LI= L I+I
YOU WI S H 10 I 'LI'I Y
F''''' JN T " (1'I'E flY E"
r
7 6~['
76 6l'
77 (11)
7 7\ 1)
·/ 7 ::'f,
77 :1.
.'7<10
77 5,',
ll ol'
77 7'-,
7801.1
7 8 1 ...,
7 8::''-'
78 :".(1
78 4 0
1 85(,
7 8 6 (1
7 87tl
79(11)
79\ ,,)
7 9:',)
79 : .f)
7 4<1 ,)
7 9 5f)
!'i"6 u
7 9 7(.
7 9 8u
79 9 0
8 ( u)O
8 0 \ .)
8(J::'0
8[)30
8 (1 4 ( ,
80 S, :
8 0 6 (1
GALLOWS I
R EM
HCOlOR = I
f 'OR R = 180 TO 19')
HF"lo T R , 16 [) TO R ,IC,
NEXT r..
RE TURN
REM
GAl lOWS :'
HC olOR: I
FOR R .. 10 TO 1 4
HF"LO T 18( ',R T O :'5(I ,R
NE XT R
RET URN
RE TURN
RE M
GAlLO WS HCOlOR =- I
HPlO T 19,) , ::(, fa :')6 , III
RETURN
RE M
ROP E
He OLOR -::,
HPLor :: ~ 4 ,::9 T O ::> ':. 4 , l:='j
RE TURN
R c: M
FACE
H COlDR = : .: F OR [ '" :::! ~ TO ::' 4 5
HPLO T 1, 4 9 TO I, :,0
NE X T [
H eOLOR": 0
H Pl o r ::> : ·lI ,45 1'0 ::'4 ( ' ,45
HF'LOT ::28 , : ,4 TO ::': [) , : .4: HPLO l ::: 4 ( " :. 4 TO :: 4 ': , -.<i
HPLOT ~:.4, ~8 TO :--.6 , 38
R E TURN
REM
BOD Y
H eOl OR'" 5
F OR I
TO :'S"
HP lO T 1 , 9 0 TO 1, 5[.>
NE X T r
He OLOR", ,-. : HPLOT : ,,:·5 , 65 : HI-'lO T ':: 35 , 85
RETURN
REM
ARM 1
He OLOR a 5
FOR [ = ~ I::, TO :-' 18
HF"LO T 1 , 55 TO 1, 11)5
NE X T [
H CDlDR= :::·
HPlOT ::' I Q, 11.I6 TU ::' 1-1, 1 1') 10 '. ' 18 , 1)11 fO ~H~ . I ' )b
R E TURN
RE M ARM::'
HCOLOR ~ 5
FOR I - ::'5 :::' I U : 57
HPlO l 1, 55 10 1 ,1 .,5
NE XT 1
HCOLOR= :.
HP lO f :5:' ,1 ',' 6 TO '::5':. 1 1') 10 :~5I:> , II' ) ! u .: ..., .... . 1.. / .
RE T URN
RE f"l
lE G I
HCOL OR ., b
F OR I ~ :::"t' 10
HP L D T 1,1 ',11' TO 1.141)
NE x r I
H eOL OR '" 7
F OR [ ::= 14 1 r o 14 8
H F'L OT ::' 1 ::: , 1 f O ::::8 ,1
NEXT I
R E TURN
REM
L EG::'
H COl OR - 6
F OR J "" :- :'8 TO :-;5(.
HFLO T I, I '.II) TO 1 ,14 ('
NEX T I
H eOL OR =. 1
F OR I '" 9 : TO 98
0:0
71 ( 11)
7 I 1<:,
7 120
?l 30
:' 140
;' 1 5~'
B'):' ~)
HFLOT 22('. I
NEXT I
H eGl OR::: 7
FOR I = 141
TO
8; 1(1
HF'LO T 24:, I
TO 25 8 , J
812('
81 :.(1
NExr 1
REM
DELAY
8 141)
8150
FOR 0 =
RETURN
9000
DATA
!
TO
APPL E ,ANGLE,ALPH A 8ET , A S TE R OI D
RE TURN
(241) HE :":
I
725(1 ~: E TU ~:t-j
7300 FE I'I GALL O~J :=; .3
7 :,: 1(I F'R an " <i,!!,\QI"
7320 FOF: F: = ~' TO (I ', ;TEF'- 1
73:3(\ PPltlT :::PC (21+P} " ~~ "
73 40 HG:T
T~:50
PP!HTS F C<~l
)" r "
7:360 F:ETUF: tl
7 4Cn) F'EM POPE
7410 F'RIIH "<i,I.\or."
;'420 FOF:F:=':1TI)1 F'F:HH',:F'C -:'29 >" I" IlE:: '
(' 4:30
751:10
751 (I
('520
FE: rU F t·j
REI'I F ACE
PF: I HT" *I~\'!!'I'li1"
pF.:II·n::;PC(2 7 . . " ,- ' -', "
~' 5::::0 FOFJ;:=OT02 ' F'F: I IIT ',; P C '~ 27 .' " I
I" ' I~E ,,: l
, 540 F'F'IIH :3F'C 0:. 27 .:0" "-..--' 'TTTT'
75:,0 FF.'IHT:; PC ' ~ ::: .. " + + " PF"I tlT';PC '.. 2? '" :
F'F: H H :;PC 0:: 2 8 .:' " - - "
7 560 F:ETU~'H
7600 PEr'l BI~I[r'T'
76 1'" P R IIH" ;:!,\'I,\'""'W'!!,I'>:'''
7620 FOF.:F:=OT0 4 PF: I fl T':;P C, 2t' :' ":~
" t·lE",;T
7 6 ::"3 PF: JIlT" 'TTTT""F'I: '. 2 9;' " :~:,,, : F'P It H S F'C .: 2 9 ',
7",40 RETUPI'l
7;'(n) REI1 RPI'll
77 10 PF: I tn " <i'1'1'1'\1!I~\'W'I'>!' ''
7720 FORR=0TO 1 PRIIHS PC <2?',,, ;,
t lE. :i
(, 7.3(t F()F.'F:=OTIJ2 P j;~ [HT ::.F'C '~2:- , ,, :~ I" t l E;~ T
;'740 FPIIH:; PI_. '.27 :·, " ,) "
7750 RETURI<
7800 REl'j AFI12
7 8 1'~
F'F: It n " ::'1'I,\.\1!I.I.I'J'1,lo.>!'''
7:32 0 FOPF:=~'TO I : P~: IIH ';PC <3 L' ''~
IlE :,: t
7:3:30 'FOF'F:= OT02 F F' IIHSF'C(.3 L''' :~
l·lO :T
7 ;;:4 ~1 P~: ItH :::P C ': ::1.' " C,"
7850 RETU~l l
;'900 ~HI LE GI
,911:' F'F:; In" <i.m.\. \1!I.."\1!I.l~\'\'\'\"\'.I "
,320 FOR F: =':'T 05 F'F' I IH::,F'I: ', 2:,:;''' :, !!I" IlE::l
79:::0 FE TUF: t·l
:3~10C1 ~:E i' l LEG2
SO 1 0 P F:1 In" ::'1'\'1.1'1'1O(.1.\.,[.\.\.1,1'"'JlI "
8020 F OF:P:;O T05 :F· Rlt·n S F" C '. 2:::)'· :~
" HE:·-·:T
:::(!:30 PRII·I EPC0::2:,: :,. " ;;rnnTn:l +
:::040 F'F: I IH SF'C 0:: 2::: .' " .m.I'l.m'T
E: 1 2 0 ~:EI1 DEUW
14 8
NExr D
HE;< T
7 2 1(1 PF: IIH"<i~ "
7220 FOF: F.:::::(1 TO 1
723(1 P~: 1I n:3 F' C(2 1 .. ":~
TO :511. I
l (u)(I:
7:::00, 79L:::l0 ,. ::: O~H)
F:EI1 C, ALLml:,: !
PF: WT " 01'':''
FOF F.'=(1 TO 21
PF: I /H::.F'I>' I~" .. " ~~
( 2 1)(1 F::Er1 [, ALL Ot·IS
: :, ' ,
8 ( -8 ·)
sr,? ,}
81' ( ,
P O ~ E5 42~'2 ! 0 ~jEX T
F' O.~.E 54';': ;:::., ~40 F'Clf-.E 5 4.29€. , 15
. 3 3 FO P l=2 5:, TOOS TEP- 1 P Of. E '5 42 ( :~: ·
FOF:E5 4 2 7 7 . 15
L I - l 1 ~ I : IF L I "" 10 THE N Ln - 1
ON II GOTO 7 1('() ,7 :'(!(' , 7'".:".(UJ , 74 (ll' , 7 5'"J , 76 '.J", 77,.. ,.! ,
780 u . 79' '(' , 8 ( 1110
LE
POKE5427 7 , 15 : F'C1kE 5427E:, 2 4 0 F CI,:E 54 2% , 15
FOKE54 276 ,3:3' F OF:I =OT0 2 5 5' POKE5 42 73 , I IlE i-n
PO KE542 76, 32
RETURN
;;'HI U:r" E
F'F' Ii IT " :1"
F!) ~' L= 1 TO J!~
IlE;<l
F'F:lIH" >l:('m,\o!,\'1 l.l lA\,'!:',H F OOL I"
PF' IH T " 'J
',(1'-' UY:· T "
H:IIH " " ....... 'rH E I,IORD I,IA:,:, I" F'F' IIH :3F'C': 5', V!
HI .:' :' '' ,I :
HI'lOl
HAS BEEH F'C1S TPOI-lED"
5':1.3''::1
IF A t '"
I:
41370
5 010
502i3
At
HOME
V H~E< ::'
RETUR N
REM
HA NG MA N
4060 PF: ltH "
~06 3 FOR I =~'T024 : PI),; E54272, I:' l·l Ei<T
i.'.'.
~
&
~:~9m.OmrnliOm~mDm~iliTmA·mm:m,:m':m:'ELrnEE'm8DmDml'm'mBmUFmFE.Am~E~;'g"mEAmC8H~Dm~i@~wmmm~~mrn!!!~JI
41
:31 ;:0 FOP [1=1 TO l(tOU
!lE>-:: T
II
;;:140 F:c TUF:II
9(100 DATA APPLE ,A ~3 LE ,A L PH~~ E l ,AS TEROID
9010 DATA BOTTL E .. Bo m .' I::_: I-FH ~ O · tEAC H
".J~':'"
I :IL: '"
rl:I"
Glossary
DATA
A list of information that is required by a program DATA can
consIst of words or numbers, or both together. A program IS
sent to the DATA with the instruction READ.
FOR ..... NEXT
This IS a sequence of commands that are used to make the
computer repeat an operatIon a certain number of tImes. For
example, the loop FOR X= 1 TO 5:PRINT 2* X:NEXT X would
cause the computer to print the two times table up to five.
GOTO
This statement tells the computer to go to the specified line,
mIssing out any lines In-between. It IS often used wIth
IF.. ... THEN (see below) and is only operated If certain
condItIons are true. Be careful when uSing GOTOs, as It'S
easy to have the program jumping backward and forward so
much that It IS Impossible to read.
HGR
HPLOT
ThIs sets the high resolution graphIcs mode on the Apple.
This places a set of x, y coordinates on the Apple screen. If
HPLOT is followed by TO, It draws a line from the last point
plotted to the coordinates indicated. ThIs works both
horizontally and vertically.
IF ..... THEN
This is used as a way of tellmg the computer to do something
only when certain condlllons are true. This instrucllon often
looks something like this: IF score=LE THEN WO= 1.
INPUT
This Instruction allows the computer to be gIven Information
while a program is running. When the computer comes to an
INPUT instruction it prints a question mark (or, for some
computers, a different symbol) to prompt the user, and walts
for the input to be gIven and carriage return to be pressed.
INT
INT IS short for integer, and instructs the computer to make a
whole number of a figure wIth decimal places m it. It is often
used in conjunction with the RND command which instructs
the computer to generate a random number (see below).
LEFT$
LEN
ThIS instruction is used to copy part of a string, starting at the
left-hand end. It IS followed in brackets by the string name
and the number of characters to be copied.
ThIS is a BASIC instructIon whIch counts the number of
characters in a string.
42
LET
This IS one way of giving the computer mformation. In some
programs there may be statements such as X= 10
This simply means that the number ten is stored under the
label X It is often clearer to write:
LET X=lO
The LET statement also gives rise to something that at first
sight seems illogical, If not Impossible. In many programs
you will see thmgs like
LET X=X+l
Of course, in mathematical terms X can't equal X + 1. All this
type of statement means is "mcrease the value of whatever is
stored in X by one."
LIST
This makes the computer display whatever program it has m
ItS memory. You can LIST single lines, or parts of a program
by following the LIST with appropriate Ime numbers.
MID$
This is used to copy the middle part of a string It is followed
m brackets by the stnng name, the start position, and the
number of characters to be copied
PEEK
This instruction looks at a particular memory location. It is
often associated with POKE.
PIXEL
This represents a pomt on the gnd m graphics mode. The
number of pixels per screen is determined by the quality of
the graphics, e.g. high or low resolution mode.
POKE
This stores numeric information in the computer's memory It
is often used for sound and places a bmary number in a
particular location.
PRINT
This tells the computer to display somethmg on the screen.
Letters and symbols that are to be displayed should be
enclosed in quotation marks, but numbers need not be.
RlGHT$
Similar to LEFT$, but copies the nght-hand end of a string
RND
This instruction makes the computer generate a random
number. The precise instruction varies between different
models of computer. RND IS followed by a figure in brackets,
usually 0 or I. To obtain random whole numbers it must be
multiplied and made a whole number by the INT statement.
STEP
The STEP statement is always used followmg a FOR. ...
statement. It indicates the amount that the variable should be
changed for each operatIOn. For example: FOR X=O TO 20
STEP 5: PRINT X: NEXT X Would mean that X would rise m
steps of five, so that the computer would print 0,5, 10, 15, 20.
43
Variables
When you give the computer mformatlOn you have to give It
a label under whi c h it is stored. This label is called a
variable since the informatIOn It contams may c hange dunng
the course of the program. When you want the computer to
do something with the information, you must refer to it by Its
label - its variable name. For example, the statement LET
A =6 places 6 under the variable name A .
There are two types of variable. A numeric vanable is one
in which the information stored will always be numbers. If
the data to be stored consIsts of le tters or words then a siring
variable must be used. The variable name must then be
followed by the string sign - $. So, for example, if you wanted
a name stored, the statement would read : LET N$ ="JAMES" .
String variable information must always be in quotes.
Index
C
M
S
color 9, 23, 24, 28, 30, 31, 32, 34,
35, 36, 37, 38, 39
control codes 8, 9
mode 8, 30
saving programs 18, 25, 40
screen backgrounds 9, 21. 24,
31, 32, 37, 38, 39
sound 26
stnng vanable 13, 16, 17, 20, 23,
25, 44
subroutme 10, ll, 19, 20, 21, 22,
23, 24, 25, 39
N
numeric vanables 44
D
DATA 12, 13, 19, 20, 26, 42
delay 33, 39
G
graphics coordinates 8, 28, 29,
30,31,32,33,35,36, 37
H
HGR 9,14,30,42
HPLOT 28,29,31, 32,33,42
p
pixel 28, 31. 42
POKE 28, 29, 30, 31. 32, 33, 37,
42
T
R
random choice 13, 19, 20, 43
RESTORE 13, 20
REVERSE 9,34,38,39
I
INPUT 16, 17, 18, 25, 42
INT20,42
44
tape recorder 18, 25
Design
Coope r · West
Program editors
Steve Rodgers
Marcus Milton
Illustrators
Lionel Jeans
Rob Shone
45