Home

"user manual"

image

Contents

1. 16860 L 1878 LESLEH N 2 D4 1 1880 The first subroutine allows the computer to choose a word from the list stored in the DATA Line 1010 sets W to the number of words in the data list RESTORE instructs the computer to READ from the beginning 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 using the INT command The 1 is added to prevent the number ever being zero The FOR NEXT loop of lines 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 HS TERO II Sea CT aa STATS T Sone NINA anon name PETENTE EN ee NS TIE AIR E LOI TIVA III SIINO gt ES SEN O O AD lt de O The next subroutine calls up the title screen This will use some of the graphics created later in the hangman subroutin
2. mac _ 7550 HELOT 250 45 TO 240 45 7560 HPLOT 228 54 TO 220 24 HPLOT 240 34 7570 HFLOT 254 58 TO 256 58 QOO TO 242 24 mi Woo x mE y ma a On an DE ANE A ENN EQ SILA II OPS Oe DERA AM es rs LB LORI EN ere LUE pereza COMMODORE 64 SIT O B F RE BTDZOPRIHTSPEOZTO I NEXT 946 PRIHTSPCCORS2 C T UTIIY O Pesa PRINTEFCC 28 e CPRIMTEPCOISOU SU O PRIHTSPC i PLE GRAPHICS CO ORBINATES START IN THE TOP LEFT 1 RNER cM p CAN USE SPECIAL CONTROL CODES TO POSITION CHARACTERS et ver vi qu p 34 XT 22 ETC 7 2 Ta 6552 4 4 e ELS y n m DC Color To obtain colors a number of different commands are used In HGR mode of the Apple colored graphics are produced using the HCOLOR command followed by a figure from 0 to 1 The exact color depends on the T V and its adjustment The background color is black On the Commodore 64 both graphics and text are colored by the CTRLor 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 N B Colors on
3. FEES First published in Great Britain in 1984 by Franklin Watts 12a Golden Square London WI First published in the United States in 1984 by Gloucester Press Copyright Aladdin Books Ltd 1984 Printed Belgium ISBN 0 33 1 03483 6 Library of Congress Catalog Card Number 84 81 108 WRITE YOUR OWN PROGRAM GRAPHICS Mike Duck GLOUCESTER PRESS NEW YORK TORONTO 1984 ae gi Foreword JOne of the most exciting things about computers is the graphics effects they can display on your screen Most ready bought games programs allow you to control what s happening on the screen whether it s moving a spaceship to javoid alien attack or steering a racing car around a dangerous Crand Prix track The programs that produce these effects are very complicated but you can use simple graphics commands to create an interesting and satisfying computer game of your own The program given in this book builds up the Hangman game In this game the computer chooses a mystery word and asks the player to guess what it 1s 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 into a number of logical stages so that you can clearly understand what each section does Giving 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 com
4. The first leg 15 created by a six line 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 UD 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 FEM LEGI FF THT FORR AT0S PRINTSPO 255 A MM HET RE TURH LI 3 1 1 1 4 41 4 ib i wi GIRI xS SRA REM LEGS SAL PRINT terete S020 FORREBTUS PRIMTSPCC2BO S SHEET S830 PRIMTSPCESS UITITITTIA SAJA CASA REM DELAY _ cagA FOR TO i886 HEST I SATA RETIREN The second leg 1s drawn by overprinting the first leg The legs are printed as a large block with a line up the middle This line 1s 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 grap
5. set at zero that 1s the game has been neither won nor lost TEST SUBROUTINE TITLE ADD REM TO THE START OF LINE 2030 b ADD LINE AUS LE 8 C TYPE HGR GOSUB 2000 PRESS RETURN DELETE THE ADDITIONS BEFORE PROCEEDING TO NEXT SECTION X HANGMAN PLEASE CHOOSE A LETTER COMPUTER S WORD IS PRESS RETURN TO START LETTERS CHOSEN 333 15 q 4 da The next subroutine really does all the work in the program 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 1 right or wrong 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 1s 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 variable LI In fact all this means is that when the value of LI is then the letter will be printed in the seventeenth column and when life becomes two on the second incorrect guess then the letter chosen will be in the eighteenth column and so on for the ten guesses allowed in the game At li
6. 2158 W z8 LIse st a 2160 RETURH O Lines 2070 to 2160 complete the title sequence First the screen 15 cleared of the initial 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 computers selected word will be displayed half way down At line 2120 an asterisk 1s printed for every letter in the mystery word This is done using another FOR NEXT loop with figures ranging from 1 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 LI and SC are set at zero WO and LO are used the main program to call up the appropriate subroutine for winning or losing a game SC is used during the game to see if the mystery word has been correctly guessed and LI 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 LETTERS CHOSEN HRNGMFIN THE COMPUTER S WORD IS KEKE PLEASE CHOOSE A LETTER PRESS RETURN The next subroutine does all the work of the program It allows the player to choose a letter and checks to see if the 3 m 459 letter 1s part of the mystery word Appropriate changes y
7. Consult your manual for more details F RI TOS4 P KESd2FPZ O HEXZXT F KES4ZT i158 P UKEBSd2T2 24B0 P EES4z535 F KES4zTE amp 33 F RIseTOZS8 P KESd272 I PIKES 32 IEXT T E NE M PG MM Ps 26 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 Letters Chosen Ce y e The Computer z word iz di d EE 4 Please choose a letter al 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 characters on the screen and are known as pixels The hangman image 1s built up in stages one for each time the player makes an Incorrect guess Line 1010 does this by increasing the value of LI by one each time the subroutine 1 called up Line 7020 sends the program to the relevant section of graphics for each life lost On the first life lost the upright post of the gallows is drawn
8. GOTO HGR HPLOT IF THEN INPUT INT LEFT LEN A list of information that is required by a program DATA can consist of words or numbers or both together A program 1 sent to the DATA with the instruction READ 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 TO 5 PRINT 2 X NEXT X would cause the computer to print the two times table up to five 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 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 This s used as a way of telling the computer to do something only when certain conditions are true This instruction often looks something like this IF score LE THEN WO 1 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
9. HCOLOR 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 point to the second set of coordinates POOO REM HANG MAN LET Xd LI IF LL s Di IHR Loos i ll GOTU FAA Pay lt ZIO ZZZ 7800 7900 80000 7100 REM 1 7110 1 7120 FOR 180 TO 7120 5 TO 14 7140 e The gallows image should be on the right 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 increasing values of Rin 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 This 1s shown in the diagram on the right The bar 1s a five line loop placed on top of the first stem It s a good 1dea to note down the various positions on graph paper so that you can keep track of where you are on the screen GALLOWS i F210 HCOLOR 1 ZU FOR 10 TO 14 Zt HOT L5 OJR TO 2950 gle 7240 NEXT When the third
10. NS ST SSS SEAR O O O O MEM CIR RI e A Meena S000 REM LOSE 5010 HOME HGR 3020 FOR L 1 TO 10 ON L 7800 7900 8000 5040 NEXT L SOSO VTAB 21 HTAB 1 PRINT ENAVIGH FOOL 5060 PRINT YOU LOST 5070 PRINT THE WORD WAS Ds SOROD RETURN The subroutine for losing the game comes into play after 5 s d _ value of LO is set at 1 this actually happens in the THE PLAY AGAIN hangman subroutine later on Again the graphics which will ROUT INE CN be produced during the hangman subroutine are called up to give a good display Notice that line 5070 also prints the original word selected at random by the computer which was stored as D in the selectword subroutine The final subroutine in this section of the book enables the player to play again Line 6040 allows the 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 1 now complete apart from the graphics section which 15 contained in the hangman subroutine This 15 treated separately in the second section of the book For those users without a disk drive at this point itis 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 Mak
11. RIsGaITO2Z55 F KES4z 73 I HET igm NEXT L F S050 VTAB 21 i PRINT FNAVISH FOOL PORE TIEF Gs 5060 PRINT YOU LOST 5 RETURN 5070 PRINT THE WORD WAS Di Saga REM LOSE 5072 FOR S 1 TO 200 FRIHT oy 5074 LET T FEE 168226 S amp S FOR L 1 TO 1H 5075 NEXT 5 25 f 7 G x 5078 HCOLOR HFLOT 228 48 TO 220 45 E mM UB ena dy toa TRAD CS TORIS 5079 HFLOT 240 45 TO 7241 48 ES FEAR 7306 5080 FOR I 141 148 HPLOT 212 1 TD 270 1 NEXT I PRINT Meat of HAVISH FL 1 Ww 5082 HCOLOR 7 FOR 1 149 TO 156 HFLOT 220 1 PRINT HY LOST TO 228 1 NEXT I ef m AREE ves N SERV dS ERIHT NNMBBITHE WORD FPRIHTSPELSO D4 ik HCOLOR 0 FOR J 141 TO HELOT 2543 IR I BT za FU E 542172 A a HEZT TO 258 J NEXT J 45086 HCOLOR 7 FOR J 149 TO 156 HPLUT 242 J FO UkKESdz 7 5 19 F kES4zr3 zz40 F EESJdZz9 amp 6 15 TO 250 J NEXT J F KES4276 33 F EIZZSSTOBSTEF 1 P KES42 03 I HEAT 6000 KEM FLAY AGAIN MUSS 50 0 VTAR 24 HTAR 1 FRINT DO YOU WISH TO FLAY PRINT SPD c DEO UA 6050 INFLIT 6040 IF Y THEN 10 SIFIRIRIRIRIPIRIMIRIRIRIRIRIIRIEIR WISH Tu 5060 RETURN 7000 REM HANG MAN FLAY AGAIH E 7020 ON LI GOTO 7100 7200 7200 7400 7500 7600 7700 IF LEFT amp 8 13 THEH 16 ise on FE IHT CINNMSINSNINISES E
12. eyes are drawn in line 7560 as two straight lines O REM FACE 2510 HCOLOR 5 FOR I 2225 1549 1001 0 faa NEXT d 7540 HGCOLOR O 23350 MHFLOT 250 45 TO 240 45 7200 HFLOT 228 54 TO 950 24 240 54 Foe WAP LA 04 38 TURN The body of the man is drawn in red HCOLOR 5 gives red on certain TVs Values of I from 220 to 250 set the X coordinates for the HPLOT command to act upon filling in with the color already specified To add a bit more detail the man 1s given coat buttons The color is set at black the same used for the details on the face Line 7650 places the buttons horizontally on coordinates 235 and vertically on coordinates 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 are those small squares similar to your graph paper An accurate plan can be made to scale by counting 0 279 horizontally and 0 158 vertically 7600 REM BODY 7610 HCOLOR amp 7620 FOR I 220 TO 250 7650 HPLOT 490 TE 1500 7640 NEXT I 7650 HCOLOR Os HFLOT 225 65 HFLOT 233 89 RETURN 3l TO O 242 54 5 The next section of graphics draws the man s arms These are again in red and are boxes with hands on the e
13. gu LF dell 1 THEN M LOSE JODO G0SUB SOOO FLAY AGAIN i0 Sr 0000 The first stage of the program 15 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 main program to the next one this case the titles subroutine This subroutine gives the initial title display Lines 40 to 70 form a loop which 1s repeated until the condition in line 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 1 sent to the win subroutine if the game is won Line 90 of the program goes 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 REN The subroutines are written separately It is a good idea to G IN check each section to see if it works Before doing this SE d b it s necessary to include the DATA statements at the end TO SEE EXACTLY HO of the program Because the computer automatically puts PROGRAM line numbers into sequence they can be added at this point 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
14. not chosen Look back to line 60 of the main program Lines 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 string 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 lt gt 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 zs equal to the input guess the program would go on to line 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 he or she will lose a life Line 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 1 and the computer returns to the main program Line 80 of the main program will then operate the winning subroutine THE COMPUTERS MORD IS B FFALO PLEASE CHOOSE A LETTER The hangman routine and the graphics it contains are g
15. program THE MAIN WoRK3 7000 DATA APPLE ANGLE ALFHARET ASTEROID 9010 DATA ial ania BUFFALO BEAC li LOO REM SELECT WORD 1910 LET W dg JOE ila Re 14430 INT RAND 13 W FOR 1 TO LOSO READ WE _ 10600 NEXT L LE CORPO LET DE 1980 The first subroutine selects the word to be guessed All subroutines are first defined as in hne 1000 REM SELECT WORD In line 1010 the value of W is set to the number of words stored in the DATA RESTORE in line 1020 tells the computer to begin at the first word in the DATA each time the subroutine is run Without 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 this point using a FOR NEXT loop with Las its loop variable If the random number generated 1 four then the computer will read through to the fourth word This word is then held in the string 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 characters held in a string and also stores the wotd selected in the variable dummy D The LEncth is used to display the number of letters to be guessed and D is used to display the mystery wor
16. the Apple may blue Try out the commands given below and experiment vary from those given below with the figures using the values given in the chart 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 CLEAR SCREEN CURSOR RIGHT HOME CURSOR al CURSOR LEFT CURSOR DOWN REVERSE ON CURSOR UP _ REVERSE OFF COLORS APPLE COMMODORE OTHER COMMODORE COLORS ORANGE BROWN LIGHT RED DARK GRAY MEDIUM GRAY LIGHT GREEN LIGHT BLUE LIGHT GRAY Better programming The first stage of writing any program 1 to break down the task which the computer is to perform into its logical steps Each of these steps can be made Into a separate stage within the program called a subroutine in the Applesoft BASIC used on the Apple computer and in Commodore 64 BASIC The main program for the game will call up and execute each of these subroutines as they are required One of the main 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 subroutine more than once the program In fact 1n the program in this book the graphics that are available from the graphics section are used this way to give an attractive title display and separate displays
17. when the game is won or lost Using subroutines also means that the main program 1s much simpler In fact the main program which places the subroutines in their logical order takes up less than twelve lines of program j fi PEY i 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 Letters Chosen The Computer word iz 40 x Please choose a letter 11 NN 9 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 HOR s HOME ZO GOSUB 1090 SELE 4 2 0002 REM IF WO OR LO 1 THEN 0 POSURE obs LH ODOSELETTER 40 IF CO THEN 7000 REMI HANGMAN 709 GOTO 40 go le WO 1 THEM 4000 REM WIN
18. 09 7258 The third stage 15 to add the cross bar which joins the first two parts together The FOR NEXT loop creates a variable in steps of 1 A parallelogram is drawn from the top of the cross bar until the upright gallows 1s reached The triangle used to make each half of the parallelogram is a shifted sign Line 7350 adds the last triangle O 7368 REM GALLONS 73158 1 7328 FOR R 2 TO 73230 PRIHTSPCCOZi ROUIMNEU 7340 C 7358 PRIHTSPCG212 F 7260 RETLURH 35 Pell RUPE PRINT ATM 291 HEAT aS ae The fo ade 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 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 including black and white The graphics for the man is built up in six stages 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 positioning and colors on the full graphics chart using POKE For that we would
19. 1 98120 REM DELAY 9140 FOR TO 1000 NEXT D 81507 RETURN DATA APPLE ANGLE ALPHABET ASTEROID DATA BOTTLE BUFFALO BEACH 7 1 i E gt gt E uw P T r gt 7 ki F E b f Ki 1 je Y 1 1 Fa 2 1 1 i CO 1_O eB La Fj 1 C3 mom wy m amr FORPZST02 SPIE FFIHTS SEL arno RETUFH REM ARMS 98804 FORR 4TO1 PRINTS FORRSATOS PRIM PRINTS prea FEM LEG FF THT eene Osos HEST FEM LEGS FE THT gapjen FORR 0T05 PRINTSPO ZA FRIHTSPCZZESU AIYIIITII S PRINTSPC ZE REM DELAY FoR TO HERT RE TURH DATA APPLE ALFHRAEET DATA BOTTLE Book BUFFALO BEACH c Oo J J o 04 EP OS OO Cl B Po n 60 I os n mL os i Am aM m gua aac 1 O 218 100 NN xS LI D 47 5 7474 74 74 SI 73 IT lugm n mi i ni tette LEE RRO E 1 re o DN Sm n co v a E pa I Me d wo Pa RS mu Ai ID 1 ER Glossary DATA FOR NEXT
20. 16 PRINT C 3040 LET CO o 3050 FOR TO LE 3060 IF C gt MIDE 1 THEN 2100 S062 LET WIFE LET Wor 3064 1 THEN WIFE LEFT WE F 1 5056 IF LE lt E THEN W2 RIGHTS ws LE F i070 LET CO 1 SC 1 2080 LET Wt WTF 2090 24 29 PRINT Cs 3100 NEXT F 3110 IF LE SC THEN LET WO 1 2120 RETURN 4000 REM WIN 4010 HOME HGR 4020 FOR L 4 TO lo 4070 ON L 4 GOSUB 7500 7600 7700 7800 7900 B8000 NEXT L W 4245 HCOLOR 0 HPLOT 227 40 TO 200 45 WM 40465 HFLOT 240 45 TO 247 40 40350 21 HTAB 1 PRINT WELL DONE YOUR EXECUTION 4060 FRINT HAS BEEN FOSTFONED 4065 FOR 5 1 TO 25 10566 PRINT CHRE 17 4057 NEXT 5 4070 RETURN Commodore 64 Given below is the complete program for the Hangman game for the Commodore computer There are additional lines marked with an asterisk not given in the main part of the book These give added detail to the game 18 PRINT I 29 GOSUB 1 REM SELECTHORD SA GOSUB 20600 REM TITLE 4 IF WO 1 OR LO t THEH 50 GOSUR SAAN CHOGSELETTER 58 IF COs8 THEN TOHO REM HAHGMAH GOTO 40 846 IF WO 1 THEH 360090 WIH 94 IF LO 1 THEN GOSUE ena REM LOSE 100 GOSUB REM PLAY AGHIN 118 STOP 1066 SELECTWARD 1495 Uls 1814 H 8 1028 RESTORE 1636 CH INTC REND Ho 1 1040 FOR L 1 TO CH 1850 REAINE 1666 NE
21. AVE the program again 25 6 lt b Li 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 better still take turns in typing in words while the other isn t watching Keep a note of the number of Words typed in and change the figure for the number of words in line 1010 accordingly Adding sound Apple The Apple 15 capable of producing many varied sounds but this requires more extensive explanation and is beyond the scope of this book However a simple buzz or bell noise can be easily produced In the addition below the computer is PEEKing the memory address 16336 a total of 300 times This memory location is particular to the Apple loudspeaker and the noise is added to the Jose subroutine when the game is lost Further additions are given in the full listing at the back of this book 2072 PUR 5 1 TO 200 LET PEER 1652 56 NEXT 5 3074 3076 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 variable in the NEXT loop is being POKEd into the HI frequency register to make the pitch change POKE 542731 The sound falls when the game is lost and rises when it is won Both additions are given in the full listing at the back
22. INTRODUCES THE ART OF roots fi Op _ PROGRAM JING YOUR COMP EACH YCTURE A PROGRAM 1 25 gt SHOWS HO TO STRUCTURE E TIME EXPLAINS pini rt SA ALIA oe Lhe di TT H YOU IVI 0172629 8 RI ni i o a SKING THE PUTER TO DO IT CRISI Lew E s FUN 700 EACH BOOK CON TAINS er gt THERE 5 _ OR MORE EXCL LIN C gt AND OK IGIN Abe P oos CAN DE TTT resero cu p NI 5 ee e ear sie u o TO THE COMMODORE 54 Books ARE SPES goce o d atit come vibe all TT 9 e erue pesos amete isle nda ee Let feno LL iL uel Pe eal a i o uM Tr TITLES IN THE 52 BEGINNING De GF JU e Sen 1 A Gloucester atester Pres Library alltuedow chi LION
23. N PRINT Spade FEINTSPCCS SITI Suit I a MES C II CUI La 1 5 m D 74717174 74 C Cur DI e DT ROB KK CX NEN A CN EN A Cf EE 11 nr OLA _ Pam mar Pg We Ma mit e gt RES 74 74 7 Ti CP IT CP CU LT mise Oy N If aa Sl T SIE T C Cm m Ti ens PSI Co CO PA P3 P3 NI RO papa mM gm Pam orm TI IS mil gt I UE Cas UE CD Im aT zo 7700 REM ARM 1 7710 HCOLOR 5 7720 FOR 1 213 TO 218 7730 HFLOT 1 55 TO 105 SFO NEXT I 7750 HCOLOR 2 PRIN TSP 7760 HPLOT 214 106 TO 214 110 TO 218 110 TO 218 106 7770 RETURN FEM PODY PRINT MEIN Mea Inter Dc BR OT 94 FORR BTOI PRINTSPL 25244 MENT eee ae aed my uo ms os pp mp f TT 7850 HFLOT 1 55 TO 1 105 PFPRINT TITTINSPO 290 ao FPRINTSPO TES 7840 NEXT 1 7850 HCOLOR 2 REM C ee PRINT SR 2870 RETURN 7900 REM LEGI 7910 HCOLOR 5 7920 FOR I 220 7970 HFLOT I 100 7941 NEXT I 7950 HCOLOR 7 4960 FOR I 141 7970 HFLOT 212 1 7980 NEXT I 7990 RE TURN 5000 REM LEGO 8010 HCOLOR goto FOR I 8030 HPLOT I 8040 NEAT Bos Boao Bory Boo ge gio Bil HFLDT 242 1 TO Bt2o NEXT
24. NEXT I soso HCOLOR 1 8060 FOR I 92 TO 98 8070 HPLOT 220 1 TO 250 1 8080 NEXT I O 8090 HCOLOR 7 8100 FOR I 141 TO 148 8110 HPLOT 242 1 TO 258 1 8120 NEXT I S120 REM DELAY 3140 FOR D 1 TO 1000 RETURN NEXT D 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 drawind a series of seven straight lines using the FOR NEXT loop You will see that the man receives his belt which 1s the same color as the gallows before his foot 1s drawn All that remains 1n this section 1s 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 1 now complete and ready to run You should have the hangman graphics on the title screen when you win or lose the game At the end of the book the listing 1s given in full and there are some suggested additions you can make to your program rames AS BELOW WHEN YOU START WIN HANGMAN WELL DONE YOUR EXECUTION p HAS BEEN POSTPONED PRESS RETURN TO START DO YOU WISH TO PLAY AGAIN Y N 33 O WHEN THE PROGRAM kS RUN THE SCREENS SHOULD SHOW LOSE KNAVISH FOOL YOU LOST THE WORD WAS BUFFALO DO YOU WISH TO PLAY AGAIN Y N The Commodor
25. TE Ev 7110 HCOLOR 1 xS cia 7120 FOR 180 TO 190 FEM HAHGMEH LI LI 1 Tu 4 THEH LU 1 7140 NEXT CH LI Gate BP Fan SEA 7150 RE TURN gt Y EIC 7210 HCOLOR 1 7220 FOR 10 TO PRINT SMR FOF TO zl 2240 NEXT 7250 RETURN WEST 7100 REM GALLOWS 7 RETURN 7310 HCOLOR 1 em 7330 RETURN FOR TO 1 7400 ROFE 7420 HPLOT 234 29 TO 234 HE 7430 RETURN 7510 HCOLOR 2 FOR PRINT SBIR 7520 HPLOT 1 49 TO 1 30 FOR P 2 TO STEP 1 7540 HCOLOR 0 7550 HFLOT 220 45 TO HEST PRINTSFEC oar 570 HFLOT 274 38 TO SBO RETURN FOFE 7510 HCOLOR 5 PR IT 7620 FOR I 220 TO 250 RE TUF 7540 NEXT I REM FALE 7650 HCOLOR 0 HPLOT 225 65 HFLOT di FEIHTSFLUZ FORE HTHZ SPRINTS roca se FRIHTSEC ae Ms t UCPEIHTSPFCZZ33 S090 RE TURN FEIT AFL 2 AGAIN Yen REM FLAT AGHIN 6050 HOME 21 HTAR 18 FRINT BYE BYE 7010 LET LI Lt 1 IF LI 20 THEN LO 1 IHFLIT AS 7100 REM GALLOWS 1 FETURH 7170 HFLOT 150 R 14 __ 7200 REM GALLOWS 2 FEM SHALLOWS 7220 HFLOT 180 R TO 250 FEIHMTSPECIS32 M 7260 KETURN GALLONS 7220 HPLOT 196 30 TO 206 14 da es 7410 HCOLOR 2 PRIHTSPLCZI2 8 7500 REM FACE REM DRLLCUUDNZ3 NEXT I S FRIHTSPCOZIM4R IV 560 HFLOT 228 24 TO 0 24 HPLOT 240 24 242 74 FETUFH 7600 REM BODY FORFRSATOI 2901 76 20 HFPLOT 1 90 TO 1 50 7660 RETUR
26. XT L 1970 LE LEHGVE DE HS 168A RETURN 2090 REM TITLE 2010 2020 FOR L 4 TO 18 2838 ON L 4 GOSUBYS8S 7600 7700 7900 SAGA 3 244A NEXT L 55 2058 FRINT LEFT amp lt UD amp 100 SPC 12 BHAHGMAH 2068 INPUT FRESS ENTER AE 2070 CHOSEN 2080 2090 PRIHT mssINENSS RhRITHE COMPUTERS 5 2180 PRIHT EBBBBBBLIOED IS 2110 PRIHT XBBBBBI 2128 FORLZITOLE PRINT amp HEAXTL PRINT 2130 CHOOSE B 2140 PRINT 3PBBBH LETTER 54 2158 WO 4 LI 6 5 2168 RETURN 3000 REM CHOOSELETTER 3619 PRINTLEFT amp UD 2320711 IERI 3020 INPUTC C LEFT C 12 3030 PRINT SPEI 3040 0 3850 FOR 1 TO LE 3060 IF C 2MID cHT P 1 THEN SIDE 3070 CO 1 SC SC 1 3884 WS LEFT EWE F 1 4 7 4RIGHTEC WS LE Fo 3090 PRINTLEFTE LUDE 1327 SPCCP 1 204 2100 NEXT 3118 IF SC LE THEN WO 1 3120 RETURN 4690 REM WIN 480180 PRINT I 4020 FOR L 4 TU 16 4930 ON L 4 60SLIB 38h 7600 7700 900 SAAR 48040 NEXT 4045 PRINT SPC ZAG 48050 PRINTLEFT amp UD 7 gt DONE SI ee WE 5000 LOSE Pi S010 HGR aeg PRINT HAS BEEN POSTPONED 5020 FORL 1 TO 16 i FORISATO 4 PORES4ISFZ 0 NEXT TOT d ee 200 7500 7400 7700 FOK ES4E FF lt FI ik E5dzrYz F 240 FO IK E 15 T 63 P KES4Z2 6 33 F
27. ag im Imi attt I ege TR HUE wisi oom r J 7 DI pa pa Cn Fi cnr O xa 1 Roe RENE st 0 ODES SONO SOOO LIL FARMI N NOG A inte a X5 55 x tatto eee Re e E NN eR ATTO on VOI NON CLELIA NASO O IT RI e EI NOn eI MAN le enne TRI RIINA MM ST ARTY NN i Sod STRO SRLS ett Ne Cee ee oe SEO NT ee 2 Se SSS OSS oe LEA ST ORIO SA OL MANE EES SENSO ree SS SSE ST SE SSS es ae SES SSE ASS SSS lt amp The three symbols line 7110 first home the cursor move it down one and set the color to brown The cursor home 1s represented by the reversed S The cursor down is represented by the reversed Q and the brown is obtained with 2 The FOR NEXT loop sets out the row values to run through from 0 to 21 and prints two solid blocks starting in column 19 To check this first section of the graphics type GOSUB7100 The second step of the graphics 1 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 REM GALLOWS 2 7219 228 FOR R 0 To 1 v238 PRIHTSFCC212 8 724
28. d if the player fails to guess it RETURN directs the computer back to the main program AGOSUB 1000 28 TO TEST SUBROUTINE SELECTWORD Q ADD LINE 1075 PRINT W b TYPE HOME PRESS RETURN GOSUB 1000 PRESS RETURN DELETE LINE 1075 BEFORE PROCEEDING TO THE NEXT SECTION The next subroutine calls up the title screen This uses some of the graphics 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 J010 HGR HOME E 2020 FOR L 4 TO 10 z02D ON L 4 GUSUB 75600 7600 700 78b8 7900 0000 2040 NEXT L S050 21 HTAB 14 PRINT H AN G M A N 2060 225 HTAB 105 INPUT PRESS RETURN TO START a 1 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 2010 selects HGR and HOME clears the screen Lines 2020 to 2040 sends the program to the appropriate section of the hangman subroutine This will 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 on row 21 beginning at the fourteenth column across Th
29. e These graphics appear on the right hand side of the screen so this should be kept in mind when deciding where to place the text instructions AL 77 MSS P A VAL A AL The title sequence has two parts The first section given below gives the initial title screen the second gives the screen for the beginning of the game Line 2010 clears the screen Lines 2020 to 2040 send the program to the appropriate section of graphics available in the hangman subroutine stages four to ten This will be explained later in that section of the program In brief the hangman image 15 built up in ten stages one for each wrong guess or life lost The PRINT command positions the word HANGMAN ten rows down the screen beginning at the twelfth column across The player is then instructed to press the RETURN key to start the game dn REM TITLE ul Oz 2B1B PRINT 2828 FOR 1 4 TO 16 J SASH OH L 4 GOSUETSOG Pena 7700 7500 7300 BERE 20468 HEXT L O S058 PRINT LEFTECU0E 1735220123 EHRHGMRE THF LIT mmm mr tenes ane S870 PRIHT TZMEMRMBLETTERS J 2090 PE IMT IRE as ZAM PRIHT TIMDINBINEEBRITHE 210A PREIHT NABBBRBLIOFI IZ 2118 PRIMT ZRBEBBI O 2128 F RL 1TULE PRIHT amp HEXTL PRIMT 2138 PRIHT IBBELERSE CHOOSE 2140 LETTER
30. e 64 text screen is divided into 40 rows across the screen and 25 vertical columns 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 OS THIS PROGRAM WE MOVE THE PRINTING CURSOR ACROSS THE SCREEN WITH SPC THE CURSOR 19 MOVED DOWN PRINTING PARTS OF UDF cec NDA n SII Vat e Robo 5 The hangman subroutine 15 divided into ten stages each stage being displayed when a wrong guess is made and a A REVERSED SPACE 15 life is lost In line 7010 the value of LI is increased by one THE OPPOSITE OF AN each time the routine 1 visited and a check is made to see if EMPTY SPACE it has reached the value of ten in which case the game is SOLID BLOCK lost Line 7020 directs the program to the appropriate section so PRINT SPC jim 1 of the graphics using the new value of LI The first section of EHI T 5 AC ES graphics builds the gallows post using the simple block 2 BLOC K 19 ca 3 graphics obtained by REVERSE ON and two spaces The FROM THE LEFI reverse of a space is a block and can be used with any color HHHGHHH LISLI 1 IF LI 14 THEH L 1 LI GOTO F r TABE PS Be REM GALLOWS 1 FUR TU z a HEAT RETLIEM FIGUR TON n mus 1 Pm m m 15 a IS 7 7 1 eal Ape ela 1 I ie GTI Pim M
31. e player is then instructed to press the RETURN key to start 14 VITA 24 l PRINT LETTERS HOME Haf CHOSE Mes HTAR 2692 PRINT COMPUTE 20 2100 VTAB ZZ HTAB 20 PRINT WORD 15 2110 VTAR 24 HEAR 20 O 2120 FOR 1 TO LE PRINT NEXT L 2130 21 HTAR i PRINT PLEASE CHOOSE A LETTER O 2150 LET WO O LET LO O LET LI LET SC 2160 RETURN 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 displayed on line 21 starting in column one At line 2120 an asterisk is printed for every letter in the selected word This is done using FOR NEXT loop with Las its loop variable with values ranging from to the value for length obtained in LE earlier Finally line 2150 sets the initial values for the other variables used in the game at zero SC will be used to decide whether or not the game 1s won LI 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
32. e 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 SOOO FLAY AGAIN VTA 24 1 PRINT DO YOU WISH TO FLAY AGAIN Y N 6040 INFUT AF 5040 IF Y THEM 10 5050 HOME is HIGH 16 PRINT BYE BYE 6060 lt Q The main program for the Hangman game is very similar to the breakdown given in the introduction Each logical step in the game s 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 1s obtained DOSIJE 19664 REM SELECTHORD 2t GUSUE 288 TITLE 46 1 OF LO 1 THEM BOSUE shige REM CHOOSELETTER SH IF Lose THEM GOSUE Pees REM HRHGMRH O GOTO 4H oH IF WO 1 THEN GOSUE qaaa REM TF LO 1 THEN GOSUB Shee LOSE DESLIE Bee REM FLAY NGRIB SUBE O LEO d Let s lookat 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 15 displayed at the beginning of the game Line 40 tests to see 1f the game has been won or lost this only c
33. e to use them at a later date The first section of the book deals with the main program which controls how the game works second section explains the graphics that will make up the screen display EE e du i et co Hue 72 an Ac aid ro E E B Contents Introducing Graphics Color 2 THE GRAP APPLEle COMMODORE I Program listing __ Glossary Index y 4 1 4 e c E i 1 i ni La c rit S E y 2 1 T J d ud m ela I T 443 b 1 iJ t CHE Mil SE C UT Qe dba MC BE fe I a RE129 ECHR 414 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 coordinate Commodore 64 can also position graphics on the screen asa series of PRINT statements Type in the graphics commands below and then RUN them to see the result APPLE Ile 7510 HCOLOR 3 FOR I 225 245 2220 HFLOT 1 49 LU 1 50 Joel NEXT I 7540 HGOCOLOR 0
34. ew made to the value of SC and a check is made to see if the SEMI x COLON game 1s won As you might expect it s also the most difficult 2 15 USED m section of program eC OF pnr NEXT Line 3010 moves the cursor to line twenty three and changes INEO n OTH HER the color to yellow Three blank spaces cover over the old 0 E UT SPACES input and the cursor is moved back three spaces to the start TRET WEEN of the line INPUTC causes a question mark and flashing Cursor to appear on the screen to prompt the player The second part of line 3020 makes sure that C only contains one character Line 3030 prints the guess on the fifth row down the screen The variable LI 1s used so that the first guess 1s printed in the first space across the second m the second space and so on T BE ELETIER 2019 2200m SAFA 1 1 15 3030A PRINT SPOOL 3848 cose E 3956 FOR F 1 TO LE 3868 IF 1 THEM 3188 Sua C1 SC Z2L 1 ABS WESLEF TEC 1 9 R IGHTECHE O PRINTLEFTECUDS 120 TREER PCP 1273 SI HEST mE C 3118 IF SC LE THEN Wo 1 a2 4 il RET LPH Line 3040 sets the value of CO at zero so that the program goes to the hangman subroutine valid letter 1
35. g the course of the program When you want the computer to do something with the information you must refer to 1t 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 variable 1s one in which the information stored will always be numbers If the data to be stored consists of letters or words then a string variable must be used The variable name must then be followed by the string sian So for example if you wanted a name stored the statement would read LET N JAMES otring variable information must always be in quotes Index C M Color 9 Z3 24 28 30 31 32 34 mode 8 30 35 410 49 1 90 39 control codes 8 9 N numeric variables 44 D DATA 12 13 19 20 26 42 P delay 33 39 pixel 28 31 42 POKE 28 29 30 31 32 33 37 G 42 graphics coordinates 8 28 29 20221 34 32 05 90 94 R random choice 13 19 20 43 H RESTORE 13 20 HGR 9 14 30 42 REVERSE 9 34 38 39 HPLOT 26 29 51 32 33 42 I INPUT 16 17 18 25 42 INT 20 42 S saving programs 18 25 40 screen backgrounds 9 21 24 SL O8 94 0 Oo sound 26 string variable 13 16 17 20 23 25 44 Subroutine 10 11 19 20 21 22 23 24 25 39 T tape recorder 18 25 44 Design Cooper West Program editors oteve Rodgers Marcus Milton Illustrators Lionel Jeans Rob Shone 45 SIRIA ET E THIS NEW RIES
36. hics we will also add belt and shoes to give the hangman detail The belt is colored medium gray tis 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 U 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 15 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 turns downward H _ WHEN THE PROGRAM 5 RUN THE SCREENS SHOULD SHOW AS FLOW WHEN YOU START WIN LOSE Comm noe emos m UNUM E Roe EER gt E SAN SOR UR WELL DONE YOUR EXECUTION HAS BEEN POSTPONED DO YOU WISH PI_RY ADAIN 1 DO YOU WISH TO PLAY AGAIN a a o CC UMEN i O x no 39 f Improving your program 2 Now that you have the complete program typed in you should save it on tape The method for storing programs 15 given in the use
37. iable there 1s no need to place it in quotation marks The last subroutine 1s the one which asks the player if he or she wants to play another game This 1s a routine which you could include in any other program that you might write The INPUT asked for in line 6030 1s checked in line 6040 to see if itisa 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 Bye in light red O O O O REM PLAY HGHIH sl YOU WISH TO FRIHT FLAY AGAIN Hf IF LEFTS A 139 4 THEH 18 PEINT CIMININININININLSISISER EYE Bre Mot IE ee 2 m Cum cU 400 x A Wa T Ts c TM oT C CD A GIRI iE Apart from the graphics contained in the hangman subroutine the program is now complete At this point it isa good idea to save the program on tape Connect the tape recorder as instructed in the manual Then type SAVE HANG 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 HANG and then press RETURN If the recording is good the computer will report VERIFYING If there are any errors S
38. iven in the final section of the book The graphics are used in the winning and losing subroutines that follow The win routine 15 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 4440 4818 PRINT FOR L 5 TO 19 C 4058 L 5 GOSUBP Sag TEHA 700 4440 HEAT 4050 FRIHTLEFT CZUID O YELL DOHE 4558 HAS BEEN POSTFOHEI 4076 RETLEH 24 C589 Salty TOJE EZXECLITICOH O O O Sama REM LOSE O Sela PRIHT 77 sam FOR TO 16 O S838 L_GOSUE7108 7200 7300 7400 7588 7600 7706 TEAR 7900 SOG O 5940 SASA PRINT AN ENAVIEH FOOL Saga PRINT a WO LOST O sa PRIHT NBMBBITHE WORD WASH PRIHTSEC 531 SASA 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 se ectword subroutine 1s displayed on the screen by line 5070 Notice that when you ask the computer to display a string var
39. life 1s lost the computer draws the third section of the gallows This is the cross bar between the first two beams It 15 made up of a single diagonal using the HPLOT instruction REM GALLOWS HCOLOR 1 Arey 9 TL SIN I 7400 REM ROPE Oo 7410 HCOLOR 2 O vaso HPLOT 254 29 TO 254 15 284 29 TO 23 44 320 RETURN Next a rope 1s added for the fourth life lost This 1 simply a line drawn from the middle of the gallows extending downwards for 14 vertical coordinates To test the graphics written so far follow the instructions the box below 70 TEST THE GALLOWS SECTION OF GRAPHICS a ADD REM AT THE START OF LINES 7 50 7250 AND 7330 b TYPE HGR GOSUB 7100 c PRESS RETURN TAKE OUT THE ADDITION BEFORE YOU PROCEED TO THE NEXT SECTION The next stage of the hangman subroutine will draw the man himself In HGR there are only eight colors available we will use six 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 5 The first stage of drawing the man is the face This 1s a block of color made up of straight vertical lines drawn close together using a loop in lines 7510 to 7530 The color is changed to draw the eyes still using the HPLOT command Line 7550 draws a straight line for the mouth and line 7570 draws the nose The
40. ll if PO 1 or PO LE To avoid this line 3062 sets up temporary string variables W 1 and W238 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 selectword subroutine Finally the value of CO is changed to 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 s given the value of 1 and the game 15 Won LETTER 7 COMPUTER S WORD IS B FFALD 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 4000 REM WIN 4310 HOME HOF 4020 FOR k 4 TO 10 4050 OM i 4 7500 7600 7700 7900 79700 8000 4040 NEXT 40500 VITAE 21 HTAR PRINT WELL DONE YOUR a wl ee I TON 4060 PRINT HAS BEEN 4070 RETURN 17 IN ORDER TO TEST SUBROUTINE CHOOSELETTER IT MUST BE RUN WITH THE REST OF THE PROGRAM a ADD REM AT THE START OF LINE 60 AND LINE 2030 b TYPE RUN PRESS RETURN DELETE THE ADDITIONS ABOVE WHEN YOU ARE READY TO PROCEED SRR PLE
41. nd The position 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 Line 7760 draws in the hands using the HPLOT command 7700 REM ARM 1 7710 HCOLOR 5 7720 FOR I 215 TO 218 7730 HFLOT 1 55 TO 1 105 7740 NEXT 1 _ 7750 HCOLOR 3 7780 HFLOT 214 106 TO 214 110 TO 318 110 TO 218 106 7770 RETURN Jm The second arm is built up in exactly the same way as the first only the horizontal coordinates change to position the arm on the other side of the body HCOLOR in line 7810 sets the graphics color back to red ARM C 7810 f FOR 1 25e TO 237 7830 JJPLUT 1 55 1 103 7840 NEXT I _ 78500 HCOLOR 2 2322106 TO TH 7370 RETURN The first 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 6 Then the loop is set up using FOR NEXT and HPLOT draws in the color The shoe 1 built up in the same manner 7900 REM LEGI 7910 HCOLOR 6 7920 FOR I 220 TO 7950 APLOY 43100 TO 7940 NEXT I 7950 HCOLOR 7 7960 FOR I 141 TO J97 SISE TU 7980 NEXT I 7990 RETURN SSIS NE Seca a TTE 5000 REM SOLO HCOLOR 6 BOLO FOR I 53 TO 250 HFLOT 1 100 TO 1 140 8040
42. ne 3040 the variable CO 1s set at zero so that the program goes to the hangman subroutine if a valid letter 1s not chosen Look back at line 60 of the main program to see why SOG REM EOE LETTER 21 HTAR 24 OBO LET WE WE ao90 VITAE 24 P 29 PRINT CEs OL NEXT F LIO LE Sl THER LET WO I 2120 RETURN 25472210 tee fe LEN tif 4 gt 1 THEN 37010 O JOIO VTAR 24 HTAR LI 16 PRINT CE A040 LET CO cg Sat POR F 1 TO LE O A060 IF Cd lt gt MIDE CAs os SILO LET Wik Fe LIT WIE TU C 2064 IF F zx gt 1 THEN Wisk LEFT WE FP 1 A060 Ife gt E THEN WEE RIGHTS F O N LET CO Le LET SU SL 1 O O CERI irae nes Transm sd E OR TEORIE TT Ol tn Lines 3050 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 5 At this point the value of MID will be 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 RIGHTS to be zero as it wi
43. need to program both the screen and color memory maps The top of the face is made using the graphics on keys U E and I 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 J Rand K 7500 REM FACE P510 PRINTERS 7520 PRIMTSPC TA 7530 FURR BTUZ PRIMTSPCQ2 O O 7546 PRINTSPCC2TO TIM _ 7598 PRINTSPCCZE2 PRIHTZPC 29 C EFI FE Foo A The details of the face are created by one line in the program line 7550 which gives two plus s for the eyes a colon for the nose and a line for the mouth place these in position the cursor has been moved up four rows at the end of the 7540 Unless a print statement ends with a semi colon or a comma the cursor moves down one line 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 in line 7610 The FOR NEXT loop prints 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 Another reversed O is printed two rows below that This produces two round buttons on the hangmans coat If you wanted to you could use a similar command to give the hangman pockets by using two subtraction s
44. omes into operation after a m 10 guess has been made Line 70 returns the program to this point for another guess to be made The subroutine called up STATE in line 50 chooseletter allows the player to make a m RE USEFUL guess At line 60 the program goes to the hangman routine EMIND 1 TE p idi which contains the graphics for the game The value of is E AC set at zero if an incorrect guess 1s made the chooseletter routine Finally there are routines which come into play the game 1s 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 dont 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 1s complete IHTH APPLE RHGLE ASTEROID BOTTLE BOOK BUFFALO BEACH 19 FEM 1065 LITER Lede Lede TINTA 1818 8 SELECTWORD O O 1828 RESTORE atat 1639 CHsIMTCORHIECEOKM 1 1640 F R 1 1 TO CH 1059
45. rs manual Why not try to build completely different graphics Apple The program listing bel w gives the complete Hangman game Those program lines marked with an asterisk are additional to the program given in the main part of the book 10 HGR HOME 20 GOSUB 1000 REM SELECTWORD GOSUEB 2000 REM TITLE 45 IF WO 1 OR LO 1 THEN BO 50 GOSUR 2000 REM CHOOSELETTER ou IF CO o THEN GOSUB 7000 REM HANGMAN 7 GOTO 40 guo 1 WO 1 THEN GOSUB 4000 WIN 90 IF LO 1 THEN GOSUB 5000 LOSE 100 GOSUB 6000 REM FLAY AGAIN 110 STOR loo SELECT WORD 1010 LET Wes B 1020 RESTORE LOZO LET CH INT t AND ti a WI 1040 FOR L 1 TO CH 1059 READ WI 1960 NEXT L 1O70 LET LE LEN Wf LET DI WI 1080 RETURN 2000 REM TITLE 29109 HGR HOME 2020 FOR 4 TO 1o 2050 ON 4 GOSUB 72500 7600 7700 7800 7900 8000 2040 NEXT L 2050 VTAB 21 14 PRINT H AN GM N 2060 VTAB DI HTAB 10 INFUT PRES RETURN TO START HOME HGA 24 i FRAINT LETTERS CHOGEN 20960 VTAB 22 28 FRINT C MFU TER G 2100 VTAB 22 3a PRINT WORD IS 2110 24 HTAB 30 2120 FOR L 1 TO LE PRINT NEXT L 2420 VITAE 21 HTAB 1 PRINT PLEASE CHOOSE A LETTER 2150 LET WO LET LO c LET LI LET SC 2150 RETURN 3000 REM CHOOSE LETTER 3010 21 HTAR 24 30270 INPUT Ct IF LEN CH gt 1 THEN 3010 VTAB 24 HTAB LI
46. start position and the number of characters to be copied This instruction looks at a particular memory location It 1s often associated with POKE This represents a point on the grid in graphics mode The number of pixels per screen is determined by the quality of the graphics e g highor low resolution mode This stores numeric information in the computers memory It IS often used for sound and places a binary number in a particular location This tells the computer to display something on the screen Letters and symbols that are to be displayed should be enclosed in quotation marks but numbers need not be Similar to LEFT but copies the right hand end of a string 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 1 To obtain random whole numbers it must be multiplied and made a whole number by the INT statement The STEP statement is always used following a statement It indicates the amount that the variable should be changed for each operation For example FOR X 0 TO 20 STEP 5 PRINT X NEXT X Would mean that X would rise in steps of five so that the computer would print 0 5 10 15 20 43 Variables When you give the computer information you have to give it a label under which itis stored This label is called a variable since the information it contains may change durin
47. user and waits for the input to be given and carriage return to be pressed INT is short for integer and instructs the computer to make a whole number of a figure with decimal places in it It 1s often used in conjunction with the RND command which instructs the computer to generate a random number see below 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 LIST MID PEEK PIXEL POKE PRINT RIGHTS RND STEP This 1s one way of giving the computer information In some programs there may be statements such as X 10 This simply means that the number ten 1 stored under the label X It is often clearer to write LET X 10 lhe LET statement also gives rise to something that at first sight seems 1llogical if not Impossible In many programs you will see things like LET X X Of course in mathematical terms X can t equal X 1 All this type of statement means is increase the value of whatever is stored in X by one This makes the computer display whatever program it has in its memory You can LIST single lines or parts of a program by following the LIST with appropriate line numbers This 1s used to copy the middle part of a string It is followed in brackets by the string name the
48. ymbols It s a good idea to run the program at this point to check that you ve positioned the body correctly cen REM EOD O rnit PEIMT USBBSMENSSBE ref HET rece PRINT UTITTINSPOC 290 30 PRINTSPO ZA sig O rede 37 For the next life lost an arm 1s added to the hangman This 1s made in three parts shoulder arm and hand The shoulder 1s made from two blocks reversed spaces on top of each other in line 7720 To separate the arm from the body a block with a bit of space missing on the right hand side 15 needed N produces a line on the right so by printing it in reverse the required space is formed Line 7130 gives a three line loop ut which makes the arm The hand is represented by an 7700 REM ARMI O 7719 PRINT O O 7720 F ERSBIDI PRIMTSPDOPTO S SHEET P730 FORRSOTOZ PRIMTSPCS7 A HET O 2248 PEIHTSPEC2TS n O 7750 The next life lost produces the second arm This 1s created in exactly the same way as the first Only the number in SPC changes to place the arm on the right hand side of the body The H is used to separate this arm REM ARMS PELO PRINT T7E2B F RR BTOUI PRIHTSPCOBI2 S 7O20 F RE BTIDSOPRIHTSPCOGi io CHEST PRINTF GI n PHSB RETURH The next part of the hangman to be added is the legs

Download Pdf Manuals

image

Related Search

Related Contents

Brenthaven 1800 backpack  Formation VIPR FONDAMENTAUX  Mode d`Emploi - Recherche état civil  Manual do proprietário  ChangeBASE 5.3 - User Guide  KPS-X30 取扱説明書  Agilent G2565AA and Agilent G2565BA Microarray Scanner System  Art.-Nr.: 45.017.20 I.  2.0 User Manual GPS  Features  

Copyright © All rights reserved.
Failed to retrieve file