-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuserDomInteractions.js
65 lines (52 loc) · 1.48 KB
/
userDomInteractions.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
var controls = {
addSizes: function() {
_.each(_.range(5, 21), i => {
$('#size-of-board').append($('<option></option>').val(i).html(i+'x'+i));
});
$('#size-of-board').val(sketchOptions.defaultGameSize);
},
onSizeChange: function() {
$('#size-of-board').change(controls.restrictBombNum).change(controls.resetGame);
},
onBombChange: function() {
$('#number-of-bombs').change(controls.resetGame);
},
restrictBombNum: function() {
var maxSize = Math.pow($(this).val(), 2) - 1;
var input = $('#number-of-bombs');
input.prop('max', maxSize);
if (input.val() > maxSize) {
input.val(maxSize);
}
},
onFaceClick: function() {
$('#face-button').click(controls.resetGame);
},
onSolveClick: function() {
$('#solve-button').click(controls.solver);
},
solver: function() {
var size = $('#size-of-board').val();
var numBombs = $('#number-of-bombs').val();
new Solver(size, numBombs, 1).solve();
},
resetGame: function() {
var size = $('#size-of-board').val();
var numBombs = $('#number-of-bombs').val();
resize(size);
game = new Board(size, numBombs, sketchOptions.cellSize, true);
},
preventRightClickModalBox: function() {
$('#canvas').bind('contextmenu', function(e) {
return false;
});
}
};
$(function() {
controls.addSizes();
controls.onSizeChange();
controls.onBombChange();
controls.onFaceClick();
controls.preventRightClickModalBox();
controls.onSolveClick();
});