home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC Format 22
/
Disk22.iso
/
MAZE.ZIP
/
MAZE.BAS
next >
Wrap
BASIC Source File
|
1993-05-24
|
13KB
|
486 lines
DECLARE SUB Program.Notes ()
DECLARE FUNCTION Show.Time$ (n&)
DECLARE FUNCTION Isoneof% (n%, a$)
DECLARE SUB Set.View (direction%, down%, across%)
DECLARE SUB Sign.On ()
DECLARE FUNCTION Central$ (xx%, n$)
DECLARE FUNCTION Fact% (n%)
DECLARE SUB Draw.Blank (n%)
DECLARE SUB Draw.Wall (n%, door%, Picture%, picol%)
DECLARE SUB Load.Data (wide%, deep%)
DEFINT A-Z
COMMON SHARED strtx, strty, finx, finy, Aspect1, Aspect2, Multiplier!, bot.line
deep = 16: wide = 24
DIM SHARED grid(1 TO deep, 1 TO wide)
CALL Load.Data(deep, wide)
DO
CLS
LOCATE 3, 45: PRINT "2 - CGA (640 x 200)"
LOCATE 4, 45: PRINT "3 - Hercules (720 x 348)"
LOCATE 5, 45: PRINT "8 - EGA/VGA (640 x 200)"
LOCATE 6, 45: PRINT "9 - EGA/VGA (640 x 350)"
LOCATE 7, 45: PRINT "12 - VGA (640 x 480)"
LOCATE 3, 1
INPUT "Enter Screen Mode: (2,3,8,9,12) "; Scrn.Mode
IF Isoneof(Scrn.Mode, "0203080912") THEN EXIT DO
LOOP
bot.line = 25
Multiplier! = 2
Aspect1 = 85
Aspect2 = 115
SELECT CASE Scrn.Mode
CASE 9, 3
Multiplier! = 3.5
Aspect1 = 149
Aspect2 = 201
CASE 12
Multiplier! = 4.8
Aspect1 = 204
Aspect2 = 276
bot.line = 30
END SELECT
DEF FNx1 (n) = 270 - (6.4 * Fact(n - 1))
DEF FNy1 (n) = Aspect1 - (Multiplier! * Fact(n - 1))
DEF FNx2 (n) = 370 + (6.4 * Fact(n - 1))
DEF FNy2 (n) = Aspect2 + (Multiplier! * Fact(n - 1))
start:
CLS
CALL Sign.On
SCREEN Scrn.Mode
direction = 1 'North = 1
down = strtx 'South = 3
across = strty 'East = 2
'West = 4
REM CALL Program.Notes: END
CALL Set.View(direction, down, across)
start& = TIMER
DO
LOCATE bot.line, 60: PRINT "Direction: "; MID$("NESW", direction, 1);
LOCATE bot.line, 1: PRINT "Down: "; down;
LOCATE bot.line, 15: PRINT "Across: "; across;
i$ = ""
WHILE i$ = ""
i$ = INKEY$
LOCATE bot.line, 32
PRINT Show.Time$(TIMER - start&);
WEND
j = ASC(RIGHT$(i$, 1))
IF j = 75 THEN ' Left
direction = direction - 1
IF direction = 0 THEN direction = 4
CLS
END IF
IF j = 77 THEN ' Right
direction = direction + 1
IF direction = 5 THEN direction = 1
CLS
END IF
IF i$ = CHR$(27) THEN EXIT DO
IF i$ = " " THEN
SELECT CASE direction
CASE 1 ' North
IF grid(down - 1, across) <> 1 THEN
down = down - 1
END IF
CASE 2 ' East
IF grid(down, across + 1) <> 1 THEN
across = across + 1
END IF
CASE 3 ' South
IF grid(down + 1, across) <> 1 THEN
down = down + 1
END IF
CASE 4 ' West
IF grid(down, across - 1) <> 1 THEN
across = across - 1
END IF
END SELECT
END IF
CALL Set.View(direction, down, across)
IF down = finx AND across = finy THEN
finish& = TIMER - start&
PRINT Central$(bot.line / 2, "WELL DONE - THAT TOOK:")
PRINT Central$((bot.line / 2) + 2, Show.Time$(finish&))
PLAY "MF O3 L8 C P16 L16 C C L8 E C L8 E G E G O4 L4 C."
i$ = INPUT$(1)
END
END IF
LOOP
SCREEN 0
END
FUNCTION Central$ (xx, n$)
LOCATE xx, (80 - LEN(n$)) / 2
PRINT n$;
END FUNCTION
SUB Draw.Blank (n)
x1 = FNx1(n)
x2 = FNx2(n)
y1 = FNy1(n)
y2 = FNy2(n)
LINE (x1, y1)-(x2, y2), 0, BF
LINE (x1, y1)-(x2, y2), 11, B
END SUB
SUB Draw.Wall (n, door, Picture, picol)
' 0 = no door.
' 1=on left.
' 2=on right.
' 3=Door both sides.
x1 = FNx1(n)
x2 = FNx2(n)
y1 = FNy1(n)
y2 = FNy2(n)
xx1 = FNx1(n - 1)
yy1 = FNy1(n - 1)
yy2 = FNy2(n - 1)
xx2 = FNx2(n - 1)
' Left hand wall first.
IF door = 1 OR door = 3 THEN
LINE (xx1, yy1)-(x1, y1), 0
LINE (xx1, yy2)-(x1, y2), 0
LINE (xx1, yy1)-(x1 + 1, yy1), 11
LINE (xx1, yy2)-(x1 + 1, yy2), 11
ELSE
LINE (xx1 - 2, yy1)-(x1 + 1, yy1), 0
LINE (xx1 - 2, yy2)-(x1 + 1, yy2), 0
LINE (xx1, yy1)-(x1, y1), 11
LINE (xx1, yy2)-(x1, y2), 11
END IF
LINE (x1 + 1, yy1 + 1)-(xx1 - 1, yy2 - 1), 0, BF ' Blank out Picture
' Right Hand Wall
IF door = 2 OR door = 3 THEN
LINE (xx2, yy1)-(x2, y1), 0
LINE (xx2, yy2)-(x2, y2), 0
LINE (xx2, yy1)-(x2 - 1, yy1), 11
LINE (xx2, yy2)-(x2 - 1, yy2), 11
ELSE
LINE (xx2 + 2, yy1)-(x2 - 1, yy1), 0
LINE (xx2 + 2, yy2)-(x2 - 1, yy2), 0
LINE (xx2, yy1)-(x2, y1), 11
LINE (xx2, yy2)-(x2, y2), 11
END IF
LINE (xx2 + 1, yy1 + 1)-(x2 - 1, yy2 - 1), 0, BF ' Blank out Picture
LINE (x1, y1)-(x1, y2), 11 ' Verticals
LINE (x2, y1)-(x2, y2), 11
' Picture
fatend = y2 - y1
thinend = yy2 - yy1
wdth = xx1 - x1
SELECT CASE Picture
CASE 1 ' On left
tlx = x1 + (wdth * .2)
tly = y1 + (fatend * .3)
trx = xx1 - (wdth * .2)
try = yy1 + (thinend * .3)
blx = tlx
bly = y2 - (fatend * .3)
brx = trx
bry = yy2 - (thinend * .3)
CASE 2
tlx = xx2 + (wdth * .2)
tly = yy1 + (thinend * .3)
trx = x2 - (wdth * .2)
try = y1 + (fatend * .3)
blx = tlx
bly = yy2 - (thinend * .3)
brx = trx
bry = y2 - (fatend * .3)
CASE 3, 0
EXIT SUB
END SELECT
LINE (tlx, tly)-(trx, try), 15
LINE -(brx, bry), 15
LINE -(blx, bly), 15
LINE -(tlx, tly), 15
IF Picture = 1 THEN
PAINT (trx - 5, try + 5), picol - 5, 15
ELSE
PAINT (tlx + 5, tly + 5), picol - 5, 15
END IF
END SUB
FUNCTION Fact (n)
temp = 0
FOR l = 1 TO n
temp = temp + l
NEXT l
Fact = temp
END FUNCTION
FUNCTION Isoneof (n, a$)
Isoneof = 0
FOR x = 1 TO LEN(a$) STEP 2
IF VAL(MID$(a$, x, 2)) = n THEN Isoneof = -1: EXIT FOR
NEXT x
END FUNCTION
SUB Load.Data (deep, wide)
OPEN "I", 1, "MAZE.DAT"
FOR x = 1 TO deep
INPUT #1, n$
FOR y = 1 TO wide
grid(x, y) = VAL(MID$(n$, y, 1))
IF grid(x, y) = 2 THEN
strtx = x
strty = y
grid(x, y) = 0
ELSEIF grid(x, y) = 3 THEN
finx = x
finy = y
grid(x, y) = 0
END IF
NEXT y
NEXT x
REM
END SUB
SUB Program.Notes
CLS
CALL Draw.Wall(7, 0, 0, 0)
LOCATE 6, 12: PRINT "x1,y1"
LOCATE 20, 12: PRINT "x1,y2"
LOCATE 6, 66: PRINT "x2,y1"
LOCATE 20, 66: PRINT "x2,y2"
LOCATE 8, 24: PRINT "xx1,yy1"
LOCATE 18, 24: PRINT "xx1,yy2"
LOCATE 8, 51: PRINT "xx2,yy1"
LOCATE 18, 51: PRINT "xx2,yy2"
i$ = INPUT$(1)
CLS
CALL Draw.Wall(7, 1, 0, 0)
LOCATE 6, 66: PRINT "x2,y1"
LOCATE 20, 66: PRINT "x2,y2"
LOCATE 8, 51: PRINT "xx2,yy1"
LOCATE 18, 51: PRINT "xx2,yy2"
LOCATE 6, 12: PRINT "x1,y1"
LOCATE 20, 12: PRINT "x1,y2"
LOCATE 8, 24: PRINT "xx1,yy1"
LOCATE 18, 24: PRINT "xx1,yy2"
LOCATE 8, 11: PRINT "x1,yy1"
LOCATE 18, 11: PRINT "x1,yy2"
LOCATE 8, 66: PRINT "x2,yy1"
LOCATE 18, 66: PRINT "x2,yy2"
i$ = INPUT$(1)
CLS
PRINT Central$(1, "For each wall section, lines are drawn that make the section a wall AND a")
PRINT Central$(2, "door. However, if the section is a door, then the diagonals that make it")
PRINT Central$(3, "a wall are drawn in COLOR 0 to blank it out. The converse applies if the ")
PRINT Central$(4, "section is to be drawn as a wall, the horizontal lines that would make it")
PRINT Central$(5, "a door are drawn, but again in COLOUR zero to blank it out. This over- ")
PRINT Central$(6, "writes the section drawn before the move was made. ")
i$ = INPUT$(1)
END SUB
SUB Set.View (direction, down, across)
SELECT CASE direction
CASE 1 ' Facing North
hey = down
xx = 10
DO UNTIL grid(hey, across) = 1
door = 0
IF grid(hey, across - 1) <> 1 THEN door = door + 1
IF grid(hey, across + 1) <> 1 THEN door = door + 2
IF grid(hey, across) = 9 THEN
Picture = 1 ' On left
ELSEIF grid(hey, across) = 7 THEN
Picture = 2 ' On right
ELSEIF grid(hey, across) = 6 THEN
Picture = 3 ' Straight on
ELSE
Picture = 0 ' No Picture
END IF
CALL Draw.Wall(xx, door, Picture, grid(hey, across))
xx = xx - 1
hey = hey - 1
LOOP
CALL Draw.Blank(xx)
CASE 2 ' Facing East
hey = across
xx = 10
DO UNTIL grid(down, hey) = 1
door = 0
IF grid(down - 1, hey) <> 1 THEN door = door + 1
IF grid(down + 1, hey) <> 1 THEN door = door + 2
IF grid(down, hey) = 6 THEN
Picture = 1 ' On left
ELSEIF grid(down, hey) = 8 THEN
Picture = 2 ' On right
ELSEIF grid(down, hey) = 7 THEN
Picture = 3 ' Straight on
ELSE
Picture = 0 ' No Picture
END IF
CALL Draw.Wall(xx, door, Picture, grid(down, hey))
xx = xx - 1
hey = hey + 1
LOOP
CALL Draw.Blank(xx)
CASE 3 ' Facing South
hey = down
xx = 10
DO UNTIL grid(hey, across) = 1
door = 0
IF grid(hey, across + 1) <> 1 THEN door = door + 1
IF grid(hey, across - 1) <> 1 THEN door = door + 2
IF grid(hey, across) = 7 THEN
Picture = 1 ' On left
ELSEIF grid(hey, across) = 9 THEN
Picture = 2 ' On right
ELSEIF grid(hey, across) = 8 THEN
Picture = 3 ' Straight on
ELSE
Picture = 0 ' No Picture
END IF
CALL Draw.Wall(xx, door, Picture, grid(hey, across))
xx = xx - 1
hey = hey + 1
LOOP
CALL Draw.Blank(xx)
CASE 4 ' Facing West
hey = across
xx = 10
DO UNTIL grid(down, hey) = 1
door = 0
IF grid(down + 1, hey) <> 1 THEN door = door + 1
IF grid(down - 1, hey) <> 1 THEN door = door + 2
IF grid(down, hey) = 8 THEN
Picture = 1 ' On left
ELSEIF grid(down, hey) = 6 THEN
Picture = 2 ' On right
ELSEIF grid(down, hey) = 9 THEN
Picture = 3 ' Straight on
ELSE
Picture = 0 ' No Picture
END IF
CALL Draw.Wall(xx, door, Picture, grid(down, hey))
xx = xx - 1
hey = hey - 1
LOOP
CALL Draw.Blank(xx)
END SELECT
IF Picture = 3 THEN
x1 = FNx1(xx)
x2 = FNx2(xx)
y1 = FNy1(xx)
y2 = FNy2(xx)
wdth = x2 - x1
depth = y2 - y1
tlx = x1 + (wdth * .2)
tly = y1 + (depth * .3)
brx = x2 - (wdth * .2)
bry = y2 - (depth * .3)
LINE (tlx, tly)-(brx, bry), 15, B
PAINT (tlx + 10, tly + 10), direction, 15
END IF
END SUB
FUNCTION Show.Time$ (n&)
mins = FIX(n& / 60)
secs = n& - (mins * 60)
IF mins < 2 THEN m$ = " min. " ELSE m$ = " mins. "
Show.Time$ = STR$(mins) + m$ + STR$(secs) + " secs. "
END FUNCTION
SUB Sign.On
COLOR 12
PRINT Central$(9, "Cheapo Nasty Productions Presents:")
COLOR 11
PRINT Central$(10, "EXPERIMENTAL MAZE PROGRAM")
PRINT Central$(11, "By: D. M. EVANS 1993")
COLOR 14
LOCATE 14, 15: PRINT "USE SPACEBAR TO MOVE FORWARD. USE LEFT/RIGHT CURSOR"
LOCATE 15, 15: PRINT "KEYS TO TURN LEFT/RIGHT. PRESS [ESC] TO ABANDON SHIP"
COLOR 15
LOCATE 17, 15: PRINT "TRY TO FIND YOUR WAY OUT IN THE QUICKEST TIME. PRESS"
LOCATE 18, 15: PRINT "`H' KEY NOW TO DISCOVER EXIT COORDINATES OR ANY OTHER"
LOCATE 19, 15: PRINT "KEY TO ENTER THE MAZE"
DO
i$ = UCASE$(INPUT$(1))
IF i$ = "H" THEN
CLS
PRINT "SQUARE: "; finx, finy
ELSE
CLS
EXIT DO
END IF
LOOP
END SUB