'on demand random retraceable maze
North
AS INTEGER 'what room lies in direction Walls
AS Roomlook
'walls or passages Created
AS _BYTE 'as this room been visited?
DIM SHARED Maze
(32000) AS room
, a$
, b$
, c$
(1), d$
(5), e$
(1) CONST UP
= 1, DOWN
= 2, LEFT
= 3, RIGHT
= 4 a$ = "To the "
b$ = " there is a "
c$(0) = "wall": c$(1) = "passage"
d$(UP) = "north": d$(DOWN) = "south": d$(LEFT) = "west": d$(RIGHT) = "east"
e$(0) = "unknown": e$(1) = "known"
'make maze ready to explore
ClearMaze
makerooms 'premake some wall sections
'create the starting room
'pick which walls you can pass
Maze
(0).Walls.up
= INT(RND * 2)Maze
(0).Walls.down
= INT(RND * 2)Maze
(0).Walls.left
= INT(RND * 2)Maze
(0).Walls.right
= INT(RND * 2)Maze(0).Created = TRUE
current% = 0 'room player is in
lastmade% = 0 'last room created
LOCATE 8, , 0 ' turn cursor off DescribeRoom current%
drawroom current%
LOCATE 8, 1, 1 ' turn cursor on
MessageHandler "You head north..."
IF Maze
(current%
).Walls.up
THEN 'if you can go up IF Maze
(current%
).North
>= 0 THEN 'is north already referenced MessageHandler "you have been here before"
current% = Maze(current%).North
ELSE 'never been north in this room MessageHandler "you find somewhere new"
lastmade% = lastmade% + 1
nul% = CreateRoom(lastmade%, current%, UP)
current% = lastmade%
MessageHandler "You head south..."
IF Maze
(current%
).Walls.down
THEN 'if you can go down IF Maze
(current%
).South
>= 0 THEN 'is south already referenced MessageHandler "you have been here before"
current% = Maze(current%).South
ELSE 'never been south in this room MessageHandler "you find somewhere new"
lastmade% = lastmade% + 1
nul% = CreateRoom(lastmade%, current%, DOWN)
current% = lastmade%
MessageHandler "You head west..."
IF Maze
(current%
).Walls.left
THEN 'if you can go left IF Maze
(current%
).West
>= 0 THEN 'is west already referenced MessageHandler "you have been here before"
current% = Maze(current%).West
ELSE 'never been west in this room MessageHandler "you find somewhere new"
lastmade% = lastmade% + 1
nul% = CreateRoom(lastmade%, current%, LEFT)
current% = lastmade%
MessageHandler "You head east..."
IF Maze
(current%
).Walls.right
THEN 'if you can go right IF Maze
(current%
).East
>= 0 THEN 'is east already referenced MessageHandler "you have been here before"
current% = Maze(current%).East
ELSE 'never been north in this room MessageHandler "you find somewhere new"
lastmade% = lastmade% + 1
nul% = CreateRoom(lastmade%, current%, RIGHT)
current% = lastmade%
exitflag%% = TRUE
kbd& = 0
FUNCTION CreateRoom
(Going%
, From%
, Direction%%
) Maze
(Going%
).Walls.up
= INT(RND * 2) Maze
(Going%
).Walls.down
= INT(RND * 2) Maze
(Going%
).Walls.left
= INT(RND * 2) Maze
(Going%
).Walls.right
= INT(RND * 2) Maze(Going%).Created = TRUE
'which direction did player head
Maze(Going%).Walls.down = 1 'down has to be open, direction coming from
Maze(Going%).South = From% 'south goes back to previous room
Maze(From%).North = Going% 'the room id north of previous room
Maze(Going%).Walls.up = 1 'up has to be open, direction coming from
Maze(Going%).North = From% 'north goes back to previous room
Maze(From%).South = Going% 'the room id south of previous room
Maze(Going%).Walls.right = 1 'left has to be open, direction coming from
Maze(Going%).East = From% 'east goes back to previous room
Maze(From%).West = Going% 'the room id west of previous room
Maze(Going%).Walls.left = 1 'right has to be open, direction coming from
Maze(Going%).West = From% 'west goes back to previous room
Maze(From%).East = Going% 'the room id east of previous room
MessageHandler
"You are currently in room" + STR$(id%
) MessageHandler a$ + d$(UP) + b$ + c$(Maze(id%).Walls.up)
MessageHandler a$ + d$(DOWN) + b$ + c$(Maze(id%).Walls.down)
MessageHandler a$ + d$(LEFT) + b$ + c$(Maze(id%).Walls.left)
MessageHandler a$ + d$(RIGHT) + b$ + c$(Maze(id%).Walls.right)
MessageHandler blank$
Maze(i%).North = -1
Maze(i%).South = -1
Maze(i%).West = -1
Maze(i%).East = -1
Maze(i%).Created = FALSE
PRINT #1, "north leads to "; Maze
(i%
).North
PRINT #1, "south leads to "; Maze
(i%
).South
PRINT #1, "west leads to "; Maze
(i%
).West
PRINT #1, "east leads to "; Maze
(i%
).East
PRINT #1, "up wall status "; Maze
(i%
).Walls.up
PRINT #1, "down wall status "; Maze
(i%
).Walls.down
PRINT #1, "left wall status "; Maze
(i%
).Walls.left
PRINT #1, "right wall status "; Maze
(i%
).Walls.right
IF Maze
(id%
).Walls.up
THEN 'has passage IF Maze
(id%
).Walls.left
THEN 'has passage IF Maze
(id%
).Walls.right
THEN 'has passage IF Maze
(id%
).Walls.down
THEN 'has passage
'ÚÄ¿³ÀÙ
wall$(0) = " ÚÄÄÄÄÄÄÄÄ¿ "
wall$(1) = " ÚÄÄÙ ÀÄÄ¿ "
wall$(2) = " ÀÄÄÄÄÄÄÄÄÙ "
wall$(3) = " ÀÄÄ¿ ÚÄÄÙ "
SUB MessageHandler
(txt$
) 'define message area
'display message
'restore screen area