Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
The Maze
#9
I found a MazeGen program, written in QB64, and figured that you could probably adapt if for your purposes.

It produces a 40x40 maze (walls only - sorry...) and outputs to the screen for a few seconds then ends.

It should not be too difficult to modify the output to a file...

I know... It's rough... but, until an Editor magically pops up, it's all I could throw together. I hope it helps...

ps: I made a very-crude Editor, in another language that shall remain nameless, and could possibly be converted to N7... but do not get your hopes up... At the moment it has more bugs than a carcass...

Code:
' Open a window and enable double buffering.
set window "MazeGen", 680, 680, false
set redraw off

randomize clock()

mWidth = 41
mHeight = 41

'   Create array and fill
maze = dim(mWidth, mHeight)
for x = 0 to mWidth - 1
    for y = 0 to mHeight - 1
        maze[x][y] = "#"
    next
next

'   Initial start locations
currentX = rnd(0, mWidth - 1)
currentY = rnd(0, mHeight - 1)

'   Values must be odd
if currentX % 2 = 0     currentX = currentX + 1
if currentY % 2 = 0     currentY = currentY + 1
maze[currentX][currentY] = " "

'   Generate Maze
done = false
do
    for i = 0 to 99
        oldX = currentX
        oldY = currentY
       
        '   Move in random directions
        select case rnd(0, 3)
            case 0
                if currentX + 2 < mWidth    currentX = currentX + 2
            case 1
                if currentY + 2 < mHeight   currentY = currentY + 2
            case 2
                if currentX - 2 > 0         currentX = currentX - 2
            case 3
                if currentY - 2 > 0         currentY = currentY - 2
        endsel
       
        '   If cell is unvisited then connect it
        if maze[currentX][currentY] = "#"
            maze[currentX][currentY] = " "
            maze[int((currentX + oldX) / 2)][(currentY + oldY) / 2] = " "
        endif
    next
   
    '   Check if all cells are visited
    done = true
    for x = 1 to mWidth - 1 step 2
        for y = 1 to mHeight - 1 step 2
            if maze[x][y] = "#"     done = false
        next
    next
until done = true

'   Draw Maze
set color 255, 255, 255
for y = 0 to mHeight - 1
    for x = 0 to mWidth - 1
        set caret x * 16, y * 16
        wln maze[x][y]
    next
    wln
next
redraw
wait 3000; end

I know... It is not very efficient, but it gets the job done... lol

J
Logic is the beginning of wisdom.
Reply


Messages In This Thread
The Maze - by 1micha.elok - 04-09-2024, 09:50 AM
RE: The Maze - by johnno56 - 04-09-2024, 11:15 AM
RE: The Maze - by 1micha.elok - 04-09-2024, 11:24 AM
RE: The Maze - by 1micha.elok - 04-12-2024, 06:59 AM
RE: The Maze - by johnno56 - 04-12-2024, 11:23 AM
RE: The Maze - by 1micha.elok - 04-12-2024, 12:54 PM
RE: The Maze - by Marcus - 04-12-2024, 06:08 PM
RE: The Maze - by 1micha.elok - 04-12-2024, 11:32 PM
RE: The Maze - by johnno56 - 04-13-2024, 07:53 AM
RE: The Maze - by 1micha.elok - 04-14-2024, 12:32 AM
RE: The Maze - by 1micha.elok - 04-15-2024, 01:35 PM
RE: The Maze - by johnno56 - 04-14-2024, 03:17 AM
RE: The Maze - by johnno56 - 04-15-2024, 05:48 PM
RE: The Maze - by 1micha.elok - 04-22-2024, 10:34 AM
RE: The Maze - by 1micha.elok - 04-24-2024, 04:41 AM
RE: The Maze - by Marcus - 04-24-2024, 06:46 AM

Forum Jump:


Users browsing this thread: 3 Guest(s)