mirror of
https://github.com/rfivet/BCG101.git
synced 2024-12-19 08:36:36 -05:00
116 lines
3.0 KiB
QBasic
116 lines
3.0 KiB
QBasic
10 ' AMAZIN -- DRAW A MAZE UP TO 14 BY 21
|
|
20 ' EDUSYSTEM 50 REFACTORING BY RENAUD FIVET
|
|
90 DEF FNR(R)=INT(RND(1)*R+1)
|
|
100 RANDOMIZE
|
|
110 DIM V(13,20)
|
|
120 PRINT "WHAT ARE YOUR WIDTH AND LENGTH";\ INPUT H,V
|
|
122 PRINT
|
|
130 IF H<2 THEN 132\ IF H>14 THEN 132
|
|
131 IF V<2 THEN 132\ IF V<=21 THEN 150
|
|
132 PRINT "MEANINGLESS DIMENSIONS, TRY AGAIN"
|
|
140 PRINT
|
|
141 GOTO 120
|
|
150 PRINT
|
|
151 PRINT
|
|
160 ' PICK ENTRY CELL ON TOP ROW AND DRAW UPPER WALL
|
|
161 C=H*V ' COUNT OF CELLS LEFT TO FILL
|
|
162 R=FNR(H)-1 ' R,0 TOP ENTRY CELL COORD
|
|
163 H=H-1\ V=V-1 ' COORD IN 0..H,0..V
|
|
170 FOR I=0 TO H
|
|
171 IF I=R THEN 174
|
|
172 PRINT ":--";
|
|
173 GOTO 175
|
|
174 PRINT ": ";
|
|
175 NEXT I
|
|
185 PRINT ":"
|
|
187 ' PICK EXIT CELL ON BOTTOM ROW AS CURRENT
|
|
190 R=FNR(H+1)-1\ S=V ' R,S CURRENT CELL COORD
|
|
192 V(R,S)=2
|
|
193 C=C-1
|
|
202 GOTO 260
|
|
209 ' SCAN FOR NEXT POSITION TO CHECK
|
|
210 R=R+1
|
|
215 IF R<=H THEN 250
|
|
220 R=0\ S=S+1
|
|
225 IF S<=V THEN 250
|
|
230 S=0
|
|
250 IF V(R,S)=0 THEN 210
|
|
255 ' CHECK FOR ADJACENT UNMARKED CELLS AND PICK ONE AT RANDOM
|
|
260 IF R=0 THEN 530\ IF V(R-1,S)<>0 THEN 530 ' L?
|
|
270 IF S=0 THEN 390\ IF V(R,S-1)<>0 THEN 390 ' LU?
|
|
290 IF R=H THEN 330\ IF V(R+1,S)<>0 THEN 330 ' LUR?
|
|
310 ON FNR(3) GOTO 790,820,860 ' LUR
|
|
320 ' LU
|
|
330 IF S=V THEN 370\ IF V(R,S+1)<>0 THEN 370 ' LUD?
|
|
350 ON FNR(3) GOTO 790,820,910 ' LUD
|
|
370 ON FNR(2) GOTO 790,820 ' LU
|
|
380 ' L
|
|
390 IF R=H THEN 470\ IF V(R+1,S)<>0 THEN 470 ' LR?
|
|
401 IF S=V THEN 450\ IF V(R,S+1)<>0 THEN 450 ' LRD?
|
|
430 ON FNR(3) GOTO 790,860,910 ' LRD
|
|
450 ON FNR(2) GOTO 790,860 ' LR
|
|
460 ' L
|
|
470 IF S=V THEN 790\ IF V(R,S+1)<>0 THEN 790 ' LD? OR L
|
|
500 ON FNR(2) GOTO 790,910 ' LD
|
|
520 '
|
|
530 IF S=0 THEN 670\ IF V(R,S-1)<>0 THEN 670 ' U?
|
|
541 IF R=H THEN 610\ IF V(R+1,S)<>0 THEN 610 ' UR?
|
|
550 IF S=V THEN 590\ IF V(R,S+1)<>0 THEN 590 ' URD?
|
|
570 ON FNR(3) GOTO 820,860,910 ' URD
|
|
590 ON FNR(2) GOTO 820,860 ' UR
|
|
600 '
|
|
610 IF S=V THEN 820\ IF V(R,S+1)<>0 THEN 820 ' UD? OR U
|
|
640 ON FNR(2) GOTO 820,910 ' UD
|
|
660 '
|
|
670 IF R=H THEN 740\ IF V(R+1,S)<>0 THEN 740 ' R?
|
|
681 IF S=V THEN 860\ IF V(R,S+1)<>0 THEN 860 ' RD? OR R
|
|
710 ON FNR(2) GOTO 860,910 ' RD
|
|
730 '
|
|
740 IF S=V THEN 210\ IF V(R,S+1)<>0 THEN 210 ' D? OR SCAN
|
|
770 GOTO 910 ' D
|
|
780 '
|
|
790 ' REMOVE LEFT WALL
|
|
800 R=R-1
|
|
801 V(R,S)=3
|
|
812 GOTO 999
|
|
820 ' REMOVE UP WALL
|
|
830 S=S-1
|
|
840 V(R,S)=2
|
|
850 GOTO 999
|
|
860 ' REMOVE RIGHT WALL
|
|
870 IF V(R,S)<2 THEN 880
|
|
872 V(R,S)=4
|
|
873 GOTO 890
|
|
880 V(R,S)=3
|
|
890 R=R+1
|
|
900 IF V(R,S)<>0 THEN 902\ V(R,S)=1
|
|
902 GOTO 999
|
|
910 ' REMOVE DOWN WALL
|
|
922 IF V(R,S)<2 THEN 940
|
|
930 V(R,S)=4
|
|
931 GOTO 950
|
|
940 V(R,S)=2
|
|
950 S=S+1
|
|
960 IF V(R,S)<>0 THEN 999\ V(R,S)=1
|
|
999 C=C-1\ IF C>0 THEN 260 ' LOOP WHILE C
|
|
1000 ' DRAW MAZE
|
|
1010 FOR J=0 TO V
|
|
1011 PRINT "I";
|
|
1012 FOR I=0 TO H
|
|
1013 IF V(I,J)<3 THEN 1030
|
|
1020 PRINT " ";
|
|
1021 GOTO 1040
|
|
1030 PRINT " I";
|
|
1040 NEXT I
|
|
1041 PRINT
|
|
1043 FOR I=0 TO H
|
|
1045 IF V(I,J)<=1 THEN 1060
|
|
1050 IF V(I,J)=3 THEN 1060
|
|
1051 PRINT ": ";
|
|
1052 GOTO 1070
|
|
1060 PRINT ":--";
|
|
1070 NEXT I
|
|
1071 PRINT ":"
|
|
1072 NEXT J
|
|
1073 END
|