ahkbin!
#Requires AutoHotkey 2.0 #SingleInstance GSize := 25, PSize := 15, WColor := "D35400", GColor := "2ECC71", Off := (GSize - PSize) // 2, Rows := 41, Cols := 75 ; Must be odd for the algorithm MData := [] loop Rows { Row := [] loop Cols Row.Push(1) MData.Push(Row) } GenerateMaze(2, 2) MData[Rows - 1][Cols - 1] := 0 GenerateMaze(y, x) { MData[y][x] := 0, Dir := [[0, -2], [0, 2], [-2, 0], [2, 0]] loop Dir.Length Index := Random(1, Dir.Length), Temp := Dir[A_Index], Dir[A_Index] := Dir[Index], Dir[Index] := Temp for D in Dir { Ny := y + D[1], Nx := x + D[2] if (Ny > 1 && Ny < Rows && Nx > 1 && Nx < Cols && MData[Ny][Nx] = 1) MData[y + D[1] // 2][x + D[2] // 2] := 0, GenerateMaze(Ny, Nx) } } G := Gui("-Caption +AlwaysOnTop", "Random Maze") G.BackColor := "000000", G.X := 2, G.Y := 2 for RowI, RowD in MData for ColI, Val in RowD if Val = 1 G.AddProgress("x" (ColI - 1) * GSize " y" (RowI - 1) * GSize " w" GSize " h" GSize " Background" WColor) G.AddProgress("x" (Cols - 2) * GSize " y" (Rows - 2) * GSize " w" GSize " h" GSize " Background" GColor) PObj := G.AddProgress("x" (G.X - 1) * GSize + Off " y" (G.Y - 1) * GSize + Off " w" PSize " h" PSize " BackgroundWhite" ) G.Show("w" Cols * GSize " h" Rows * GSize) Up:: MovePlayer(0, -1) Down:: MovePlayer(0, 1) Left:: MovePlayer(-1, 0) Right:: MovePlayer(1, 0) Esc:: ExitApp() MovePlayer(DX, DY) { NX := G.X + DX, NY := G.Y + DY if MData[NY][NX] = 0 { G.X := NX, G.Y := NY, PObj.Move((G.X - 1) * GSize + Off, (G.Y - 1) * GSize + Off) if (G.X = Cols - 1 && G.Y = Rows - 1) MsgBox("Winner!", "Goal", 4096), Reload() } }
Reindent
Announce to IRC