-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
66 lines (52 loc) · 1.33 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { Grid } from './src/grid'
import { Utils } from './src/utils'
let grid
const MAZE_RANDOMIZER_BUTTON = document.getElementById('mazerun')
grid = new Grid(18, 32)
grid.makeGrid()
Utils.generateMaze(grid)
MAZE_RANDOMIZER_BUTTON.onclick = function()
{
if(grid != undefined)
{
grid.removeGrid()
}
let gridWidth = document.getElementById('width').value
gridWidth = gridWidth == '' ? 32 : gridWidth
gridWidth = gridWidth > 100 ? 100 : gridWidth
let gridHeight = document.getElementById('heigth').value
gridHeight = gridHeight == '' ? 18 : gridHeight
gridHeight = gridHeight > 50 ? 50 : gridHeight
grid = new Grid(gridHeight, gridWidth)
grid.makeGrid()
Utils.generateMaze(grid)
}
const PATHFINDER_RUN_BUTTON = document.getElementById('pathrun')
let algorithim
PATHFINDER_RUN_BUTTON.onclick = function()
{
if(grid == undefined || Utils.creatingmaze)
{
return
}
if(algorithim != undefined)
{
algorithim.stop()
grid.clearGrid()
}
algorithim = Utils.selectSolveAlgorithim()
algorithim.solveMaze(grid)
}
const CLEAR_BUTTON = document.getElementById('clear')
CLEAR_BUTTON.onclick = function()
{
if(Utils.creatingmaze)
{
return
}
if(algorithim != undefined)
{
algorithim.stop()
}
grid.clearGrid()
}