///////////////////////////////////////////////////////////////// // // // Module: mazekit.txt // // // // Universe: "Either/Or" // // // // Description: The tasks in this module allow you to create // // and display mazes of up to size 25x25. // // // // Example: The following program will create and dis- // // play a 20x16 maze in the upper-left corner // // of a window: // // // // Ultra-SiMPLE [] // // make maze_rjb (20, 16) @ // // draw maze_rjb (0, 0, 10) @ // // Append L: mazekit // // // // Example: The following program will create a 25x21 // // maze with two entrances and display it in // // blue on a white background: // // // // Ultra-SiMPLE [] // // randomize; cls (15) // // make maze_rjb (25, 21) @ // // entrance_rjb (2, 15) @ // // entrance_rjb (8, 5) @ // // line color (1); line size (3) // // draw maze_rjb (145, 25, 14) @ // // Append L: mazekit // // // // Author: Bob Bishop // // // ///////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////// // // // Task: make maze_rjb (Int dx, Int dy) // // // // Description: Creates (but does not display) a maze of // // a specified size // // // // Parameters: dx: The number of cells (2-25) in the // // maze's horizontal direction // // dy: The number of cells (2-25) in the // // maze's vertical direction // // // ///////////////////////////////////////////////////////////////// // // // Task: entrance_rjb (Int w, Int loc) // // // // Description: Creates an entrance to the maze at a // // specified location // // // // Parameters: w: Specifies the wall in which the // // entrance is to be created: // // // // 1: Top wall // // 2: Right wall // // 4: Bottom wall // // 8: Left wall // // // // loc: The location of the entrance relative // // to the upper-left corner of the maze // // // ///////////////////////////////////////////////////////////////// // // // Task: draw maze_rjb (Int x, Int y, Int size) // // // // Description: Displays the maze at a specified location // // on the screen // // // // Parameters: x: The x-coordinate at which the upper- // // left corner of the maze should appear // // y: The y-coordinate at which the upper- // // left corner of the maze should appear // // size: The physical size at which each cell // // of the maze is to be drawn // // // ///////////////////////////////////////////////////////////////// Task make maze_rjb (Int dx, Int dy) Common Int grid_rjb[25][25], dx_rjb, dy_rjb Int xyq[625] Int xcand[4], ycand[4], mask[4] dx_rjb=dx; dy_rjb=dy If (dx<2) dx_rjb=2 If (dy<2) dy_rjb=2 If (dx>25) dx_rjb=25 If (dy>25) dy_rjb=25 Do j=0, dx_rjb-1 Do k=0, dy_rjb-1 grid_rjb[j][k]=0 Loop k Loop j qpntr=1 xyq[0]=dx_rjb/2+256*(dy_rjb/2) Do qpntr=qpntr-1; If (qpntr<0) Break x=xyq[qpntr]%256; y=xyq[qpntr]/256 Do numcand=0 If (x>0) If (grid_rjb[x-1][y]=0) xcand[numcand]=x-1; ycand[numcand]=y mask[numcand]=40 numcand=numcand+1 End If End If If (x0) If (grid_rjb[x][y-1]=0) xcand[numcand]=x; ycand[numcand]=y-1 mask[numcand]=65 numcand=numcand+1 End If End If If (y=dx_rjb | y>=dy_rjb Return bits=0 If (d=1) xx=x; yy=y-1; bits=65 If (d=2) xx=x+1; yy=y; bits=130 If (d=4) xx=x; yy=y+1; bits=20 If (d=8) xx=x-1; yy=y; bits=40 If bits=0 Return grid_rjb[x][y]=Bitor(grid_rjb[x][y],bits%16) If xx<0 | yy<0 | xx>=dx_rjb | yy>=dy_rjb Return grid_rjb[xx][yy]=Bitor(grid_rjb[xx][yy],bits/16) Task draw maze_rjb (Int x, Int y, Int size) Common Int grid_rjb[25][25], dx_rjb, dy_rjb Do xx=0, dx_rjb-1 z=grid_rjb[xx][0] If (!(z%2)) Line (x+size*xx, y, x+size*(xx+1), y) Loop Do yy=0, dy_rjb-1 z=grid_rjb[0][yy]/8 If (!(z%2)) Line (x, y+size*yy, x, y+size*(yy+1)) Loop Do yy=0, dy_rjb-1 Do xx=0, dx_rjb-1 z=grid_rjb[xx][yy]/2 If (!(z%2)) Line (x+size*(xx+1), y+size*yy, x+size*(xx+1), y+size*(yy+1)) z=z/2 If (!(z%2)) Line (x+size*xx, y+size*(yy+1), x+size*(xx+1), y+size*(yy+1)) Loop Loop