10REM BATTLESHIP - version 2C
20REM (c) M.Bobrowski 8'89
30:
40MODE7:PROCinstr:PROCsetup:MODE1:PRO
Cscreen:*FX15,1
50ONERRORIFERR=17PROCshow:ELSEPRINT:R
EPORT:PRINT" at line ";ERL:END
60REPEAT:REPEAT:REPEAT:VDU28,3,30,36,
28,12:INPUTTAB(12,0)"Target ? "Q$:X%=ASC
Q$-65:Y%=ASC(RIGHT$(Q$,1))-48:IFX%<0ORX%
>9ORY%<0ORY%>9VDU7:PRINTTAB(8,2)"Illegal
coordinates";:XX=INKEY(300)
70UNTIL(X%>=0ANDX%<=9)AND(Y%>=0ANDY%<
=9):IFS%?(X%+10*Y%)=128 VDU7:PRINTTAB(11
,2)"Already Shot!";:XX=INKEY(300)
80UNTILS%?(X%+10*Y%)<>128:PROCshoot:L
%=L%-1:VDU24,808;872;900;912;16,26,5,18,
0,1:MOVE 824,912:PRINT;L%;:GCOL0,3:COLOU
R3:VDU4
90IFL%=0VDU24,300;872;900;912;16,26:P
ROCtx("GAME OVER",496,912):PROCshow
110UNTILFALSE
120:
130DEFPROCsetup:DIMS% 99,H%(10):L%=55:
G%=0:sink=FALSE:FORI%=S%TOS%+99:?I%=0:NE
XT:VDU23,128,0,24,38,193,0,24,38,193,19,
3,3;0;19,2,6;0;19,0,4;0;:ENVELOPE1,1,0,0
,0,0,0,0,126,-1,0,-20,126,30:*FX202,32
140M%=4:Q%=0:REPEAT:FORJ%=0TO4-M%:D%=R
ND(2)-2:REPEAT:N%=RND(100)-1:H%=N%MOD10:
V%=N%DIV10:IFD%ANDH%<(10-M%)PROCchH(M%):
UNTILok:ELSEIFNOTD%ANDV%<(10-M%)PROCchV(
M%):UNTILok:ELSEUNTILFALSE
150Q%=Q%+1:H%(Q%)=N%:IFD%PROCsetH(M%)E
LSEPROCsetV(M%)
160NEXT:M%=M%-1:UNTILM%=0:FORI%=S%TOS%
+99:IF?I%=&FF ?I%=0
170NEXT:VDU7:PRINT'TAB(11)"Press Space
Bar ";:REPEATUNTILINKEY-99:ENDPROC
180DEFPROCchH(M%):ok=TRUE:FORI%=N%TON%
+M%-1:IFS%?I% ok=FALSE
190NEXT:ENDPROC
200DEFPROCchV(M%):ok=TRUE:FORI%=N%TON%
+(M%-1)*10STEP10:IFS%?I% ok=FALSE
210NEXT:ENDPROC
220DEFPROCsetH(M%):FORI%=N%TON%+M%-1:S
%?I%=Q%:NEXT:IFV%>0A%=N%-10+(H%>0):B%=N%
+M%-11-(H%<(10-M%)):FORI%=A%TOB%:S%?I%=&
FF:NEXT
230IFV%<9A%=N%+10+(H%>0):B%=N%+M%+9-(H
%<(10-M%)):FORI%=A%TOB%:S%?I%=&FF:NEXT
240IFH%>0S%?(N%-1)=&FF
250IFH%<(10-M%)S%?(N%+M%)=&FF
260ENDPROC
270DEFPROCsetV(M%):FORI%=N%TON%+(M%-1)
*10STEP10:S%?I%=Q%EOR&80:NEXT:IFH%>0A%=N
%-1+(V%>0)*10:B%=N%-1+(M%-1)*10-(V%<(10-
M%))*10:FORI%=A%TOB%STEP10:S%?I%=&FF:NEX
T
280IFH%<9A%=N%+1+(V%>0)*10:B%=N%+1+(M%
-1)*10-(V%<(10-M%))*10:FORI%=A%TOB%STEP1
0:S%?I%=&FF:NEXT
290IFV%>0S%?(N%-10)=&FF
300IFV%<(10-M%)S%?(N%+M%*10)=&FF
310ENDPROC
320:
330DEFPROCscreen:COLOUR2:FORI%=0TO4:PR
INTSTRING$(255,CHR$128);:NEXT:PRINTSTRIN
G$(5,CHR$128);CHR$30:VDU24,320;172;976;8
24;16, 24,84;24;1194;136;16, 24,280;860;
1000;990;16,26:MOVE0,0:DRAW0,1023:DRAW12
79,1023:DRAW1279,0:DRAW0,0
340MOVE280,860:DRAW280,990:DRAW1000,99
0:DRAW1000,860:DRAW280,860: MOVE320,172:
DRAW320,824:DRAW976,824:DRAW976,172:DRAW
320,172: MOVE84,24:DRAW84,136:DRAW1194,1
36:DRAW1194,24:DRAW84,24
350FORI%=400TO960STEP56:MOVEI%,248:DRA
WI%,808:MOVE400,I%-152:DRAW960,I%-152:NE
XT:VDU5:FORI%=0TO9:MOVE 348,288+I%*56:PR
INT;I%;:MOVE 416+I%*56,220:PRINT;CHR$(65
+I%):NEXT:VDU4:PROCtx("B a t t l e s h i
p s",308,966)
360GCOL0,1:VDU5:MOVE 408,912:PRINT"Sho
ts Left : 55"CHR$4:GCOL0,3:COLOUR3:VDU28
,3,30,36,28:ENDPROC
370:
380DEFPROCshoot:VDU5:MOVEX%*56+428,276
+Y%*56:K%=S%?(X%+Y%*10):S%?(X%+Y%*10)=&8
0:IFK%>128K%=K%EOR&80:D%=FALSE:ELSED%=TR
UE
390IFK%=0SOUND1,-10,10,10:GCOL0,3:PLOT
0,0,4:PLOT1,0,-8:PLOT0,-4,4:PLOT1,8,0 EL
SESOUND0,1,6,20:PROChit:GCOL0,1:PLOT0,-2
4,24:PLOT0,48,0:PLOT81,0,-48:PLOT0,-48,4
8:PLOT81,0,-48
400VDU4:IFsink PROCsink ELSEIFK%COLOUR
2:PRINTTAB(15,2)"Hit!";:COLOUR3:XX=INKEY
(300)
410ENDPROC
420:
430DEFPROChit:IFK%=1M%=3ELSEIFK%=2ORK%
=3M%=2ELSEIFK%>3ANDK%<7M%=1ELSEM%=0
440sink=TRUE:IFM%=0ENDPROC ELSEIFNOTD%
THEN470
450FORI%=H%(K%)TOH%(K%)+M%:IFS%?I%<>&8
0sink=FALSE
460NEXT:ENDPROC
470FORI%=H%(K%)TOH%(K%)+M%*10STEP10:IF
S%?I%<>&80sink=FALSE
480NEXT:ENDPROC
490:
500DEFPROCsink:G%=G%+1:IFM%=0PRINTTAB(
10,2)"Submarine";ELSEIFM%=1PRINTTAB(11,2
)"Frigate";ELSEIFM%=2PRINTTAB(11,2)"Crui
ser";ELSEIFM%=3PRINTTAB(7,2)"Aircraft Ca
rrier";
510PRINT" sunk";:FORI%=200TO8STEP-16:S
OUND1,-10,I%,(280-I%)/40:NEXT:XX=INKEY(4
00):sink=FALSE:IFG%<>10ENDPROC
520VDU19,2,9;0;:COLOUR2:PRINTTAB(4)"Wh
ole computer's fleet sunk";SPC10:PROCaga
in:ENDPROC
530DEFPROCshow:VDU28,3,30,36,28,12:COL
OUR3:PRINT" Missed ships are indicated b
y X."':VDU19,2,9;0;:GCOL0,2:VDU5:FORX%=0
TO9:FORY%=0TO9:Z%=S%?(X%+10*Y%):IF(Z%>0A
NDZ%<11)ORZ%>128MOVEX%*56+416,288+Y%*56:
PRINT"X"
540NEXT,:VDU4:PROCagain:ENDPROC
550:
560DEFPROCagain:COLOUR3:PRINTTAB(11)"P
ress Space ";:REPEATUNTILINKEY-99:CLS:VD
U19,2,6;0;:PRINTTAB(3)"Would you like to
play again"''TAB(12)"(Y/N) ? ";:REPEAT:
OSCLI"FX15,1":G$=GET$:UNTILINSTR("YyNn",
G$):IFINSTR("Yy",G$)RUN
570VDU22,7,10:END
580:
590DEFPROCinstr:PRINT'TAB(14)"BATTLESH
IPS"''"Find and sink 10 ships hidden in
the 10 by 10 grid."
600PRINT"The ships are as follows:"'"
One Aircraft Carrier";TAB(27)"- 4 squar
es"'" Two Cruisers";TAB(22)"- each 3 sq
uares"'" Three Frigates";TAB(22)"- each
2 squares"'" Four Submarines";TAB(22)"
- each 1 square."
610PRINT"No two ships will touch."''"T
here is a limit of 55 shots. To fire a s
hot enter the coordinates of the targets
quare and press RETURN. The coordinatesc
onsist of two characters:"'" the first
is a letter from A to J,"
620PRINT" the second is a digit from
0 to 9,"'"eg, D3, which is column 'D' an
d row '1'."''"A miss is denoted by a sma
ll cross and a hit - by a red square."
:ENDPROC
630DEFPROCtx(a$,x,y):VDU18,0,2,5:FORyy
=y-4TOy+4STEP4:FORxx=x-4TOx+4STEP4:MOVEx
x,yy:PRINT;a$;:NEXT,:GCOL0,0:MOVEx,y:PRI
NT;a$;:VDU18,0,3,4:ENDPROC