mirror of
https://github.com/inexorabletash/jsbasic.git
synced 2024-10-05 16:56:21 +00:00
91 lines
4.9 KiB
Plaintext
91 lines
4.9 KiB
Plaintext
0 PR#0
|
|
10 DEF FN R(X) = INT ( RND (1) * X) + 1: DEF FN M4(Y) = Y - INT (Y / 4) * 4: DIM NU(16)
|
|
15 R$ = "4567RTYUFGHJVBNM":P$ = "ABCD..........N...IJK.L..PO...E.FHM..G"
|
|
20 POKE - 16368,0
|
|
30 TEXT : HOME : VTAB 4: HTAB 14: PRINT "THE PUZZLER"
|
|
40 VTAB 15: HTAB 12: PRINT "by Gregg Buntin"
|
|
50 FOR I = 1 TO 2000: NEXT I
|
|
60 VTAB 20: PRINT "Do you wish instructions";: INPUT I$
|
|
70 IF LEFT$ (I$,1) < > "Y" THEN 190
|
|
80 HOME : VTAB 2: HTAB 14: PRINT "THE PUZZLER"
|
|
90 VTAB 4: PRINT "The object of this game is to get all ofthe numbers in order from 1 to 15."
|
|
100 PRINT : PRINT "The basic command keys are:";: HTAB 36: INVERSE : PRINT "A": NORMAL : HTAB 36: PRINT ":": HTAB 36: PRINT ":"
|
|
110 HTAB 33: INVERSE : PRINT "<-";: NORMAL : PRINT " + ";: INVERSE : PRINT "->";: NORMAL : PRINT
|
|
120 PRINT "By means of these keys you" TAB( 36) ":": PRINT "will exchange the blank" TAB( 36) ":"
|
|
130 PRINT "space with the number in the";: INVERSE : HTAB 36: PRINT "Z": NORMAL
|
|
140 PRINT "up,down,left or right positions."
|
|
145 PRINT : PRINT : PRINT "Alternatively, use the [mouse] and [END]key, or any highlighted key in the"
|
|
148 PRINT "displayed diagram, to move up to ALL thetiles in a row or column at once!"
|
|
150 VTAB 24: PRINT SPC( 7)"Press <ESC> to start game";
|
|
160 K = PEEK ( - 16384): IF K < > 155 THEN 160
|
|
190 POKE - 16368,0: HOME : VTAB 4: HTAB 14: PRINT "THE PUZZLER": VTAB 12
|
|
200 PRINT "Type N to start a (N)EW GAME"
|
|
220 K = PEEK ( - 16384): IF K = 155 GOTO 480
|
|
230 ON K < > 206 GOTO 220: POKE - 16368,0
|
|
260 HOME : PRINT "SCRAMBLING PUZZLE.............."
|
|
262 I = RND ( - PEEK (79) * 999 - PEEK (78)): REM RANDOM SEED
|
|
265 FOR I = 1 TO 16:NU(I) = I: NEXT
|
|
270 FOR I = 1 TO 40:Q = FN R(15)
|
|
280 K = FN R(14):K = (K > = Q) + K
|
|
290 X = NU(Q):NU(Q) = NU(K):NU(K) = X: NEXT
|
|
292 A = FN R(16):Y = 16: X = 4: ON A < 13 GOSUB 580
|
|
295 X = 1: ON A < Y GOSUB 580
|
|
300 TEXT : HOME : GR : COLOR= 12
|
|
310 FOR I = 0 TO 18: Q = 38 - I: HLIN I,Q AT I: HLIN I,Q AT Q
|
|
320 VLIN I,Q AT I: VLIN I,Q AT Q: NEXT : PLOT 19,19
|
|
330 COLOR= 1: FOR I = 9 TO 29 STEP 10: HLIN 0,38 AT I: VLIN 0,38 AT I: NEXT
|
|
350 FOR PL = 1 TO 16: GOSUB 380: REM DISPLAY WHOLE GRID
|
|
360 NEXT :PL = A: PRINT "At any time,": PRINT "press <ESC>": PRINT "to exit.": GOTO 440
|
|
365 REM 370-430, 840-930 - ROUTINE TO DISPLAY NUMBERS
|
|
370 COLOR= 12: GOTO 390
|
|
380 COLOR= 2
|
|
390 IF NU(PL) = 16 THEN RETURN
|
|
400 Q = PL - 1: GOSUB 600
|
|
410 Q = NU(PL) > 9: ON Q GOSUB 870
|
|
420 X = Q * 2 + X + 2
|
|
430 Q = NU(PL) - Q * 10: ON Q + 1 GOTO 840,870,880,850,890,900,910,920,840,930
|
|
435 REM DISPLAY ACTIVE-KEY GRID
|
|
440 VTAB 21: GOSUB 825: I = I + 1: FOR Y = 0 TO 3: IF Y THEN PRINT
|
|
450 HTAB 17: FOR X = 1 TO 4: K = (X = I) + (Y = Q): IF K THEN INVERSE
|
|
460 PRINT MID$ (R$,Y * 4 + X,K < 2);: NORMAL : PRINT TAB( X * 2 + 17): NEXT : NEXT
|
|
465 REM GET KEY, MOVE TILE TO EMPTY SPACE
|
|
470 K = ( PEEK (49250) > 127) * 301 + PEEK ( - 16384): IF K < 128 THEN 470
|
|
480 POKE - 16368,0
|
|
490 IF K = 155 THEN TEXT : HOME : PRINT "BYE-BYE": END
|
|
500 IF K > 300 GOTO 610: REM "BUTTON" ([END] KEY) PRESSED
|
|
510 IF K > 179 AND K < 218 THEN Q = ASC ( MID$ (P$,K - 179,1)) - 65: IF Q > = O THEN GOSUB 600: GOTO 630
|
|
520 K = INT ((K = 193 OR K = 218 OR K = 136 OR K = 149) * K / 7)
|
|
530 IF NOT K GOTO 470
|
|
540 I = K < 22:A = (K - 29) * 2
|
|
550 IF K < 20 = FN M4(PL) AND I OR (A + 8.5 - PL) * A * NOT I < 0 GOTO 470
|
|
560 IF I THEN A = K - 20
|
|
570 GOSUB 770: GOTO 810
|
|
580 FOR Y = Y TO A + X STEP -X:NU(Y) = NU(Y - X): NEXT : NU(Y) = 16: RETURN
|
|
600 GOSUB 830:X = I * 10 + 1:Y = Q * 10 + 2: RETURN
|
|
605 REM HANDLE "JOYSTICK" (MOUSE) AND MULTIPLE TILES
|
|
606 REM INTERPRET TRUE MOUSE POSITION (PC) BASED ON ITS CURSOR
|
|
610 X = PDL (0) / 6.4: Y = PDL(1) * .1875: K = SCRN (X,Y)
|
|
620 IF K < > 2 AND K < > 12 OR Y > 38 GOTO 470
|
|
630 GOSUB 825: X = INT (X / 10) - I
|
|
640 Y = INT (Y / 10) - Q
|
|
650 IF NOT X = NOT Y GOTO 470
|
|
660 A = SGN(Y) * 4 + SGN (X): FOR K = 1 TO ABS (X + Y): GOSUB 770: NEXT
|
|
670 ON PEEK (49250) > 127 GOTO 670: GOTO 810
|
|
770 PL = PL + A: GOSUB 370
|
|
780 NU(PL - A) = NU(PL):NU(PL) = 16:PL = PL - A
|
|
790 GOSUB 380:PL = PL + A: RETURN
|
|
800 REM TEST FOR SOLVED PUZZLE
|
|
810 Q = 0: FOR I = 1 TO 16: Q = NU(I) < > I OR Q: NEXT : IF Q GOTO 440
|
|
820 HOME : PRINT "CONGRATULATIONS!": PRINT : GOTO 200
|
|
825 Q = PL - 1
|
|
830 I = FN M4(Q):Q = INT (Q / 4): RETURN
|
|
840 VLIN Y,Y + 4 AT X
|
|
850 IF Q THEN PLOT X + 1,Y + 2
|
|
860 HLIN X,X + 1 AT Y: HLIN X,X + 2 AT Y + 5: VLIN Y,Y + 4 AT X + 2: RETURN
|
|
870 VLIN Y,Y + 5 AT X + 1: PLOT X,Y + 1: HLIN X,X + 2 AT Y + 5: RETURN
|
|
880 HLIN X,X + 2 AT Y: VLIN Y,Y + 2 AT X + 2: PLOT X + 1,Y + 2: VLIN Y + 3,Y + 5 AT X: HLIN X,X + 2 AT Y + 5: RETURN
|
|
890 VLIN Y,Y + 5 AT X + 2: VLIN Y,Y + 3 AT X: PLOT X + 1,Y + 3: RETURN
|
|
900 HLIN X,X + 2 AT Y: VLIN Y,Y + 2 AT X: PLOT X + 1,Y + 2: VLIN Y + 3,Y + 4 AT X + 2: HLIN X,X + 1 AT Y + 5: RETURN
|
|
910 VLIN Y + 1,Y + 5 AT X: HLIN X + 1,X + 2 AT Y: VLIN Y + 2,Y + 5 AT X + 2: PLOT X + 1,Y + 2: PLOT X + 1,Y + 5: RETURN
|
|
920 HLIN X,X + 2 AT Y: VLIN Y,Y + 5 AT X + 2: RETURN
|
|
930 VLIN Y,Y + 5 AT X + 2: VLIN Y,Y + 2 AT X: PLOT X + 1,Y: PLOT X + 1,Y + 2: HLIN X,X + 1 AT Y + 5: RETURN |