-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_app.js
83 lines (69 loc) · 1.84 KB
/
test_app.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
var selectedSpots = document.querySelectorAll('.spot');
//var selectBoard = document.querySelector('.select-board');
// var boardPositions = [
// [0,1,2],
// [3,4,5],
// [6,7,8]
// ];
var winningCombinations = [
[0,1,2],
[3,4,5],
[6,7,8],
[0,3,6],
[1,4,7],
[2,5,8],
[0,4,8],
[2,4,6]
]
var playerOneClicked = null;
var playerTwoClicked = null;
var spotId = 0;
var playerOneGo = [];
var playerTwoGo = [];
var handleSelectedSpots = function(event) {
if (playerOneClicked) {
event.target.textContent = 'O';
playerOneClicked = null;
spotId = Number(event.target.id);
playerTwoGo.push(spotId);
haveWinner(playerTwoGo);
} else {
event.target.textContent = 'X';
playerOneClicked = true;
spotId = event.target.id;
console.log(spotId);
playerOneGo.push(spotId);
console.log(playerOneGo);
haveWinner(playerOneGo);
}
}
var haveWinner = function(arr) {
console.log('test');
arr.forEach(function(winningCombinations.forEach(function(winningCombination) {
winningCombination.forEach(function(rowElement)) {
if (arrElement == rowElement0
}
}
if (arr.includes(winningCombination)) {
console.log('winner!')
}
})
}
// if (arr.includes()) {
// console.log('Winner!!!!!!')
// }
// }
// }
// if(arr.includes('0') && arr.includes('1') && arr.includes('2')) {
// setTimeout(gameOver, 3000);
// console.log('we have a winner!');
// }
// }
var gameOver = function() {
selectedSpots.forEach(function(selectedSpot) {
selectedSpot.textContent = '';
})
}
selectedSpots.forEach(function(selectedSpot) {
selectedSpot.addEventListener('click', handleSelectedSpots)
})