-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrunGame.js
46 lines (43 loc) · 1.61 KB
/
runGame.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
;(function(exports) {
// Playing the game
function difficulty(table) {
return function(event) {
var buttonID = event.currentTarget.getAttribute('id');
if (buttonID === 'hard') {
table.difficulty = 15;
} else if (buttonID === 'medium') {
table.difficulty = 30;
} else {
table.difficulty = 45;
}
console.log('difficulty', table.difficulty);
}
}
function startGame(table) {
return function() {
var tableNode, difficulty, newTable;
if (table.difficulty === null) {
alert('Please choose a difficulty.');
return false;
}
if ((tableNode = document.getElementById('table'))) {
console.log('table has been previously created', table.difficulty);
difficulty = table.difficulty;
window.clearInterval(computerInterval);
}
newTable = new Table(21);
newTable.difficulty = table.difficulty || difficulty;
exports.DomManipulation.newGame(newTable, newTable.difficulty);
}
}
function addDifficultyClicks(table) {
var buttons = document.getElementsByClassName('difficulty');
for (var i = 0; i < buttons.length; i++) {
buttons[i].addEventListener('click', difficulty(table));
}
var start = document.getElementById('startgame');
start.addEventListener('click', startGame(table));
}
var table = new Table(21);
addDifficultyClicks(table);
})(this);