2 PRINT"WELCOME TO THE CLASSIC GAME OF 'BATTLESHIP'. YOU AND THE" 3 PRINT"COMPUTER WILL TRY TO FIND EACH OTHER'S 5 SHIPS HIDDEN IN A" 4 PRINT"10 X 10 GRID. POINTS ON THE GRIDS ARE IDENTIFIED BY ROW AND" 5 PRINT"COLUMN. 6,7 FOR EXAMPLE SPECIFIES THE POINT WHERE ROW 6 AND" 6 PRINT"COLUMN 7 CROSS. YOU WILL NOW HIDE YOUR SHIPS. GOOD LUCK!" 7 CLEAR 10:RUN 10 10 DIM A$(5),S(5),L$(5),M$(11,11),C$(10,10),H$(11,11),X(4),Y(4),S$(4) 20 FOR I=1 TO 5:READ A$(I),S(I),L$(I):NEXT 30 DATA AIRCRAFT CARRIER,4,A,BATTLESHIP,3,B,CRUISER,2,C 31 DATA SUBMARINE,2,S,PT BOAT,1,P 33 FOR I=0 TO 11:FOR J=0 TO 11:M$(I,J)=" ":H$(I,J)=".":NEXTJ,I 35 FOR I=1 TO 10:FOR J=1 TO 10:M$(I,J)=".":C$(I,J)=".":NEXTJ,I 36 FOR I=1 TO 4:S$(I)=" ":NEXT 40 PRINT"ENTER THE ENDPOINTS OF YOUR SHIPS, TOP TO BOTTOM OR LEFT TO" 45 PRINT"RIGHT, THE NUMBER INDICATES THE LENGTH OF THE SHIP." 60 FOR I=1 TO 5:GOSUB 1000 65 PRINT A$(I);S(I)+1;:INPUT X1,Y1,X2,Y2 70 IF X1>10 OR X2>10 OR Y1>10 OR Y2>10 THEN PRINT"YOU GOOFED":GOTO 65 80 IF X1<>X2 AND Y1<>Y2 OR X1<1 OR X2<1 OR Y1<1 OR Y2<1 THEN PRINT"YOU GOOFED":GOTO 65 99 IF X2-X1<>S(I) AND Y2-Y1<>S(I) THEN PRINT"YOU GOOFED":GOTO 65 101 FOR J=X1 TO X2:FOR K=Y1 TO Y2 110 IF M$(J,K)<>"." THEN PRINT "2 SHIPS CANNOT OCCUPY THE SAME SPOT":GOTO 65 120 NEXT K,J 130 FOR J=X1 TO X2:FOR K=Y1 TO Y2:M$(J,K)=L$(I):NEXT K,J 140 NEXT I:GOSUB 1000:PRINT:PRINT"I WILL NOW HIDE MY SHIPS." 142 CD=INT(RND(1)*3+1):IF CD=1 THEN C1=2:C2=1:C3=3:C4=2:C5=1:C6=3 144 IF CD=2 THEN C1=1:C2=1:C3=2:C4=2:C5=3:C6=3 146 IF CD=3 THEN C1=3:C2=1:C3=1:C4=2:C5=2:C6=3 150 FOR I=1 TO 5 160 Z=RND(1) 170 IF Z>.5 THEN X1=INT(RND(1)*(10-S(I))+1):Y1=INT(RND(1)*10+1):Y2=Y1 180 IF Z>.5 THEN X2=X1+S(I):GOTO 200 190 Y1=INT(RND(1)*(10-S(I))+1):X1=INT(RND(1)*10+1):X2=X1:Y2=Y1+S(I) 200 FOR J=X1 TO X2:FOR K=Y1 TO Y2:IF RND(1)>.85 GOTO 212 210 IF H$(J,K+1)<>"." OR H$(J+1,K)<>"." OR H$(J-1,K)<>"." GOTO 160 212 IF H$(J,K)<>"." OR H$(J,K-1)<>"." THEN 160 215 NEXT K,J 220 FOR J=X1 TO X2:FOR K=Y1 TO Y2:H$(J,K)=L$(I):NEXT K,J 240 NEXT I:PRINT:PRINT"OK, LET'S PLAY" 251 IF CC=17 THEN PRINT:PRINT"YOU WON!!":GOTO 600 252 IF CM=17 THEN PRINT:PRINT"YOU LOST, CHECK THE"17-CC"HIT(S) YOU FAILED TO MAKE" 253 IF CM=17 THEN GOSUB 700:GOTO 600 255 INPUT"YOUR SHOT";A,B 257 IF A>10 OR B>10 OR A<1 OR B<1 THEN PRINT"YOU GOOFED":GOTO 255 260 IF H$(A,B)<>"." THEN C$(A,B)=H$(A,B) ELSE C$(A,B)="*" 270 IF H$(A,B)<>"." THEN CC=CC+1:H$(A,B)="." 290 ON H GOTO 400,510,510,510 300 IF S$(1)=" " AND S$(2)=" " AND S$(3)=" " THEN R=0:GOTO 310 302 FOR QI=1 TO 4:IF S$(QI)<>" " THEN 305 303 NEXT QI 305 FOR I=1 TO 5:IF S$(QI)=L$(I) GOTO 308 306 NEXT I 308 S$(QI)=" ":H=1:X=X(QI):Y=Y(QI):GOTO 400 310 A=INT(RND(1)*10+1):B=INT(RND(1)*10+1):IF CM=15 AND GF=1 THEN 325 312 BS=B:AS=A 314 IF B>3 THEN B=B-3:GOTO 314 316 IF A>3 THEN A=A-3:GOTO 316 317 IF CM=15 THEN CG=CG+1:IF CG=50 THEN GF=1 318 IF A=C1 AND B=C2 OR A=C3 AND B=C4 OR A=C5 AND B=C6 THEN 320 ELSE 310 320 A=AS:B=BS 325 IF M$(A,B)="H" OR M$(A,B)="*" GOTO 310 330 IF CM>=12 AND PX=1 OR CM=15 THEN GOSUB 800:IF SP=S(I)+1 GOTO 460 ELSE 400 460 IF M$(X+P,Y+Q)="." THEN M$(X+P,Y+Q)="*":GOSUB 1000:GOTO 251 470 IF M$(X+P,Y+Q)<>L$(I) THEN R=R+1:S$(R)=M$(X+P,Y+Q):M$(X+P,Y+Q)="H" 480 IF M$(X+P,Y+Q)<>L$(I) THEN CM=CM+1:GOSUB 1000:X(R)=X+P:Y(R)=Y+Q:GOTO 251 490 M$(X+P,Y+Q)="H":CM=CM+1:H=2:GOSUB 1000:P=P*2:Q=Q*2 500 IF H=S(I)+1 THEN H=0:PRINT CHR$(7)"SUNK!! GURGLE,GURGLE,GOODBYE "A$(I) 501 IF I=5 THEN PX=1 502 GOTO 251 510 IF M$(X+P,Y+Q)="." THEN M$(X+P,Y+Q)="*":GOTO 530 520 GOTO 540 530 ON Z GOSUB 900,902,904,906:GOSUB 1000:GOTO 251 540 IF M$(X+P,Y+Q)="*" OR M$(X+P,Y+Q)=" " THEN CK=1:ON Z GOSUB 900,902,904,906 542 IF CK=1 THEN 550 544 IF M$(X+P,Y+Q)="H" THEN ON Z GOSUB 900,902,904,906 550 CK=0:IF M$(X+P,Y+Q)<>L$(I) THEN R=R+1:S$(R)=M$(X+P,Y+Q):M$(X+P,Y+Q)="H" 560 IF M$(X+P,Y+Q)<>L$(I) THEN CM=CM+1:X(R)=X+P:Y(R)=Y+Q:GOSUB 1000:GOTO 251 570 M$(X+P,Y+Q)="H":CM=CM+1:H=H+1:GOSUB 1000:GOSUB 950 580 IF H=S(I)+1 THEN H=0:PRINT CHR$(7)"SUNK!! GURGLE,GURGLE,GOODBYE "A$(I) 590 GOTO 251 600 PRINT:INPUT"WOULD YOU LIKE TO PLAY AGAIN";F$:IF F$="YES" GOTO 7 ELSE END 700 FOR HH=1 TO 10:FOR YY=1 TO 10:PRINT" "H$(HH,YY);:NEXT:PRINT TAB(34) 701 FOR YY=1 TO 10:PRINT" "C$(HH,YY):NEXT:PRINT:NEXT:RETURN 800 SL=17-CM:SP=1 810 FOR F=A+1 TO A+4:IF F>10 THEN 860 830 IF M$(F,B)<>"H" AND M$(F,B)<>"*" THEN SP=SP+1:GOTO 850 840 GOTO 860 850 NEXT F 860 FOR F=A-1 TO A-4 STEP -1:IF F<1 THEN 870 864 IF M$(F,B)<>"H" AND M$(F,B)<>"*" THEN SP=SP+1:GOTO 868 866 GOTO 870 868 NEXT F 870 IF SP>=SL THEN RETURN 872 SP=1:FOR F=B+1 TO B+4:IF F>10 GOTO 880 874 IF M$(A,F)<>"H" AND M$(A,F)<>"*" THEN SP=SP+1:GOTO 878 876 GOTO 880 878 NEXT F 880 FOR F=B-1 TO B-4 STEP -1:IF F<1 THEN 898 892 IF M$(A,F)<>"H" AND M$(A,F)<>"*" THEN SP=SP+1:GOTO 896 894 GOTO 898 896 NEXT F 898 RETURN 900 P=-1:Q=0:RETURN 902 P=1:Q=0:RETURN 904 P=0:Q=-1:RETURN 906 P=0:Q=1:RETURN 950 IF P>0 THEN P=P+1 951 IF P<0 THEN P=P-1 952 IF Q>0 THEN Q=Q+1 953 IF Q<0 THEN Q=Q-1 954 RETURN 1000 PRINT:PRINT TAB(4)"1 2 3 4 5 6 7 8 9 10"; 1010 PRINT TAB(34)"1 2 3 4 5 6 7 8 9 10":PRINT 1020 FOR IL=1 TO 10:PRINT IL TAB(4); 1030 FOR IC=1 TO 10:PRINT M$(IL,IC);:PRINT" ";:NEXT IC 1040 PRINT TAB(30) IL;TAB (34);:FOR IC=1 TO 10:PRINT C$(IL,IC);:PRINT" "; 1050 NEXT IC:PRINT:NEXT IL:PRINT:PRINT:PRINT:RETURN