COMMANDS
Key in program and type RUN.
100 REM Program P10 - WHEEL OF FORTUNE 110 MODE 6 120 PRINT TAB(5,5)"GOOD EVENING friends and" 130 PRINT TAB(5,6) "WELCOME to the ELECTRON" 140 PRINT TAB(5,8)" WHEEL OF FORTUNE" 150 PRINT TAB(5,10)"Why don't you step up and" 160 PRINT TAB(5,11) "try your luck? Pick a " 170 PRINT TAB(5,12) "number between 1 and 30" 180 PRINT TAB(5,13)"and gamble away" 190 PRINT ''''"Press any key to continue" 200 Z=GET 210 REM Draw WHEEL OF FORTUNE 220 MODE 1 230 VDU 29,640;512; 240 VDU 19,0,2;0;0;0 250 VDU 23,1,0;0;0;0; 260 GCOL 0,1 270 MOVE 400,0 280 A=0 290 REPEAT 300 MOVE 0,0 310 PLOT 85,400*COS(A),400*SIN(A) 320 A=A+.1 330 PLOT 85,400*COS(A),400*SIN(A) 340 A=A+.1 350 UNTIL A>2*PI+.01 360 GCOL 0,2 370 FOR I=0.1 TO 2*PI STEP PI/15 380 MOVE 0,0 390 DRAW 400*COS(I),400*SIN(I) 400 NEXT I 410 REM Put on numbers 420 FOR N=1 TO 30 430 PRINT TAB(400*COS(N/15*PI)/32+20,32-400*SIN(N/15*PI) /32-16);N 440 NEXT N 450 REM Start wheel 460 PRINT TAB(0,31)"Press any key to start"; 470 Z=GET 480 PRINT TAB(0,31)" "; 490 REM get time to spin 500 TIME=0 510 T=(RND(10)+2)*300 520 REPEAT 530 A=TIME/600*PI 540 MOVE 0,0 550 GCOL 3,3 560 DRAW 400*COS(A),400*SIN(A) 570 SOUND 3,-10,53,1 580 GCOL 3,3 590 MOVE 0,0 600 DRAW 400*COS(A),400*SIN(A) 610 UNTIL TIME>T 620 GCOL 0,3 630 MOVE 0,0 640 DRAW 400*COS(A),400*SIN(A) 650 END
P11 Mastermind
This program implements the first version of the popular game by INVICTA, Ltd.
The object of the game is to determine the colour of the four squares on the screen, the uer has up to twenty attempts at working out the code.
When you enter an attempt, the computer responds by indicating whether you have a coloured square in the correct position, or whether you have a correctly coloured square, but it is in the wrong position.
For each correct square in the correct position, the computer places a magenta dash to the right of the guess.
For each correct square in the wrong position the computer places a cyan (light blue) dash to the right of the guess.
COMMANDS
Key in program and type RUN.
Enter guess as e.g. RGYB.
100 REM Program P11 - Mastermind 110 MODE 2 120 VDU 19,0,7,0,0,0 130 VDU 19,7,0,0,0,0 140 DIM colour(3),guess(3),temp(3) 150 VDU 23,224,255,255,255,255,255,255,255,255 160 PRINT TAB(2,0) CHR$(224);" ";CHR$(224);" ";CHR$(224);" ";CHR$(224) 170 line=0 180 FOR I=0 TO 3 190 colour(I)=RND(3)+1 200 temp(I)=colour(I) 210 NEXT I 220 REPEAT 230 line=line+1 240 FOR I= 0 TO 3 250 colour(I)=temp(I) 260 NEXT I 270 COLOUR 7 280 PRINT TAB(0,29); 290 REM Program will be unsatisfactory if more than 4 ch aracters are input 300 INPUT "Enter colour pattern eg: RGYB " patt$ 310 PRINT TAB(3,23) STRING$(40," "); 320 FOR I= 0 TO 3 330 guess(I)=0 340 IF MID$(patt$,I+1,1)="R" THEN guess(I)=1 350 IF MID$(patt$,I+1,1)="G" THEN guess(I)=2 360 IF MID$(patt$,I+1,1)="Y" THEN guess(I)=3 370 IF MID$(patt$,I+1,1)="B" THEN guess(I)=4 380 COLOUR guess(I) 390 PRINT TAB(2+I*2,line);CHR$(224); 400 NEXT I 410 pc=0:cc=0 420 FOR I=0 TO 3 430 IF guess(I)=colour(I) THEN pc=pc+1:colour(I)=10:gu ess(I)=11 440 NEXT I 450 FOR I=0 TO 3 460 FOR J=0 TO 3 470 IF guess(I)=colour(J) THEN cc=cc+1:colour(J)=10: J=3 480 NEXT J 490 NEXT I 500 IF pc>0 THEN PROCposn 510 IF cc>0 THEN PROCcolour 520 UNTIL pc=4 OR line=20 530 COLOUR 7 540 IF pc=4 THEN Z=INKEY(200):CLS:PRINT TAB(0,12) "W E L L D O N E !!",TAB(0,14);"YOU TOOK "line" ATTEMPTS" :END 550 CLS 560 PRINT '''''"THE CORRECT CODE WAS" 570 FOR I=0 TO 3 580 COLOUR temp(I) 590 PRINT TAB(2+I*3,12) CHR$(224); 600 NEXT I 610 PRINT 620 END 630 640 DEF PROCposn 650 FOR I=1 TO pc 660 COLOUR 5 670 PRINT TAB(10+I*2,line) CHR$(224); 680 NEXT I 690 ENDPROC 700 710 DEF PROCcolour 720 FOR I=1 TO cc 730 COLOUR 6 740 PRINT TAB(10+pc*2+ I*2,line) CHR$(224); 750 NEXT I 760 ENDPROC
P12 Guess the Number
In this simple game the user has to try to outguess the computer. The computer selects a random whole number between 1 and 100, and the user has to find it out.
The instructions for this program are included within the code.
COMMANDS
Key in program and type RUN.
Follow instructions.
100 REM Program P12 - Guess the Number 110 MODE 2 120 PRINT TAB(2,14);"GUESS THE NUMBER " 130 Z=INKEY(300) 140 MODE 1 150 COLOUR 2 160 PRINT '''"In this program you attempt to " 170 PRINT "outguess the computer. You will be" 180 PRINT "prompted to guess a number between" 190 PRINT "0 and 100. If you guess wrongly" 200 PRINT "the computer will tell you if you are" 210 PRINT "too low or too high. When finished" 220 PRINT "the computer will give you your" 230 PRINT "average number of attempts to " 240 COLOUR 1 250 PRINT ''"GUESS THE NUMBER" 260 COLOUR 2 270 PRINT '''"Press any key to start" 280 Z=GET 290 300 CLS 310 goes=0 320 attempts=0 330 340 REPEAT 350 goes=goes+1 360 number=RND(TIME) MOD 100 370 correct=0 380 390 REPEAT 400 PRINT TAB(0,12);"Enter your guess "; 410 INPUT guess 420 CLS 430 IF guess<number THEN COLOUR2:PRINT TAB(0,12);"Too low" 440 IF guess>number THEN COLOUR2:PRINT TAB(0,12);"Too high" 450 IF guess=number THEN COLOUR 1:PRINT TAB(0,12);"Cor rect":correct=-1 460 Z=INKEY(300) 470 attempts=attempts+1 480 UNTIL correct 490 500 CLS 510 PRINT TAB(0,12);"Another go (Y/N)"; 520 INPUT a$ 530 UNTIL a$<>"y" AND a$<>"Y" 540 550 CLS 560 average=attempts/goes 570 PRINT TAB(0,12);"You took an average of "average" per shot" 580 IF average<7 THEN PRINT TAB(0,15)"P R E T T Y G O O D " 590 END
P13 Reaction Test
This program could help your keyboard skills. The computer places a random character on the screen and starts to time your response.
The object of the game is to press the required key as fast as possible.
When the program is complete an average reaction time is displayed on the screen.
COMMANDS
Key in program and type RUN.
100 REM Program P13 - Reaction Test 110 MODE 6 120 PRINT TAB(12,12)"REACTION TEST" 130 Z=INKEY(300) 140 CLS 150 PRINT TAB(0,12)"How many tries do you want"; 160 INPUT no_of_attempts 170 PRINT "Press any key to start":Z=GET 180 FOR letter=1 TO no_of_attempts 190 CLS 200 TIME=0 210 X=RND(39):Y=RND(24) 220 A$=CHR$(RND(25)+65) 230 PRINT TAB(X,Y) A$ 240 REPEAT 250 B$=GET$ 260 UNTIL B$=A$ 270 tot_time=tot_time+TIME 280 NEXT letter 290 300 CLS 310 PRINT TAB(0,10)"Number of attempts "no_of_attempts 320 PRINT "Total time ";tot_time/100" seconds" 330 PRINT "Average reactin time was ";tot_time/no_of_attem pts/100;" seconds" 340 END
P14 Gobble
In this program we show the effects of simple graphics.
We have two beasties eating up a field of grass. This is a two-player game, with each player taking the part of one of the beasties.
W | |||
Player 1 uses keys | A | S | |
Z |
| |||
Player 2 uses keys | ; | : | |
/ |
Player 1 | moves up and down using keys | W and Z |
moves left and righ using | A and S | |
Player 2 | moves up and down using keys | and / |
moves left and right using | ; and :. | |
Every time a piece is eaten points are scored.
COMMANDS
Key in program and type RUN.
Use keys as described above.
100 REM Program P14 - Gobble 110 120 REM Set up board 130 MODE 5 140 VDU 19,0,2;0; 150 VDU 23,1,0;0;0;0 160 GCOL 0,3 170 MOVE 0,0 180 DRAW 1279,0 190 DRAW 1279,1023 200 DRAW 0,1023 210 DRAW 0,0 220 230 REM Initialize parameters 240 DIM X(2),Y(2),DX(2),DY(2),score(2) 250 X(1)=16:X(2)=1263:Y(1)=512:Y(2)=512 260 PLOT 69,8,512:PLOT 69,1271,512 270 A=1:B=2 280 gameover=FALSE 290 flag=0 300 310 REM Play game 320 REPEAT 330 DX(1)=(INKEY(-86)-INKEY(-82))*8 340 DX(2)=(INKEY(-88)-INKEY(-73))*8 350 DY(1)=(INKEY(-98)-INKEY(-34))*4 360 DY(2)=(INKEY(-105)-INKEY(-58))*4 370 FOR I=A TO B 380 IF DX(I)+DY(I)=0 THEN VDU 0 ELSE IF POINT(X(I)+DX( I),Y(I)+DY(I))<>0 THEN PROCbang(I) ELSE PROCmove(I) 390 NEXT I 400 UNTIL gameover 410 420 REM Display result 430 MODE 6 440 PRINT TAB(0,12);"Player 1's score is ";score(1); 450 PRINT TAB(0,16);"Player 2's score is ";score(2); 460 PRINT 470 *FX15,0 480 END 490 500 510 DEF PROCbang(i) 520 SOUND 0,-15,53,4 530 IF i=1 THEN A=2 ELSE B=1 540 flag=flag+1 550 IF flag=2 THEN gameover=TRUE 560 ENDPROC 570 580 590 DEF PROCmove(i) 600 X(i)=X(i)+DX(i) 610 Y(i)=Y(i)+DY(i) 620 PLOT 69,X(i),Y(i) 630 score(i)=score(i)+1 640 ENDPROC
P15 Tennis
This is an adaptation of an old video game. We have two players playing tennis on a green pitch.
Player 1 uses keys Z and X to move his bat up and down.
Player 2 uses keys . and / to move his bat up and down.
The score is displayed at the top of the screen. There are a total of fifty balls available in the game, rather more than in the old video games.
This is an interesting program in that no graphics are used. All movements are accomplished by print statements.
Try using *FX11 and *FX12 commands to improve the program.
COMMANDS
Key in program and type RUN.
Player 1 uses | Z for up, |
X for down. |
Player 2 uses | / for up, | |
. for down. |
100 REM Program P15 - Tennis 110 MODE4 120 @%=2 130 balls_left=50 140 DIM goals(2) 150 VDU 19,0,2;0;19,7,0;0; 160 VDU 23,224,24,90,90,255,255,90,90,24 170 VDU 23,225,24,24,24,24,24,24,24,24 180 VDU 23,1,0;0;0;0; 190 ball$=CHR$(224) 200 unball$=" " 210 bat$=CHR$(225)+CHR$(10)+CHR$(8)+CHR$(225)+CHR$(10)+CHR $(8)+CHR$(225) 220 unbat$=" "+CHR$(10)+CHR$(8)+" "+CHR$(10)+CHR$(8)+" " 230 PRINT TAB(0,16);bat$;TAB(39,16);bat$; 240 player_1=16:player_2=16 250 X%=19:Y%=RND(27)+1 260 IF RND(4)>2 THEN DX%=-1 ELSE DX%=1 270 IF RND(4)>2 THEN DY%=-1 ELSE DY%=1 280 REPEAT 290 PRINT TAB(X%,Y%)unball$; 300 X%=X%+DX%:Y%=Y%+DY% 310 IF Y%<2 OR Y%>29 THEN PROCwall_bounce 320 PRINT TAB(X%,Y%) ball$; 330 PROCbat 340 UNTIL balls_left=0 350 360 PRINT "Finished, give me more money!!!" 370 REPEAT : UNTIL INKEY$(100)="Q" 380 END 390 400 DEF PROCwall_bounce 410 SOUND &11,-15,100,2 420 DY%=-DY% 430 ENDPROC 440 450 DEF PROCbat 460 key$=INKEY$(2) 470 D_player_1=(key$=CHR$(90))*-4+(key$=CHR$(88))*4 480 D_player_2=(key$=CHR$(46))*-4+(key$=CHR$(47))*4 490 temp_1=player_1+D_player_1 500 temp_2=player_2+D_player_2 510 IF temp_1<29 AND temp_1>-1 THEN PRINT TAB(0,player_1)u nbat$;:PRINT TAB(0,temp_1) bat$;:player_1=temp_1 520 IF temp_2<29 AND temp_2>-1 THEN PRINT TAB(39,player_2) unbat$;:PRINT TAB(39,temp_2) bat$;:player_2=temp_2 530 IF X%=39 AND ABS(Y%-player_2-1)<2 THEN SOUND &11,-15,1 00,2:DX%=-DX% ELSE IF X%=39 PROCscore(1) 540 IF X%=0 AND ABS(Y%-player_1-1)<2 THEN SOUND &11,-15,10 0,2:DX%=-DX% ELSE IF X%=0 PROCscore(2) 550 ENDPROC 560 570 DEF PROCscore(k) 580 SOUND &11,-15,64,4 590 balls_left=balls_left-1 600 goals(k)=goals(k)+1 610 PRINT TAB(k*10,0) goals(k); 620 PRINT TAB(X%,Y%) unball$; 630 X%=19 640 FOR I=1 TO 20:PROCbat:NEXT I 650 ENDPROC
P16 Bombs
In this program, the user has to defend his city against attacks from the sky.
The game is placed purely in text, with many user defined characters. The city is built up in lines 230 to 360.
The user has control of a laser gun which can be used to knock out bombs which appear at random at the top of the screen.
To control the gun we use the edit keys (hence the use of *FX4,1) to move horizontally and <COPY> to fire the gun.
The game finishes when the city is destroyed, which can take some time!
If you find the copy key too awkward to use then change line 480 to look for the space bar, thus:
480 IF K=32 AND FLAG=0 THEN PROCfire
If you find that the edit keys no longer work after playing this game, then use *FX4,0 to fix it.
COMMANDS
Key in program and type RUN.
Use cursor control keys to move gun.
Press <COPY> key to fire.
100 REM Program P16 - Bombs 110 FLAG=0:F=0 120 @%=&3 130 MODE4 140 VDU 19,0,5;0;19,3,7;0; 150 REM Define characters 160 VDU 23,224,255,153,153,255,255,129,129,255 170 VDU 23,225,24,126,231,219,219,231,126,0 180 VDU 23,226,231,102,60,24,24,24,24,24 190 VDU 23,227,0,0,0,24,24,0,0,0 200 SHELL$=CHR$(227) 210 BOMB$=CHR$(226) 220 D$=CHR$(225) 230 C$=CHR$(224) 240 C2$=C$+C$ 250 C3$=C2$+C$ 260 C7$=C3$+C2$+C2$ 270 C10$=C7$+C3$ 280 C16$=C7$+C7$+C2$ 290 C18$=C16$+C2$ 300 PRINT TAB(4,24)C3$+" "+C2$+" "+C3$+" "+C3$+" "+C3$ 310 PRINT" "+C3$+" "+C2$+" "+C3$+" "+C3$+" "+C 3$+" "+C3$ 320 PRINT" "+C3$+" "+C10$+" "+C16$ 330 PRINTC7$+" "+C10$+" "+C18$ 340 PRINTC7$+" "+C10$+" "+C18$ 350 PRINT" "+C3$+" "+C10$+" "+C18$ 360 PRINT" "+C3$+" "+C10$+" "+C18$ 370 A=20 380 *FX4,1 390 B%=RND(38) 400 Z%=1 410 MOVE 0,0 420 PRINTTAB(20,0)"Bombs landed ";:HIT%=0 430 PRINT TAB(0,0)"Bombs blasted";:Blast%=0 440 R%=A:S%=23 450 REPEAT 460 PRINT TAB(35,0)HIT%; 470 K=ASC(INKEY$(0)) 480 IF K=135 AND FLAG=0 THEN PROCfire 490 IF FLAG=1 THEN PRINT TAB(R%,S%-1)SHELL$;:PRINT TAB(R %,S%)" ";:PROCbang:S%=S%-1 500 K=(K=136)-(K=137)+(A=39)-(A=0) 510 PRINT TAB(A,23)" "; 520 PRINT TAB(A+K,23)D$; 530 A=A+K 540 G=1280*((B%)/40)+16:H=1023*((30.5-Z%)/32) 550 Q=(POINT(G,H)=1) 560 IF F=1 THEN PRINT TAB(B%,Z%)" ";:PRINT TAB(B%,Z%+1)B OMB$;:Z%=Z%+1 570 F=(F+1) MOD 3 580 IF Z%=30 OR Q THEN PRINT TAB(B%,Z%)" "+CHR$(8)+CHR$( 10)+" ";:Z%=1:B%=RND(38):HIT%=HIT%+1 590 UNTIL HIT%=555 600 END 610 620 DEF PROCfire 630 FLAG=1 640 R%=A 650 SOUND0,-15,67,2 660 ENDPROC 670 680 DEF PROCbang 690 T=(B%=R%) AND ((S%=Z%+1) OR (S%=Z%+2)) 700 IF T THEN SOUND 1,-15,53,2:Blast%=Blast%+1:PRINT TAB(1 4,0)Blast%:Z%=1:B%=RND(38) 710 IF T OR S%=3 THEN FLAG=0:PRINT TAB(R%,S%-1)" "+CHR$(8) +CHR$(11)+" ":R%=A:S%=23 720 ENDPROC
P17 Bat'n'Moths
This game developed from an idea of my wife's, who designed the various characters used in the game.
The object of the game is to control a bat to attempt to eat a set of moths which tilt about on the screen.
This can be a fairly difficult game, so there is a parameter 'D' which is used to slow down the moths. D can hold any value between 0 and 5, 4 being difficult.
As in P16, we use the cursor control keys to move the bat and COPY to gobble the moths. All four cursor keys are used to move the bat.
COMMAND
Key in program and type RUN.
Use cursor control keys to move bat.
Press <COPY> key to eat moth.
100 REM Program P17 -Bat'n'Moths 110 DIM X%(10),Y%(10) 120 DIM DX%(10),DY%(10) 130 MODE4 140 VDU 23,1,0;0;0;0; 150 160 FOR I=224 TO 229 170 READ B1,B2,B3,B4,B5,B6,B7,B8 180 VDU 23,I,B1,B2,B3,B4,B5,B6,B7,B8 190 NEXT I 200 REM define characters 210 M1$=CHR$(224):M2$=CHR$(225) 220 BAT$=CHR$(226)+CHR$(227)+CHR$(8)+CHR$(8)+CHR$(10)+CHR$ (228)+CHR$(229) 230 UNBAT$=" "+CHR$(8)+CHR$(8)+CHR$(10)+" " 240 REM change colours 250 VDU 19,0,4,0,0,0 260 VDU 19,1,3,0,0,0 270 INPUT "Number of moths (1 to 10) ",K:K=K-1 280 FOR I%=0 TO K:X%(I%)=RND(39):Y%(I%)=RND(31):NEXT I% 290 *FX4,1 300 INPUT "Difficulty (0 to 5)",D:D=5-D 310 CLS 320 BX=20:BY=16 330 PRINT TAB(BX,BY)BAT$; 340 FOR I%=0 TO K 350 DX%(I%)=1:DY%(I%)=1 360 NEXTI% 370 REPEAT 380 FOR I%=0 TO K 390 IF (X%(I%)+DX%(I%))>38 OR (X%(I%)+DX%(I%))<1 THEN DX%(I%)=-DX%(I%)*2 400 IF (Y%(I%)+DY%(I%))>30 OR (Y%(I%)+DY%(I%))<1 THEN DY%(I%)=-DY%(I%)*2 410 PRINT TAB(X%(I%),Y%(I%)) M1$; 420 NEXT I% 430 PROCbat 440 FOR I%=0 TO K 450 PRINT TAB(X%(I%),Y%(I%)) " "; 460 NEXT I% 470 FOR I%=0 TO K 480 X%(I%)=X%(I%)+DX%(I%):Y%(I%)=Y%(I%)+DY%(I%) 490 PRINT TAB(X%(I%),Y%(I%)) M2$; 500 NEXT I% 510 PROCbat 520 FOR I%=0 TO K 530 PRINT TAB(X%(I%),Y%(I%)) " "; 540 DX%(I%)=RND MOD 3 550 DY%(I%)=RND MOD 3 560 NEXT I% 570 *FX 15,1 580 UNTIL K=-1 590 *FX4,0 600 END 610 620 630 DEF PROCgulp 640 FOR I%=0 TO K 650 IF ABS(BX-X%(I%))>D OR ABS(BY-Y%(I%))>D THEN SOUND 1 ,-15,53,1 ELSE PROCsplat 660 NEXT I% 670 ENDPROC 680 690 DEF PROCbat 700 PRINT TAB(BX,BY) UNBAT$; 710 B=ASC(INKEY$(2)) 720 IF B=136 THEN BX=BX-1 ELSE IF B=137 THEN BX=BX+1 ELSE IF B=138 THEN BY=BY+1 ELSE IF B=139 THEN BY=BY-1 ELSE IF B=1 35 THEN PROCgulp 730 IF BY<1 BY=BY+1 ELSE IF BY>29 BY=BY-1 740 IF BX<1 BX=BX+1 ELSE IF BX>38 BX=BX-1 750 PRINT TAB(BX,BY) BAT$; 760 ENDPROC 770 780 DEF PROCsplat 790 ENVELOPE 1,2,1,0,3,1,1,1,0,0,0,0,0,0 800 SOUND 0,1,0,2 810 PRINT TAB(X%(I%),Y%(I%))" "; 820 FOR T%=I% TO K-1 830 X%(T%)=X%(T%+1) 840 Y%(T%)=Y%(T%+1) 850 NEXT T% 860 K=K-1 870 ENDPROC 880 890 900 DATA 129,129,195,231,255,231,195,129 910 DATA 36,102,102,102,126,102,102,36 920 DATA 130,130,129,195,199,195,225,227 930 DATA 65,65,129,195,227,195,135,199 940 DATA 231,255,255,239,231,197,137,156 950 DATA 231,255,255,247,231,163,145,57
P18 Monster Island
In this program you have landed on a volcanic island and are being pursued by voracious monsters.
Your only hope is to lead the monsters into volcanic pits, over which you can jump. The monsters always move in your direction, so with thought you should survive.
Your position on the island is shown by a small man shaped character. Use keys Z and X to move the man horizontally, / and : to move vertically.
The monsters do not notice you until you move.
Change lines 550 through 600 to improve the response of the game if you wish.
COMMANDS
Key in program and type RUN.
Use Z X / : to move man.
100 REM Program P18 - Monster Island 110 MODE 6 120 PRINT TAB(12,12)"M O N S T E R S" 130 INPUT TAB(5,20) "SPEED(1-5)"SPEED 140 MODE5 150 SPEED=6-SPEED:count=0 160 DEAD=FALSE 170 M=RND(5):F=RND(5)+5 180 DIM MONS(M,2),MAN(2) 190 L$=" " 200 VDU 23,224,31,124,200,248,248,120,60,31:REM Monster 210 VDU 23,225,60,126,255,254,254,62,30,28: REM Pool 220 VDU 23,226,28,28,8,127,28,20,20,54: REM Man 230 VDU 23,1,0;0;0;0;:REM Switch cursor off 240 FOR I=1 TO M 250 X=RND(19):Y=RND(31) 260 MONS(I,1)=X:MONS(I,2)=Y 270 COLOUR 1 280 PRINT TAB(X,Y) CHR$(224); 290 NEXT I 300 FOR I=1 TO F 310 X=RND(19):Y=RND(31) 320 COLOUR 3 330 PRINT TAB(X,Y) CHR$(225); 340 NEXT I 350 360 MAN(1)=RND(19):MAN(2)=RND(31) 370 DX=0:DY=0 380 COLOUR 2 390 PRINT TAB(MAN(1),MAN(2)) CHR$(226); 400 Z=GET 410 420 REPEAT 430 COLOUR 2 440 PRINT TAB(MAN(1),MAN(2)) CHR$(226); 450 DX=INKEY(-98)-INKEY(-67) 460 IF DX PROCmove(1,DX) 470 DX=0 480 DY=INKEY(-73)-INKEY(-105) 490 IF DY PROCmove(2,DY) 500 DY=0 510 count=(count+1) MOD SPEED 520 IF count=0 THEN PROCmonsters 530 UNTIL M=0 OR DEAD 540 550 IF M=0 THEN VDU 19,0,13;0; 560 FOR Z=1 TO 300:NEXT Z 570 *FX15,0 580 SOUND1,1,1,1 590 END 600 610 620 DEF PROCmove(I,d) 630 IF L$=" " THEN COLOUR 0 ELSE COLOUR 3 640 PRINT TAB(MAN(1),MAN(2)) L$; 650 IF MAN(1)+DX=19 OR MAN(1)+DX=0 DX=0 660 IF MAN(2)+DY=31 OR MAN(2)+DY=0 DY=0 670 L=FNchar(MAN(1)+DX,MAN(2)+DY) 680 IF L=224 OR L=128 PROCdie:ENDPROC 690 IF L=225 OR L=129 THEN L$=CHR$(225) ELSE L$=" " 700 COLOUR 2 710 PRINT TAB(MAN(1)+DX,MAN(29+DY) CHR$(226); 720 MAN(1)=MAN(1)+DX 730 MAN(2)=MAN(2)+DY 740 ENDPROC 750 760 DEF PROCdie 770 VDU19,0,9;0; 780 SOUND 1,-15,23,100 790 DEAD=TRUE 800 FOR Z=1 TO 300:NEXT Z 810 ENDPROC 820 830 DEF PROCmonsters 840 FOR I=1 TO M 850 CX=SGN(MAN(1)-MONS(I,1)) 860 CY=SGN(MAN(2)-MONS(I,2)) 870 L=FNchar(MONS(I,1)+CX,MONS(I,2)+CY) 880 IF L=225 OR L=129 PROCmonskill:GOTO 970 890 COLOUR 1 900 IF L=226 OR L=130 PRINT TAB(MONS(I,1)+CX,MONS(I,2)+C Y) CHR$(224);:COLOUR 0:PRINT TAB(MONS(I,1),MONS(I,2)) " ";:P ROCdie:ENDPROC 910 COLOUR 0 920 PRINT TAB(MONS(I,1),MONS(I,2)) " "; 930 COLOUR 1 940 PRINT TAB(MONS(I,1)+CX,MONS(I,2)+CY) CHR$(224); 950 MONS(I,1)=MONS(I,2)+CX 960 MONS(I,2)=MONS(I,2)+CY 970 NEXT I 980 ENDPROC 990 1000 DEF PROCmonskill 1010 SOUND 0,-15,10,2 1020 COLOUR 0 1030 PRINT TAB(MON(I,1),MONS(I,2))" "; 1040 IF I=M THEN M=M-1:ENDPROC 1050 FOR J=1 TO M-1 1060 MONS(J,1)=MONS(J+1,1) 1070 MONS(J,2)=MONS(J+1,2) 1080 NEXT J 1090 M=M-1 1100 ENDPROC 1110 1120 DEF FNchar(u,v) 1130 PRINT TAB(u,v); 1140 A%=135 1150 =(USR(&FFF4) AND &FF00)/&100
P19 Battleships
This is an implementation of the old schoolboy game of battleships. The game is played in Mode 5 using a mixture of graphics and user defined characters.
The game opens by displaying a map of an area of sea in which an enemy fleet is deployed. The fleet consists of four battleships, eight cruisers and sixteen destroyers.
The map is displayed as a 26 by 18 square grid. A battleship occupies three contiguous grid locations, a cruiser two locations and a destroyer one location.
Thus out of a possible 486 squares, 44 (or approximately 10%) are occupied by enemy ships.
The positions of the enemy fleet are displayed on the screen when the computer allocates each ship's position but, when the whole fleet has been placed, the computer hides the fleet. You therefore have a few seconds in which to memorize the fleet positions.
Once the board is set up, the computer prompts you to enter a grid reference. If the position is occupied by a ship:
To improve the game, make the ships larger, this would give the player a better chance of achieving a good score.
COMMANDS
Key in program and type RUN.
Watch the screen carefully, then follow instructions.
100 REM Program P19 - Battleships 110 MODE 5 120 DIM POSNS(44,2) 130 VDU 23,225,0,0,12,12,0,0,0,0 140 VDU 23,224,73,42,28,63,248,28,18,17 150 ENVELOPE 1,4,90,-15,-15,10,20,20,126,0,0,-126,126,126 160 VDU 19,0,4;0; 170 VDU 5 180 FOR X=64 TO 1216 STEP 64 190 MOVE X,128:DRAW X,960 200 NEXT X 210 FOR Y=128 TO 960 STEP 32 220 MOVE 64,Y:DRAW 1216,Y 230 NEXT Y 240 MOVE 64,1000 250 FOR I=1 TO 18 260 PRINT CHR$(64+I); 270 NEXT I 280 MOVE 0,960 290 FOR I=1 TO 26 300 PRINT CHR$(64+I);CHR$(8);CHR$(10); 310 NEXT I 320 REM Set up board 330 L=0 340 GCOL 0,2 350 S$=CHR$(225) 360 FOR battle=1 TO 4 370 X=RND(14)+2:Y=RND(22)+3 380 DX=RND(3)-2:DY=RND(3)-2 390 IF DX=0 AND DY=0 THEN DX=1 400 FOR I=0 TO 2 410 PROCcheck(X+DX*I,Y+DY*I) 420 NEXT I 430 IF position_free PROCtab(X,Y):PRINT S$;:PROCtab(X+DX ,Y+DY):PRINT S$;:PROCtab(X+DX*2,Y+DY*2):PRINT S$;:PROCposns( 3) ELSE battle=battle-1 440 NEXT battle 450 460 FOR cruiser=1 TO 8 470 X=RND(14)+2:Y=RND(22)+3 480 DX=RND(3)-2:DY=RND(3)-2 490 IF DX=0 AND DY=0 THEN DX=1 500 FOR I=0 TO1 510 PROCcheck(X+DX*I,Y+DY*I) 520 NEXT I 530 IF position_free PROCtab(X,Y):PRINT S$;:PROCtab(X+DX ,Y+DY):PRINT S$;:PROCposns(2) ELSE cruiser=cruiser-1 540 NEXT cruiser 550 560 FOR destroyer=1 TO 16 570 X=RND(14)+2:Y=RND(22)+3 580 PROCcheck(X,Y) 590 IF position_free PROCtab(X,Y):PRINT S$;:POSNS(L+1,1) =X:POSNS(L+1,2)=Y:L=L+1 ELSE destroyer=destroyer-1 600 NEXT destroyer 610 VDU 19,2,4;0; 620 hits=0:miss=0 630 REPEAT 640 PROCgetposn 650 PROCcheck(X,Y) 660 IF position_free PROCmiss(X,Y):miss=miss+1 ELSE hits =hits+1:PROChit(X,Y) 670 UNTIL hits=44 680 MODE 6 690 PRINT TAB(0,12) "SCORE="hits-miss 700 END 710 720 DEF PROChit(X,Y) 730 GCOL0,1 740 PROCtab(X,Y):PRINT CHR$(224) 750 SOUND &10,1,100,100 760 ENDPROC 770 780 DEF PROCmiss(X,Y) 790 GCOL0,3 800 PROCtab(X,Y):PRINT CHR$(224) 810 SOUND &11,-15,53,10 820 ENDPROC 830 840 DEF PROCcheck(X,Y) 850 position_free=TRUE 860 FOR I=1 TO 44 870 IF X=POSNS(I,1) AND Y=POSNS(I,2) THEN position_free= FALSE:I=44 880 NEXT I 890 ENDPROC 900 910 DEF PROCposns(K) 920 FOR I=1 TO K 930 POSNS(L+I,1)=X+DX*(I-1):POSNS(L+I,2)=Y+DY*(I-1) 940 NEXT I 950 L=L+K 960 ENDPROC 970 980 DEF PROCgetposn 990 VDU 4:VDU 28,0,31,19,28 1000 PRINT "HITS= ";STR$(hits) 1010 INPUT TAB(0,30)"ROW= "R$,"COLUMN= "C$ 1020 X=ASC(C$)-64:Y=ASC(R$)-63 1030 VDU 26 1040 VDU 5 1050 ENDPROC 1060 1070 DEF PROCtab(X,Y) 1080 MOVE X*64,1020-Y*32 1090 ENDPROC