mirror of
https://github.com/inexorabletash/jsbasic.git
synced 2024-12-04 11:49:51 +00:00
209 lines
5.7 KiB
Plaintext
209 lines
5.7 KiB
Plaintext
|
1 TEXT: HOME
|
||
|
2 PRINT "WELCOME TO THE DRAGON'S MAZE"
|
||
|
3 PRINT "YOU MAY WATCH WHILE I BUILD A MAZE,"
|
||
|
4 PRINT "BUT WHEN IT'S COMPLETE, I'LL ERASE"
|
||
|
5 PRINT "THE PICTURE. THEN YOU'LL ONLY SEE THE WALLS AS YOU BUMP INTO THEM."
|
||
|
6 PRINT "TO MOVE, YOU HIT 'R' FOR RIGHT,"
|
||
|
7 PRINT "'L' FOR LEFT, 'U' FOR UP, AND"
|
||
|
8 PRINT "'D' FOR DOWN. DO NOT HIT RETURN!"
|
||
|
9 PRINT
|
||
|
10 PRINT "THE OBJECT IS FOR YOU (THE GREEN DOT"
|
||
|
11 PRINT "TO GET TO THE DOOR ON THE RIGHT SIDE"
|
||
|
12 PRINT "BEFORE THE DRAGON (THE RED DOT) EATS"
|
||
|
13 PRINT "YOU."
|
||
|
14 PRINT "BEWARE!!!!!!!!! SOMETIMES THE DRAGON"
|
||
|
15 PRINT "GETS REAL MAD, AND CLIMBS OVER A WALL."
|
||
|
16 PRINT "BUT MOST OF THE TIME, HE CAN'T GO OVER"
|
||
|
17 PRINT "AND HAS TO GO AROUND."
|
||
|
18 PRINT
|
||
|
19 PRINT "(HINT: YOU CAN OFTEN TELL WHERE A WALL"
|
||
|
20 PRINT "IS, EVEN BEFORE YOU CAN SEE IT, BY"
|
||
|
21 PRINT "THE FACT THAT THE DRAGON CAN'T GET"
|
||
|
22 PRINT "THROUGH IT!)"
|
||
|
23 PRINT
|
||
|
99 DIM A$(3), M(169), T(169)
|
||
|
|
||
|
100 PRINT "ENTER GAME # TO BEGIN ";: INPUT A: IF A<=0 THEN 100
|
||
|
110 A=RND(-ABS(A)): BL=0: WH=15: RD=1: GN=12
|
||
|
120 GR: COLOR=WH
|
||
|
130 HOME: VTAB (21): PRINT "DRAGON MAZE" TAB(25) "GARY J. SHANNON": PRINT TAB(4) "(Applesoft port) RUSSELL A. HOKANSON"
|
||
|
140 FOR I=0 TO 39 STEP 3: VLIN 0,39 AT I: HLIN 0,39 AT I: NEXT I
|
||
|
150 COLOR=BL
|
||
|
160 S=1000
|
||
|
|
||
|
1000 REM INITIALIZE ARRAYS, STARTING POINT AND PROCESSED COUNT
|
||
|
1000 FOR I=1 TO 169: T(I)=0: M(I)=11: NEXT I
|
||
|
1010 X=INT(RND(1)*13)+1: Y=INT(RND(1)*13)+1: C=169
|
||
|
|
||
|
1035 IF C=1 THEN 1200
|
||
|
1040 R=0: D=0: L=0: U=0: K=X+13*(Y-1): M(K)=-ABS(M(K)): C=C-1
|
||
|
1050 IF X=13 THEN 1060
|
||
|
1051 R=M(K+1)>0
|
||
|
1060 IF Y=13 THEN 1070
|
||
|
1061 D=M(K+13)>0
|
||
|
1070 IF X=1 THEN 1080
|
||
|
1071 L=M(K-1)>0
|
||
|
1080 IF Y=1 THEN 1090
|
||
|
1081 U=M(K-13)>0
|
||
|
1090 Q=R+D+L+U
|
||
|
1100 IF (Q<3 AND INT(RND(1)*10)<2) OR Q=0 THEN 1170
|
||
|
|
||
|
1110 DR=INT(RND(1)*4): REM CHOOSE A DIRECTION (0-RIGHT, 1-DOWN, 2-LEFT, 3-UP)
|
||
|
1121 IF DR=1 THEN 1140
|
||
|
1122 IF DR=2 THEN 1150
|
||
|
1123 IF DR=3 THEN 1160
|
||
|
|
||
|
1130 IF NOT R THEN 1110: REM R-RIGHT
|
||
|
1131 M(K)=M(K)+1: X=X+1
|
||
|
1135 VLIN 3*Y-2,3*Y-1 AT 3*(X-1)
|
||
|
1136 GOTO 1035
|
||
|
|
||
|
1140 IF NOT D THEN 1110: REM D-DOWN
|
||
|
1141 M(K)=M(K)+10: Y=Y+1
|
||
|
1145 HLIN 3*X-2,3*X-1 AT 3*(Y-1)
|
||
|
1146 GOTO 1035
|
||
|
|
||
|
1150 IF NOT L THEN 1110: REM L-LEFT
|
||
|
1151 M(K-1)=M(K-1)-1: X=X-1
|
||
|
1155 VLIN 3*Y-2,3*Y-1 AT 3*X
|
||
|
1156 GOTO 1035
|
||
|
|
||
|
1160 IF NOT U THEN 1110: REM U-UP
|
||
|
1161 M(K-13)=M(K-13)-10: Y=Y-1
|
||
|
1165 HLIN 3*X-2,3*X-1 AT 3*Y: GOTO 1035
|
||
|
|
||
|
1170 X=INT(RND(1)*13)+1: Y=INT(RND(1)*13)+1: REM SELECT RANDOM POSITION
|
||
|
1180 IF M(X+13*(Y-1))>0 THEN 1170
|
||
|
1190 C=C+1: GOTO 1035
|
||
|
|
||
|
1200 GOSUB 5000: PRINT "THE MAZE IS READY"
|
||
|
1205 GR: COLOR=WH
|
||
|
1210 VLIN 0,39 AT 0: VLIN 0,39 AT 39: HLIN 0,39 AT 0: HLIN 0,39 AT 39
|
||
|
1220 X=1: Y=INT(RND(1)*13)+1: HX=3*X-2: HY=3*Y-2: FOR K=0 TO 1: FOR L=0 TO 1: COLOR=GN: PLOT HX+K,HY+L: NEXT L,K
|
||
|
1230 WY=INT(RND(1)*13)+1
|
||
|
1240 COLOR=BL: VLIN 3*WY-2,3*WY-1 AT 39
|
||
|
1250 SX=13: SY=WY
|
||
|
1260 QX=3*SX-2: QY=3*SY-2
|
||
|
|
||
|
1500 K= PEEK(-16384): IF K<128 THEN 1500
|
||
|
1510 POKE -16368,0
|
||
|
1515 QQ=K: GOSUB 7000: K=QQ
|
||
|
1516 IF SX=X AND SY=Y THEN 8000
|
||
|
1520 IF K=ASC("R") THEN 2000
|
||
|
1521 IF K=210 THEN 2000
|
||
|
1522 IF K=242 THEN 2000
|
||
|
1530 IF K=ASC("L") THEN 2500
|
||
|
1531 IF K=204 THEN 2500
|
||
|
1532 IF K=236 THEN 2500
|
||
|
1540 IF K=ASC("U") THEN 3000
|
||
|
1541 IF K=213 THEN 3000
|
||
|
1542 IF K=245 THEN 3000
|
||
|
1550 IF K=ASC("D") THEN 3500
|
||
|
1551 IF K=196 THEN 3500
|
||
|
1552 IF K=228 THEN 3500
|
||
|
1560 GOSUB 5000: GOTO 1500
|
||
|
1999 END
|
||
|
|
||
|
2000 DX=1: DY=0: REM RIGHT
|
||
|
2005 IF X=13 THEN 4000
|
||
|
2010 P1=M(X+13*(Y-1)): GOSUB 9000: IF MOD>0 THEN 4000
|
||
|
|
||
|
2020 FX=3*X-2: FY=3*Y-2: FOR I=1 TO 3
|
||
|
2030 FX=FX+DX: FY=FY+DY
|
||
|
2040 COLOR=BL
|
||
|
2060 FOR K=0 TO 1: FOR L=0 TO 1: PLOT HX+K,HY+L: NEXT L,K: COLOR=GN: FOR K=0 TO 1: FOR L=0 TO 1: PLOT FX+K,FY+L: NEXT L,K: HX=FX: HY=FY
|
||
|
2110 NEXT I
|
||
|
2115 X=X+DX: Y=Y+DY
|
||
|
2116 IF X=13 AND Y=WY THEN 6000
|
||
|
2120 GOTO 1500
|
||
|
|
||
|
2500 DX=-1: DY=0: REM LEFT
|
||
|
2505 IF X=1 THEN 4100
|
||
|
2510 P1=M(X+13*(Y-1)-1): GOSUB 9000: IF MOD>0 THEN 4100
|
||
|
2520 GOTO 2020
|
||
|
|
||
|
3000 DX=0: DY=-1: REM UP
|
||
|
3005 IF Y=1 THEN 4200
|
||
|
3010 IF INT(ABS(M(X+13*(Y-2)))/10)>0 THEN 4200
|
||
|
3020 GOTO 2020
|
||
|
|
||
|
3500 DX=0: DY=1: REM DOWN
|
||
|
3505 IF Y=13 THEN 4300
|
||
|
3510 IF INT(ABS(M(X+13*(Y-1)))/10)>0 THEN 4300
|
||
|
3520 GOTO 2020
|
||
|
|
||
|
4000 GOSUB 5000
|
||
|
4010 COLOR=WH
|
||
|
4020 VLIN 3*(Y-1),3*Y AT 3*X
|
||
|
4030 GOTO 1500
|
||
|
|
||
|
4100 GOSUB 5000
|
||
|
4110 COLOR=WH
|
||
|
4120 VLIN 3*(Y-1),3*Y AT 3*(X-1)
|
||
|
4130 GOTO 1500
|
||
|
|
||
|
4200 GOSUB 5000
|
||
|
4210 COLOR=WH
|
||
|
4220 HLIN 3*(X-1),3*X AT 3*(Y-1)
|
||
|
4230 GOTO 1500
|
||
|
|
||
|
4300 GOSUB 5000
|
||
|
4310 COLOR=WH
|
||
|
4320 HLIN 3*(X-1),3*X AT 3*Y
|
||
|
4330 GOTO 1500
|
||
|
|
||
|
5000 S=S-1: FOR I=1 TO 20: A=PEEK(-16336) + PEEK(-16336) + PEEK(-16336) + PEEK(-16336): NEXT I: RETURN
|
||
|
|
||
|
6000 PRINT "YOU WIN!"
|
||
|
6010 GOSUB 5000: GOSUB 5000: GOSUB 5000
|
||
|
6020 PRINT "SCORE=";S+3
|
||
|
6030 END
|
||
|
|
||
|
7000 REM DRAGON SUB ROUTINE
|
||
|
7000 IF X>SX THEN 7050: REM RIGHT
|
||
|
7001 IF Y>SY THEN 7100: REM DOWN
|
||
|
7002 IF X<SX THEN 7150: REM LEFT
|
||
|
7003 IF Y<SY THEN 7200: REM UP
|
||
|
|
||
|
7050 REM RIGHT
|
||
|
7050 IF SX=13 THEN 7100
|
||
|
7060 IF T(SX+13*(SY-1))>9 THEN 7080
|
||
|
7070 P1=M(SX+13*(SY-1)): GOSUB 9000: IF MOD>0 THEN 7100
|
||
|
7080 DX=1: DY=0: GOTO 7300
|
||
|
|
||
|
7100 REM DOWN
|
||
|
7100 IF SY=13 THEN 7150
|
||
|
7110 IF T(SX+13*(SY-1))>9 THEN 7130
|
||
|
7120 IF INT(ABS(M(SX+13*(SY-1)))/10) THEN 7150
|
||
|
7130 DX=0: DY=1: GOTO 7300
|
||
|
|
||
|
7150 REM LEFT
|
||
|
7150 IF SX=1 THEN 7200
|
||
|
7160 IF T(SX+13*(SY-1))>9 THEN 7180
|
||
|
7170 P1=M(SX+13*(SY-1)-1): GOSUB 9000: IF MOD>0 THEN 7200
|
||
|
7180 DX=-1: DY=0: GOTO 7300
|
||
|
|
||
|
7200 REM UP
|
||
|
7200 IF SY=1 THEN 7050
|
||
|
7210 IF T(SX+13*(SY-1))>9 THEN 7230
|
||
|
7220 IF INT(ABS(M(SX+13*(SY-1)-13))/10) THEN 7050
|
||
|
7230 DX=0: DY=-1: GOTO 7300
|
||
|
|
||
|
7300 REM DRAW WALLS/DRAGON
|
||
|
7300 COLOR=BL
|
||
|
7310 RX=3*SX-2: RY=3*SY-2
|
||
|
7320 FOR I=1 TO 3: RX=RX+DX: RY=RY+DY
|
||
|
7330 COLOR=BL: FOR K=0 TO 1: FOR L=0 TO 1: PLOT QX+K,QY+L: NEXT L,K
|
||
|
7340 COLOR=RD: FOR K=0 TO 1: FOR L=0 TO 1: PLOT RX+K,RY+l: NEXT L,K: QX=RX: QY=RY
|
||
|
7350 NEXT I
|
||
|
|
||
|
7360 REM UPDATE DRAGON WALLS
|
||
|
7360 SX=SX+DX: SY=SY+DY
|
||
|
7370 T(SX+13*(SY-1))=T(SX+13*(SY-1))+1
|
||
|
7380 RETURN
|
||
|
|
||
|
8000 GOSUB 5000: GOSUB 5000: GOSUB 5000: GOSUB 5000: PRINT "THE DRAGON GON GOT YOU!": END
|
||
|
|
||
|
9000 REM MOD: Remainder of P1 is returned in MOD
|
||
|
9000 MOD=ABS(P1)-10*INT(ABS(P1)/10): RETURN
|