5 CLS : CLEAR 1000
10 A$ = "N": INPUT "DO YOU NEED INSTRUCTIONS"; A$
20 A$ = LEFT$(A$, 1): IF A$ <> "Y" AND A$ <> "y" THEN 90
30 OPEN "STINSTR.TXT" FOR INPUT AS #1: I = O: PRINT
40 IF EOF(1) THEN 70
50 LINE INPUT #1, I$: PRINT I$
55 IF I <> 18 AND I <> 38 AND I <> 58 AND I <> 79 THEN 60
57 LINE INPUT "PRESS 'ENTER' KEY TO CONTINUE . . . "; A$: PRINT
60 I = I + 1: GOTO 40
70 CLOSE #1
80 CLEAR : PRINT : PRINT
90 DIM D(5), K1(7), K2(7), K3(7), S(7, 7), Q(7, 7), D$(5)
100 Q$ = ".EKB*"
110 D$(0) = "WARP ENGINES"
120 D$(1) = "SHORT RANGE SENSORS"
130 D$(2) = "LONG RANGE SENSORS"
140 D$(3) = "PHASERS"
150 D$(4) = "PHOTON TORPEDOES": D$(5) = "GALACTIC RECORDS"
160 PRINT : INPUT "PLEASE ENTER A RANDOM NUMBER"; E$: IF E$ = "" THEN E$ = "0"
162 I = ASC(E$): CLS
165 RANDOMIZE (TIMER / 3.14) - (I * 7.7)
170 I = I - 11 * INT(I / 11): FOR J = 0 TO I: K = RND(1): NEXT: PRINT "WORKING --- "
180 DEF FND (N) = SQR((K1(I) - S1) ^ 2 + (K2(I) - S2) ^ 2)
190 GOSUB 690: GOSUB 530: Q1 = X: Q2 = Y: X = 8: Y = 1: X1 = .2075: Y1 = 6.28: X2 = 3.28
200 Y2 = 1.8: A = .96: C = 100: W = 10: K9 = 0: B9 = 0: S9 = 400: T9 = 3451: GOTO 220
210 K = K + (N < X2) + (N < Y2) + (N < .28) + (N < .08) + (N < .03) + (N < .01): K9 = K9 - K: GOTO 240
220 T0 = 3421: T = T0: E0 = 4000: E = E0: P0 = 10: P = P0: FOR I = 0 TO 7
230 FOR J = 0 TO 7: K = 0: N = RND(1): IF N < X1 THEN N = N * 64: K = (N < Y1) - Y: GOTO 210
240 B = (RND(1) > A): B9 = B9 - B: Q(I, J) = K * C + B * W - INT(RND(1) * X + Y): NEXT J, I
250 IF K9 > (T9 - T0) THEN T9 = T0 + K9
260 IF B9 > 0 THEN 280
270 GOSUB 530: Q(X, Y) = Q(X, Y) - 10: B9 = 1
280 CLS : PRINT : PRINT LEFT$("STARTREK ADAPTED BY L.E. COCHRAN 2/29/76", 8): K0 = K9
285 PRINT "========": PRINT
290 PRINT "OBJECTIVE: DESTROY"; K9; "KLINGON BATTLE CRUISERS IN"; T9 - T0;
300 PRINT "YEARS.": PRINT " THE NUMBER OF STARBASES IS"; B9
310 A = 0: IF Q1 < 0 OR Q1 > 7 OR Q2 < 0 OR Q2 > 7 THEN N = 0: S = 0: K = 0: GOTO 330
320 N = ABS(Q(Q1, Q2)): Q(Q1, Q2) = N: S = N - INT(N / 10) * 10: K = INT(N / 100)
330 B = INT(N / 10 - K * 10): GOSUB 530: S1 = X: S2 = Y
340 FOR I = 0 TO 7: FOR J = 0 TO 7: S(I, J) = 1: NEXT J, I: S(S1, S2) = 2
350 FOR I = 0 TO 7: K3(I) = 0: X = 8: IF I < K THEN GOSUB 540: S(X, Y) = 3: K3(I) = S9
360 K1(I) = X: K2(I) = Y: NEXT: I = S
370 IF B > 0 THEN GOSUB 540: S(X, Y) = 4
380 IF I > 0 THEN GOSUB 540: S(X, Y) = 5: I = I - 1: GOTO 380
390 GOSUB 630: IF A = 0 THEN GOSUB 560
400 IF E <= 0 THEN 1450
410 I = 1: IF D(I) > 0 THEN 700
420 FOR I = 0 TO 7: FOR J = 0 TO 7: PRINT MID$(Q$, S(I, J), 1); " "; : NEXT J
430 PRINT "  "; : ON I GOTO 460, 470, 480, 490, 500, 510, 520
440 PRINT "YEARS ="; T9 - T
450 NEXT: GOTO 730
460 PRINT "STARDATE ="; T: GOTO 450
470 PRINT "CONDITION: "; C$: GOTO 450
480 PRINT "QUADRANT ="; Q1 + 1; "-"; Q2 + 1: GOTO 450
490 PRINT "SECTOR ="; S1 + 1; "-"; S2 + 1: GOTO 450
500 PRINT "ENERGY ="; E: GOTO 450
510 PRINT D$(4); " ="; P: GOTO 450
520 PRINT "KLINGONS LEFT ="; K9: GOTO 450
530 X = INT(RND(1) * 8): Y = INT(RND(1) * 8): RETURN
540 GOSUB 530: IF S(X, Y) > 1 THEN 540
550 RETURN
560 IF K < 1 THEN RETURN
570 IF C$ = "DOCKED" THEN PRINT "STARBASE PROTECTS ENTERPRISE": RETURN
580 FOR I = 0 TO 7: IF K3(I) <= 0 THEN 605
590 H = K3(I) * .4 * RND(1): K3(I) = K3(I) - H: H = H / (FND(0) ^ .4): E = E - H
600 E$ = "ENTERPRISE FROM": N = E: GOSUB 610
605 NEXT: RETURN
610 PRINT H; "UNIT HIT ON "; E$; " SECTOR"; K1(I) + 1; "-"; K2(I) + 1;
620 PRINT " ("; N; "LEFT)": RETURN
630 FOR I = S1 - 1 TO S1 + 1: FOR J = S2 - 1 TO S2 + 1
640 IF I < 0 OR I > 7 OR J < 0 OR J > 7 THEN 660
650 IF S(I, J) = 4 THEN C$ = "DOCKED": E = E0: P = P0: GOSUB 690: RETURN
660 NEXT J, I: IF K > 0 THEN C$ = "RED": RETURN
670 IF E < E0 * .1 THEN C$ = "YELLOW": RETURN
680 C$ = "GREEN": RETURN
690 FOR N = 0 TO 5: D(N) = 0: NEXT: RETURN
700 PRINT D$(I); " DAMAGED.";
710 PRINT " "; D(I); "YEARS ESTIMATED FOR REPAIR.": PRINT
720 IF A = 1 THEN RETURN
730 INPUT "COMMAND"; A
735 IF A < -98 THEN 1520
740 IF A < 1 OR A > 6 THEN 760
750 ON A GOTO 790, 390, 1330, 1220, 770, 1380
760 FOR I = 0 TO 5: PRINT I + 1; "= "; D$(I): NEXT: GOTO 730
770 IF D(4) > 0 THEN PRINT "SPACE CRUD BLOCKING TUBES.": I = 4: GOTO 710
780 N = 15: IF P < 1 THEN PRINT "NO TORPEDOES LEFT.": GOTO 730
790 IF A = 5 THEN PRINT "TORPEDO ";
800 INPUT "COURSE (1-8.9)"; C: IF C < 1 THEN 730
810 IF C >= 9 THEN 790
820 IF A = 5 THEN P = P - 1: PRINT "TRACK:"; : GOTO 980
830 INPUT "WARP (0-12)"; W: IF W <= 0 OR W > 12 THEN 790
840 IF W <= .2 OR D(0) <= 0 THEN 860
850 I = 0: PRINT D$(I); " DAMAGED, MAX IS .2 "; : GOSUB 710: GOTO 830
860 GOSUB 560: IF E <= 0 THEN 1450
870 IF RND(1) > .25 THEN 950
880 X = INT(RND(1) * 6): IF RND(1) > .5 THEN 910
890 D(X) = D(X) + INT(6 - RND(1) * 5): PRINT "**SPACE STORM, ";
900 PRINT D$(X); " DAMAGED**": I = X: GOSUB 710: D(X) = D(X) + 1: GOTO 950
910 FOR I = X TO 5: IF D(I) > 0 THEN 940
920 NEXT
930 FOR I = 0 TO X: IF D(I) > 0 THEN 940
935 NEXT: GOTO 950
940 D(I) = .5: PRINT "**SPOCK USED A NEW REPAIR TECHNIQUE**"
950 FOR I = 0 TO 5: IF D(I) = 0 THEN 970
960 D(I) = D(I) - 1: IF D(I) <= 0 THEN D(I) = 0: PRINT D$(I); " ARE FIXED!"
970 NEXT: N = INT(W * 8): E = E - N - N + .5: T = T + 1: S(S1, S2) = 1
980 Y1 = S1 + .5: X1 = S2 + .5: IF T > T9 THEN 1450
990 Y = (C - 1) * .785398: X = COS(Y): Y = -SIN(Y)
1000 FOR I = 1 TO N: Y1 = Y1 + Y: X1 = X1 + X: Y2 = INT(Y1): X2 = INT(X1)
1010 IF X2 < 0 OR X2 > 7 OR Y2 < 0 OR Y2 > 7 THEN 1190
1020 IF A = 5 THEN PRINT Y2 + 1; "-"; X2 + 1; "  ";
1030 IF S(Y2, X2) <> 1 THEN 1040
1035 NEXT: GOTO 1140
1040 PRINT : IF A = 1 THEN PRINT "BLOCKED BY ";
1050 ON S(Y2, X2) - 3 GOTO 1120, 1100
1060 PRINT "KLINGON"; : IF A = 1 THEN 1130
1070 FOR I = 0 TO 7: IF Y2 <> K1(I) THEN 1090
1080 IF X2 = K2(I) THEN K3(I) = 0
1090 NEXT: K = K - 1: K9 = K9 - 1: GOTO 1150
1100 PRINT "STAR"; : IF A = 5 THEN S = S - 1: GOTO 1150
1110 GOTO 1130
1120 PRINT "STARBASE"; : IF A = 5 THEN B = 2: GOTO 1150
1130 PRINT " AT SECTOR"; Y2 + 1; "-"; X2 + 1: Y2 = INT(Y1 - Y): X2 = INT(X1 - X)
1140 S1 = Y2: S2 = X2: S(S1, S2) = 2: A = 2: GOTO 390
1150 PRINT " DESTROYED!"; : IF B = 2 THEN B = 0: PRINT ". . .GOOD WORK!";
1160 PRINT : S(Y2, X2) = 1: Q(Q1, Q2) = K * 100 + B * 10 + S: IF K9 < 1 THEN 1480
1170 GOSUB 560: IF E <= 0 THEN 1450
1180 GOSUB 630: GOTO 730
1190 IF A = 5 THEN PRINT "MISSED!": GOTO 1170
1200 Q1 = INT(Q1 + W * Y + (S1 + .5) / 8): Q2 = INT(Q2 + W * X + (S2 + .5) / 8)
1210 Q1 = Q1 - (Q1 < 0) + (Q1 > 7): Q2 = Q2 - (Q2 < 0) + (Q2 > 7): GOTO 310
1220 I = 3: IF D(I) > 0 THEN 700
1230 INPUT "PHASERS READY: ENERGY UNITS TO FIRE"; X: IF X <= 0 THEN 730
1240 IF X > E THEN PRINT "ONLY GOT"; E: GOTO 1230
1250 E = E - X: Y = K: FOR I = 0 TO 7: IF K3(I) <= 0 THEN 1310
1260 H = X / (Y * (FND(0) ^ .4)): K3(I) = K3(I) - H
1270 E$ = "KLINGON AT": N = K3(I): GOSUB 610
1280 IF K3(I) > 0 THEN 1310
1290 PRINT "**KLINGON DESTROYED**"
1300 K = K - 1: K9 = K9 - 1: S(K1(I), K2(I)) = 1: Q(Q1, Q2) = Q(Q1, Q2) - 100
1310 NEXT: IF K9 < 1 THEN 1480
1320 GOTO 1170
1330 I = 2: IF D(I) > 0 THEN 700
1340 PRINT D$(I); " FOR QUADRANT"; Q1 + 1; "-"; Q2 + 1
1350 FOR I = Q1 - 1 TO Q1 + 1: FOR J = Q2 - 1 TO Q2 + 1: PRINT "   ";
1360 IF I < 0 OR I > 7 OR J < 0 OR J > 7 THEN PRINT "***"; : GOTO 1375
1370 Q(I, J) = ABS(Q(I, J))
1373 E$ = STR$(Q(I, J)): E$ = "00" + MID$(E$, 2): PRINT RIGHT$(E$, 3);
1375 NEXT J: PRINT : NEXT I: GOTO 730
1380 I = 5: IF D(I) > 0 THEN 700
1390 PRINT "CUMULATIVE GALACTIC MAP FOR STARDATE:"; T
1400 FOR I = 0 TO 7: FOR J = 0 TO 7: PRINT "  ";
1410 IF Q(I, J) < 0 THEN PRINT "***"; : GOTO 1430
1420 E$ = STR$(Q(I, J)): E$ = "00" + MID$(E$, 2): PRINT RIGHT$(E$, 3);
1430 NEXT J: PRINT : NEXT I: GOTO 730
1440 PRINT : PRINT "IT IS STARDATE"; T: RETURN
1450 GOSUB 1440: PRINT "THANKS TO YOUR BUNGLING, THE FEDERATION WILL BE"
1460 PRINT "CONQUERED BY THE REMAINING"; K9; "KLINGON CRUISERS!"
1470 PRINT "YOU ARE DEMOTED TO CABIN BOY!": GOTO 1510
1480 GOSUB 1440: PRINT "THE FEDERATION HAS BEEN SAVED!"
1490 PRINT "YOU ARE PROMOTED TO ADMIRAL.": PRINT K0; "KLINGONS IN";
1500 PRINT T - T0; "YEARS.  RATING ="; INT(K0 / (T - T0) * 1000)
1510 E$ = "N": INPUT "TRY AGAIN"; E$: E$ = LEFT$(E$, 1): IF E$ = "Y" OR E$ = "y" THEN 190
1515 GOTO 1530
1520 PRINT : PRINT "GOOD-BYE, YOU QUITTER!"
1530 END
