10REM       **********************
15REM       ** SUBMARINE SEARCH **
20REM       ** OR BE DESTROYED  **
25REM       ** BY BRUCE WESTFALL**
30REM       ** & ROBERT CARLSON **
35REM       ** 1975 AT UNIV OF  **
40REM       ** IOWA MODIFIED FOR**
45REM       ** ADAM 1985 BY     **
50REM       ** BRUCE E. WESTFALL**
55REM       **********************
60DIM sub(5, 4), pt(5, 3), map(10, 10, 10)
65GOSUB 9960
70? "  AGAIN, "; 
75? "HIT ANY KEY.":GET a$
80 a1=-ASC(a$)
85 a=RND(a+a1)
95REM      initialization
100FOR s=1 TO 5
105 x=INT(RND(1)*10)+1
110 y=INT(RND(1)*10)+1
115 z=INT(RND(1)*10)+1
120 sub(s, 1)=x
125 sub(s, 2)=y
130 sub(s, 3)=z
135 sub(s, 4)=1
140IF s=1 THEN 180
145 flag=0
150FOR s1=1 TO s-1
155IF sub(s1, 1)<>sub(s, 1) THEN 170
160IF sub(s1, 2)<>sub(s, 2) THEN 170
165IF sub(s1, 3)=sub(s, 3) THEN  flag=1
170NEXT s1
175IF flag=1 THEN 105
180NEXT s
195REM    PLACE PT BOATS
200FOR s=1 TO 5
205IF s=1 THEN  a$="first"
210IF s=2 THEN  a$="second"
215IF s=3 THEN  a$="third"
220IF s=4 THEN  a$="fourth"
225IF s=5 THEN  a$="final"
230 pt(s, 3)=1
235? "Enter the coordinates of the":? a$; " PT Boat! (X,Y) "; 
238INPUT x, y
239IF x=0 THEN  x=10
240IF x<1 OR x>10 THEN 235
241IF y=0 THEN  y=10
242IF y<1 OR y>10 THEN 235
245 pt(s, 1)=INT(x)
250 pt(s, 2)=INT(y)
255IF s=1 THEN 285
260 flag=0
265FOR s1=1 TO s-1
270IF pt(s1, 1)<>pt(s, 1) THEN 280
275IF pt(s1, 2)=pt(s, 2) THEN  flag=1
280NEXT s1
285IF flag=1 THEN 235
290NEXT s
295REM    YOUR SHOTS
300 s=5
305 p=5
310FOR t=1 TO 3000:NEXT t
313HOME:? "THERE ARE "; p; " PT BOATS LEFT"
315? "THERE ARE "; s; " SUBMARINES LEFT":?
320FOR i=1 TO p
323INPUT "Enter your shot "; x, y, z
325IF x=100 OR y=100 THEN GOSUB 1000
326IF x=0 THEN  x=10
327IF x<1 OR x>10 THEN 350
328IF y=0 THEN  y=10
330IF y<1 OR y>10 THEN 350
333IF z=0 THEN  z=10
335IF z<1 OR z>10 THEN 350
340GOSUB 2000
342GOSUB 4000
345GOTO 365
350IF x=100 OR y=100 THEN 315
355INVERSE:? "ONLY BETWEEN 1 AND 10!":NORMAL
360GOTO 315
365NEXT i
395IF s=0 THEN 700
400FOR i=1 TO 5
405 x=INT(RND(1)*10)+1
410 y=INT(RND(1)*10)+1
415GOSUB 3000
420NEXT i
500IF p=0 THEN 600
510GOTO 310
595REM      YOU LOSE
600INVERSE:? "You have lost your command.  "
605? "there is "; s; " submarines left.  "
610? "The submarines where located "
615? "at:                          "
620FOR i=1 TO 5
625? "Sub #"; i; " at "; sub(i, 1); ", "; sub(i, 2); "              "; :IF sub(i, 1)=10 THEN ? " "; 
627IF sub(i, 2) THEN ? " "; 
628?
630? "at a depth of "; sub(i, 3); "."; 
635IF sub(i, 4)=0 THEN ? "  SUNK       "; :IF sub(i, 3)=10 THEN ? " "; 
640IF sub(i, 4)<>0 THEN ? "             "; :IF sub(i, 3)=10 THEN ? " "; 
643?
645NEXT i
655GOTO 800
695REM      you win
700?:INVERSE
705? "You have sunk all enemy   "
710? "submarines.  You have "; p; " PT"
715? "Boats left.               "
800NORMAL
805? "Play again? (Y or N) "; 
810GET a$
815IF a$="Y" OR a$="y" THEN 100
900END
1000HOME
1003? "Depth "; z; "."
1005? "   1 2 3 4 5 6 7 8 9 0"
1010FOR v=1 TO 10
1015? v; " "; :IF v<10 THEN ? " "; 
1020FOR u=1 TO 10
1025? map(u, v, z); " "; 
1030NEXT u
1035?
1040NEXT v
1045? "Another level? (Y or N) "
1050GET a$
1055IF a$="N" OR a$="n" THEN 1070
1060INPUT "Enter depth "; z
1065GOTO 1000
1070RETURN
1995REM      looking for player hits
2000 flag=0
2005FOR j=1 TO 5
2010IF sub(j, 4)=0 THEN 2030
2015IF sub(j, 1)<>x THEN 2030
2020IF sub(j, 2)<>y THEN 2030
2025IF sub(j, 3)=z THEN  flag=j
2030NEXT j
2100IF flag=0 THEN 2130
2103? "      "; 
2105INVERSE:? "HIT AT "; x; ", "; y; ", AT "; z; " DEPTH":NORMAL
2110 map(x, y, z)=2
2115 s=s-1
2120 sub(flag, 4)=0
2125RETURN
2130? "MISS"
2135 map(x, y, z)=1
2140RETURN
2995REM      looking for computer hits
3000 flag=0
3005FOR j=1 TO 5
3010IF pt(j, 3)=0 THEN 3025
3015IF x<>pt(j, 1) THEN 3025
3020IF y=pt(j, 2) THEN  flag=j
3025NEXT j
3100IF flag=0 THEN 3125
3105FLASH:? "PT #"; flag; " IS SUNK":NORMAL
3110 pt(flag, 3)=0
3115 p=p-1
3120RETURN
3125? "He missed"
3130RETURN
3995REM   SONAR
4000FOR k=x-1 TO x+1
4005FOR l=y-1 TO y+1
4010FOR m=z-1 TO z+1
4015IF x=k AND y=l AND z=m THEN 4080
4020 flag=0
4025FOR n=1 TO 5
4030IF sub(n, 4)=0 THEN 4050
4035IF sub(n, 1)<>k THEN 4050
4040IF sub(n, 2)<>l THEN 4050
4045IF sub(n, 3)=m THEN  flag=n
4050NEXT n
4055IF flag=0 THEN 4075
4060? "Sonar report, Sir.  Submarine"
4065? "spotted at "; k; ", "; l; ", at "; m; " depth."
4070 map(k, l, m)=3
4075NEXT m
4080NEXT l
4085NEXT k
4090RETURN
9955REM      instructions
9960? "   You command five PT Boats."
9965? "Your mission is to destroy"
9970? "five submarines before you"
9975? "lose your PT Boats.  Shots are"
9980? "entered by x,y,z where x is"
9985? "the lattitude, and y is the"
9990? "longitude, and z is the depth."
9993? "X,y,z are entered as integers"
9995? "between 1 and 10.  An 0 is  "
9997? "treated as 10.  If x or y is"
10000? "equal 100 a display of that"
10005? "level at depth z.  A 2"
10010? "signifies a hit, a 1 signifies"
10015? "a miss, and a 0 means that no"
10020? "shots have been fired there."
10025? "  You only need a direct hit"
10030? "to destroy a submarine."
10035? "  READY! HIT ANY KEY"
10040GET a$
10045 a=-ASC(a$)
