| Joel | People | Hobbies | Fun | Miscellaneous | |||||||||
|
Random Maze Generator Code <%const W = 49 const H = 49 const S = 6 dim g_intDepth dim arrGrid(2500) dim intIndex dim x dim y for intIndex = 0 to (W*H)-1 arrGrid(intIndex) = 0 next g_intDepth = 0 ClearPoint arrGrid, 1, 1 arrGrid(1*W+1) = 2 arrGrid(47*W+48) = 1 response.write "<TABLE BORDER=""0"" CELLPADDING=""0"" CELLSPACING=""1"">" & vbcrlf for y = 0 to H-1 response.write "<TR>" & vbcrlf for x = 0 to W-1 select case arrGrid(y*W+x) case 0 response.write "<TD BGCOLOR=""#336633""><IMG HEIGHT=""" & S & """ SRC=""/images/trans.gif"" WIDTH=""" & S & """></TD>" & vbcrlf case 1 response.write "<TD BGCOLOR=""#ffffff""><IMG HEIGHT=""" & S & """ SRC=""/images/trans.gif"" WIDTH=""" & S & """></TD>" & vbcrlf case 2 response.write "<TD BGCOLOR=""#cc0000""><IMG HEIGHT=""" & S & """ SRC=""/images/trans.gif"" WIDTH=""" & S & """></TD>" & vbcrlf end select next response.write "</TR>" & vbcrlf next response.write "</TABLE>" & vbcrlf Sub ClearPoint(byref arrGrid, x, y) dim newx dim newy dim intCount g_intDepth = g_intDepth + 1 arrGrid(y*W+x) = 1 intCount = ValidCount(arrGrid, x, y) while (intCount > 0) select case int(rnd()*4) case 0 if ValidMove(arrGrid, x,y-2) > 0 then arrGrid((y-1)*W+x) = 1 ClearPoint arrGrid, x,y-2 end if case 1 if ValidMove(arrGrid, x+2,y) > 0 then arrGrid(y*W+x+1) = 1 ClearPoint arrGrid, x+2,y end if case 2 if ValidMove(arrGrid, x,y+2) > 0 then arrGrid((y+1)*W+x) = 1 ClearPoint arrGrid, x,y+2 end if case 3 if ValidMove(arrGrid, x-2,y) > 0 then arrGrid(y*W+x-1) = 1 ClearPoint arrGrid, x-2,y end if end select intCount = ValidCount(arrGrid, x, y) wend g_intDepth = g_intDepth - 1 End Sub Function ValidMove(byref arrGrid, x, y) dim intResult intResult = 0 if x>=0 and x<W and y>=0 and y<H then if arrGrid(y*W+x) = 0 then intResult = 1 end if end if ValidMove = intResult End Function Function ValidCount(byref arrGrid, x, y) dim intResult intResult = 0 intResult = intResult + ValidMove(arrGrid, x,y-2) intResult = intResult + ValidMove(arrGrid, x+2,y) intResult = intResult + ValidMove(arrGrid, x,y+2) intResult = intResult + ValidMove(arrGrid, x-2,y) ValidCount = intResult End Function %>
|
||||
| Tell me what you think | Copyright © 2000 Joel T. Anderson | |