-
Notifications
You must be signed in to change notification settings - Fork 0
/
choices.js
63 lines (50 loc) · 1.54 KB
/
choices.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
// SELECT START ELEMENT
const options = document.querySelector(".options");
// SELECT BUTTONS
const computerBtn = document.querySelector(".computer");
const friendBtn = document.querySelector(".friend");
const xBtn = document.querySelector(".x");
const oBtn = document.querySelector(".o");
const playBtn = document.querySelector(".play");
// GAME OVER ELEMENT
const gameOverElement = document.querySelector(".gameover");
const player = new Object;
let OPPONENT;
oBtn.addEventListener("click", function(){
player.man = "O";
player.computer = "X";
player.friend = "X";
switchActive(xBtn, oBtn);
});
xBtn.addEventListener("click", function(){
player.man = "X";
player.computer = "O";
player.friend = "O";
switchActive(oBtn, xBtn);
});
computerBtn.addEventListener("click", function(){
OPPONENT = "computer";
switchActive(friendBtn, computerBtn);
});
friendBtn.addEventListener("click", function(){
OPPONENT = "friend";
switchActive(computerBtn, friendBtn);
});
playBtn.addEventListener("click", function(){
if( !OPPONENT){
computerBtn.style.backgroundColor = "red";
friendBtn.style.backgroundColor = "red";
return;
}
if( !player.man ){
oBtn.style.backgroundColor = "red";
xBtn.style.backgroundColor = "red";
return;
}
init(player, OPPONENT);
options.classList.add("hide");
});
function switchActive(off, on){
off.classList.remove("active");
on.classList.add("active");
}