100 REM CODE NAME: SECTOR
105 REM BY TURSI
110 REM A PORT OF THE MB GAME
120 DIM DIRLAT(8),DIRLON(8)
130 DATA 1,0,1,1,0,1,-1,1,-1,0,-1,-1,0,-1,1,-1
140 FOR I=1 TO 8 :: READ DIRLAT(I),DIRLON(I):: NEXT I
150 DIM SHIPLAT(4),SHIPLON(4)
160 DIM SHIPSP(4),SHIPDIR(4)
170 DIM SHIPAIM(4)
180 RANDOMIZE
190 REPLAY=0
200 CALL CLEAR
210 CALL CHARSET
220 CALL DELSPRITE(ALL)
230 DISPLAY AT(12,1):"CODE NAME: SECTOR"
240 PRINT "PLEASE ENTER THE SIZE OF":"YOUR GRAPH PAPER (LAT,LON)":"THE NORMAL GAME RUNS AT A":"SIZE OF 50,50"
250 INPUT WIDTH,HEIGHT
260 IF WIDTH<20 OR HEIGHT<20 THEN PRINT "YOU NEED AT LEAST 20X20" :: GOTO 250
270 IF WIDTH>99-25 OR HEIGHT>99-25 THEN PRINT "MAX SIZE IS 74X74" :: GOTO 250
280 CALL CLEAR
290 PRINT "PLEASE MARK THE BOTTOM":"LEFT CORNER AS 25 N, 25 E"
300 SHIPLAT(1)=35
310 SHIPLAT(2)=30
320 SHIPLAT(3)=25
330 SHIPLAT(4)=25
340 SHIPLON(1)=25
350 SHIPLON(2)=25
360 SHIPLON(3)=30
370 SHIPLON(4)=35
380 PRINT
390 FOR I=1 TO 4
400 SHIPSP(I)=0 :: SHIPDIR(I)=2
410 SHIPAIM(I)=2
420 PRINT "MARK SHIP";I;"AT";SHIPLON(I);"N,";SHIPLAT(I);"E"
430 NEXT I
440 PRINT
450 PRINT "WOULD YOU LIKE TO PLAY THE":"TRAINING GAME FROM THE":"OFFICIAL MANUAL? (Y/N)"
460 INPUT A$
470 IF SEG$(A$,1,1)="Y" THEN TRAIN=1 ELSE TRAIN=0
480 EVASIVE=0
490 IF TRAIN=1 THEN SUBLAT=35 :: SUBLON=35 :: SUBDIR=2 :: SUBDEPTH=1 :: GOTO 550
500 IF REPLAY=1 THEN 540
510 PRINT "WOULD YOU LIKE THE EVASIVE":"SUB? (MORE DIFFICULT!)"
520 INPUT A$
530 IF SEG$(A$,1,1)="Y" THEN EVASIVE=1
540 SUBLAT=INT(RND*(WIDTH-10))+30 :: SUBLON=INT(RND*(WIDTH-10))+30 :: SUBDIR=INT(RND*8)+1 :: SUBDEPTH=INT(RND*3)+1
550 REM
560 CALL CLEAR :: CALL SCREEN(8):: IF REPLAY<>0 THEN 710
570 CALL CHAR(136,"0030787C7E7F7F7F7773717070707030000C0E0E0E0E8ECEEEFEFEFE7E3E1E0C")
580 CALL CHAR(140,"003F7F7F7070707F7F7F7070707F7F3F00FCFEFC00000080C080000000FCFEFC")
590 CALL CHAR(40,"002070707070707173737373737F7E3C00040E0E0E0E0E8ECECECECECEFE7E3C")
600 CALL CHAR(36,"001F3F7F7070707F3F1F0000003F7F3F00FCFEFC000000F8FCFE0E0E0EFEFCF8")
610 CALL CHAR(116,"003E414141414141004141414141413E00000101010101010001010101010100")
620 CALL CHAR(120,"003E0101010101013E4040404040403E003E0101010101013E0101010101013E")
630 CALL CHAR(124,"00004141414141413E01010101010100003E4040404040403E0101010101013E")
640 CALL CHAR(128,"003E4040404040403E4141414141413E003E0101010101010001010101010100")
650 CALL CHAR(132,"003E4141414141413E4141414141413E003E4141414141413E0101010101013E")
660 CALL CHAR(96,"00000000000000000000000F08080808000000FF00000000000000FF08080808")
670 CALL CHAR(100,"000000F80808080808080808080808080808080F08080808080808FF08080808")
680 CALL CHAR(104,"080808F8080808080808080F00000000080808FF00000000080808F8")
690 CALL CHAR(108,"80402010080402010103070F1F3F7FFF0102040810204080FF7F3F1F0F070301")
700 CALL CHAR(112,"80C0E0F0F8FCFEFFFFFEFCF8F0E0C080FFFFFFFFFFFFFFFF")
710 CALL CLEAR
720 DISPLAY AT(1,6):"abbbbcbbbbbcbbcbbd"
730 DISPLAY AT(2,6):"eSHIPeSPEEDeN eE e"
740 DISPLAY AT(3,6):"fbbbbgbbbbbgbbjbbh"
750 DISPLAY AT(4,6):"errrrerrrrrerrrrre"
760 DISPLAY AT(5,6):"errrrerrrrrerrrrre"
770 DISPLAY AT(6,6):"errrrerrrrrerrrrre"
780 DISPLAY AT(7,6):"fbbbbgbbbbbgbbbbbh"
790 DISPLAY AT(8,6):"e    e     e     e"
800 DISPLAY AT(9,6):"fbbbbjbbbbbjbbbbbh"
810 DISPLAY AT(10,6):"e                e"
820 DISPLAY AT(11,6):"e    NW    NE    e"
830 DISPLAY AT(12,6):"e       ml       e"
840 DISPLAY AT(13,6):"e      nomp      e"
850 DISPLAY AT(14,6):"e      oqpn      e"
860 DISPLAY AT(15,6):"e       lq       e"
870 DISPLAY AT(16,6):"e    SW    SE    e"
880 DISPLAY AT(17,6):"e                e"
890 DISPLAY AT(18,6):"ibbbbbbbbbbbbbbbbk"
900 DISPLAY AT(19,4):"N-NEXT SHIP   X-SLOWER"
910 DISPLAY AT(20,4):"M-MOVE SHIP   E-FASTER"
920 DISPLAY AT(21,4):"S-LEFT        R-RANGE"
930 DISPLAY AT(22,4):"D-RIGHT       A-AIM"
940 DISPLAY AT(23,4):"G-GIVE UP     !-FIRE"
950 DISPLAY AT(24,4):".-RECALL"
960 CALL MAGNIFY(3)
970 CALL SPRITE(#1,48,1,28,70)
980 CALL SPRITE(#2,52,1,28,118)
990 CALL SPRITE(#3,56,1,28,155)
1000 CALL SPRITE(#4,60,1,28,175)
1010 CALL SPRITE(#5,136,15,72,121)
1020 CALL SPRITE(#6,140,15,96,147)
1030 CALL SPRITE(#7,36,15,122,121)
1040 CALL SPRITE(#8,40,15,96,95)
1050 SHIP=1
1060 GAMEOVER=0
1070 MOVED=0 :: FIRED=0
1080 REM MAIN LOOP
1090 AIMING=0
1100 CALL DEFNUM(1,48,SHIP)
1110 CALL DEFNUM(2,52,SHIPSP(SHIP))
1120 CALL DEFNUM(3,56,SHIPLAT(SHIP))
1130 CALL DEFNUM(4,60,SHIPLON(SHIP))
1140 CALL COMPASS(SHIPDIR(SHIP))
1150 DISPLAY AT(8,6):"e    e     e     e"
1160 DISPLAY AT(2,12):"SPEED";
1170 CALL KEY(0,K,S)
1180 IF S=0 THEN 1170
1190 I=POS("NMSDGXERA!.",CHR$(K),1)
1200 IF I=0 THEN 1170
1210 IF I=11 THEN 1080
1220 ON I GOSUB 1270,1430,1640,1740,1840,1940,1990,2040,2150,2210
1230 IF I=1 THEN 1080
1240 IF I=2 THEN 1110
1250 IF GAMEOVER=1 THEN 2600
1260 GOTO 1170
1270 REM NEXT SHIP
1280 MOVED=0 :: FIRED=0
1290 SUBLAT=SUBLAT+DIRLAT(SUBDIR)
1300 SUBLON=SUBLON+DIRLON(SUBDIR)
1310 IF SUBLAT<30 OR SUBLAT>HEIGHT-5+25 THEN SUBLAT=SUBLAT-DIRLAT(SUBDIR):: GOSUB 1350
1320 IF SUBLON<30 OR SUBLON>WIDTH-5+25 THEN SUBLON=SUBLON-DIRLAT(SUBDIR):: GOSUB 1350
1330 SHIP=SHIP+1 :: IF SHIP=5 THEN SHIP=1
1340 RETURN
1350 SUBDIR=INT(RND*8)
1360 SUBDIR=SUBDIR+1
1370 IF SUBDIR>8 THEN SUBDIR=1
1380 LAT=SUBLAT+DIRLAT(SUBDIR)
1390 LON=SUBLON+DIRLON(SUBDIR)
1400 IF LON<30 OR LON>WIDTH-5+25 THEN 1360
1410 IF LAT<30 OR LAT>HEIGHT-5+25 THEN 1360
1420 RETURN
1430 REM MOVE SHIP
1440 IF MOVED=0 THEN 1470
1450 DISPLAY AT(8,7):"NEXT";
1460 RETURN
1470 DISPLAY AT(8,7):"MOVE";
1480 MOVED=1
1490 FOR N=1 TO SHIPSP(SHIP)
1500 SHIPLAT(SHIP)=SHIPLAT(SHIP)+DIRLAT(SHIPDIR(SHIP))
1510 SHIPLON(SHIP)=SHIPLON(SHIP)+DIRLON(SHIPDIR(SHIP))
1520 IF SHIPLAT(SHIP)<25 THEN SHIPLAT(SHIP)=25 :: SHIPSP(SHIP)=0
1530 IF SHIPLAT(SHIP)>25+HEIGHT THEN SHIPLAT(SHIP)=25+HEIGHT :: SHIPSP(SHIP)=0
1540 IF SHIPLON(SHIP)<25 THEN SHIPLON(SHIP)=25 :: SHIPSP(SHIP)=0
1550 IF SHIPLON(SHIP)>25+WIDTH THEN SHIPLON(SHIP)=25+WIDTH :: SHIPSP(SHIP)=0
1560 FOR Q=1 TO 4 :: IF Q=SHIP THEN 1580
1570 IF SHIPLAT(SHIP)=SHIPLAT(Q)AND SHIPLON(SHIP)=SHIPLON(Q)THEN 1610
1580 NEXT Q
1590 NEXT N
1600 RETURN
1610 REM COLLISION!
1620 DISPLAY AT(8,7):"COLL";
1630 GOTO 2530
1640 REM LEFT
1650 IF AIMING=1 THEN 1700
1660 SHIPDIR(SHIP)=SHIPDIR(SHIP)-1
1670 IF SHIPDIR(SHIP)<1 THEN SHIPDIR(SHIP)=8
1680 CALL COMPASS(SHIPDIR(SHIP))
1690 RETURN
1700 SHIPAIM(SHIP)=SHIPAIM(SHIP)-1
1710 IF SHIPAIM(SHIP)<1 THEN SHIPAIM(SHIP)=8
1720 CALL COMPASS(SHIPAIM(SHIP))
1730 RETURN
1740 REM RIGHT
1750 IF AIMING=1 THEN 1800
1760 SHIPDIR(SHIP)=SHIPDIR(SHIP)+1
1770 IF SHIPDIR(SHIP)>8 THEN SHIPDIR(SHIP)=1
1780 CALL COMPASS(SHIPDIR(SHIP))
1790 RETURN
1800 SHIPAIM(SHIP)=SHIPAIM(SHIP)+1
1810 IF SHIPAIM(SHIP)>8 THEN SHIPAIM(SHIP)=1
1820 CALL COMPASS(SHIPAIM(SHIP))
1830 RETURN
1840 REM GIVE UP
1850 DISPLAY AT(8,7):"GIVEeDEPTH";
1860 DISPLAY AT(2,12):"     ";
1870 CALL DEFNUM(2,52,SUBDEPTH)
1880 CALL DEFNUM(3,56,SUBLAT)
1890 CALL DEFNUM(4,60,SUBLON)
1900 CALL COMPASS(SUBDIR)
1910 CALL HCHAR(19,1,32,32*6)
1920 GAMEOVER=1
1930 RETURN
1940 REM SLOWER
1950 IF SHIPSP(SHIP)<1 THEN RETURN
1960 SHIPSP(SHIP)=SHIPSP(SHIP)-1
1970 CALL DEFNUM(2,52,SHIPSP(SHIP))
1980 RETURN
1990 REM FASTER
2000 IF SHIPSP(SHIP)>8 THEN RETURN
2010 SHIPSP(SHIP)=SHIPSP(SHIP)+1
2020 CALL DEFNUM(2,52,SHIPSP(SHIP))
2030 RETURN
2040 REM DISTANCE/RANGE
2050 DISPLAY AT(8,18):"RANGE";
2060 CALL COLOR(#3,1)
2070 R1=ABS(SUBLAT-SHIPLAT(SHIP)):: R2=ABS(SUBLON-SHIPLON(SHIP))
2080 IF R1>R2 THEN CALL DEFNUM(4,60,R1):: R=R1 ELSE CALL DEFNUM(4,60,R2):: R=R2
2090 IF R<=1 THEN 2130
2100 IF R<>2 THEN 2120
2110 IF R1=0 OR R2=0 OR R1=R2 THEN 2130
2120 RETURN
2130 DISPLAY AT(8,7):"F OK";
2140 RETURN
2150 REM AIM
2160 IF FIRED<>0 THEN AIMING=0 :: RETURN
2170 DISPLAY AT(8,7):" AIM";
2180 CALL COMPASS(SHIPAIM(SHIP))
2190 AIMING=1
2200 RETURN
2210 REM FIRE
2220 IF FIRED<>0 THEN AIMING=0 :: RETURN
2230 IF AIMING=0 THEN 2150
2240 DISPLAY AT(8,7):"FIREeENTEReDEPTH";
2250 FIRED=1
2260 R1=ABS(SUBLAT-SHIPLAT(SHIP)):: R2=ABS(SUBLON-SHIPLON(SHIP))
2270 IF R1>R2 THEN R=R1 ELSE R=R2
2280 CALL KEY(0,K,S)
2290 IF S=0 THEN 2280
2300 IF K<49 OR K>51 THEN 2280
2310 DISPLAY AT(8,12):"     e     ";
2320 K=K-48
2330 IF R>2 THEN 2520
2340 IF R=2 AND R1<>R2 THEN 2520
2350 IF R=0 THEN 2390
2360 IF SGN(SUBLAT-SHIPLAT(SHIP))<>DIRLAT(SHIPAIM(SHIP))THEN 2520
2370 IF SGN(SUBLON-SHIPLON(SHIP))<>DIRLON(SHIPAIM(SHIP))THEN 2520
2380 IF K<>SUBDEPTH THEN 2470
2390 REM SUB HIT!
2400 FOR N=1 TO 3
2410 DISPLAY AT(8,7):"    ";
2420 DISPLAY AT(8,7):"SUB!";
2430 NEXT N
2440 DISPLAY AT(8,7):"SUB!eDEPTH";
2450 GOTO 1860
2460 GOSUB 2710
2470 K=ABS(K-SUBDEPTH)
2480 DISPLAY AT(8,12):" OFF ";
2490 CALL DEFNUM(2,52,K)
2500 RETURN
2510 REM SOS! (MISSED)
2520 DISPLAY AT(8,7):"SOS!";
2530 CALL COLOR(#5,7,#6,7,#7,7,#8,7)
2540 CALL DEFNUM(3,56,88):: CALL DEFNUM(4,60,88)
2550 CALL COLOR(#5,15,#6,15,#7,15,#8,15)
2560 CALL COLOR(#3,1,#4,1)
2570 SHIPLAT(SHIP)=INT(RND*WIDTH)+25 :: SHIPLON(SHIP)=INT(RND*HEIGHT)+25 :: SHIPDIR(SHIP)=INT(RND*8)+1
2580 GOSUB 2710
2590 RETURN
2600 DISPLAY AT(19,1):"PRESS"
2610 DISPLAY AT(20,3):"Q-QUIT"
2620 DISPLAY AT(21,3):"R-REPLAY"
2630 DISPLAY AT(22,3):"C-CHANGE OPTIONS"
2640 CALL KEY(0,K,S)
2650 IF S=0 THEN 2640
2660 I=POS("QRC",CHR$(K),1)
2670 IF I=0 THEN 2640
2680 IF I=1 THEN CALL CLEAR :: END
2690 IF I=2 THEN REPLAY=1 :: GOTO 490
2700 CALL CLEAR :: REPLAY=-1 :: GOTO 200
2710 REM EVASIVE SUB
2720 IF EVASIVE=0 THEN RETURN
2730 IF RND>.5 THEN 2770
2740 SUBDIR=SUBDIR+1
2750 IF SUBDIR>8 THEN SUBDIR=1
2760 RETURN
2770 SUBDIR=SUBDIR-1
2780 IF SUBDIR<1 THEN SUBDIR=8
2790 RETURN
2800 SUB DEFNUM(SP,CH,N)
2810 CALL COLOR(#SP,1)
2820 IF N>99 THEN N=N-100 :: GOTO 2820
2830 N1=INT(N/10)
2840 N2=N-(N1*10)
2850 IF N1=0 THEN A1$=RPT$("0",16):: A2$=A1$ :: GOTO 2880
2860 CALL CHARPAT(N1*2+116,A1$)
2870 CALL CHARPAT(N1*2+117,A2$)
2880 CALL CHARPAT(N2*2+116,A3$)
2890 CALL CHARPAT(N2*2+117,A4$)
2900 CALL CHAR(CH,A1$&A2$&A3$&A4$)
2910 CALL COLOR(#SP,7)
2920 SUBEND
2930 SUB COMPASS(DIR)
2940 IF AIMING THEN C=13 ELSE C=7
2950 IF DIR=1 OR DIR=2 OR DIR=8 THEN CALL COLOR(#5,C)ELSE CALL COLOR(#5,15)
2960 IF DIR=2 OR DIR=3 OR DIR=4 THEN CALL COLOR(#6,C)ELSE CALL COLOR(#6,15)
2970 IF DIR=4 OR DIR=5 OR DIR=6 THEN CALL COLOR(#7,C)ELSE CALL COLOR(#7,15)
2980 IF DIR=6 OR DIR=7 OR DIR=8 THEN CALL COLOR(#8,C)ELSE CALL COLOR(#8,15)
2990 SUBEND
