-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTicTacToe.js
127 lines (119 loc) Β· 4.07 KB
/
TicTacToe.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
const restartButton = document.getElementById('game-restart');
restartButton.addEventListener('click', function () {
console.log("Thanky you, for clicking the retart button!");
location.reload();
});
const gameboard = document.getElementById('gameboard');
gameboard.addEventListener('click', markField);
let currentPlayer = 'X';
const currentPlayerElement = document.getElementById('currentPlayer');
function markField(e) {
var field = e.target;
if (field.localName === 'div'){
return;
}
field.setAttribute('aria-label', currentPlayer);
field.setAttribute('disabled', 'disabled');
if (playerHasWon()){
console.log(`${currentPlayer} has won!`);
currentPlayerElement.textContent = `${currentPlayer} has won!`;
return;
}
if (currentPlayer === 'X'){
currentPlayer = 'O';
currentPlayerElement.textContent = "O's turn";
} else {
currentPlayer = 'X';
currentPlayerElement.textContent = "X's turn";
}
}
function playerHasWon(){
// TO DO
return false;
}
function nervig() {
if (xoxo.textContent === 'π²') {
xoxo.textContent = 'π©';
xoxo.direction = 'left';
} else if (xoxo.textContent === 'π©'){
xoxo.direction = 'up';
xoxo.textContent = 'π½';
} else if (xoxo.textContent === 'π½'){
xoxo.textContent = 'π»';
xoxo.direction = 'right';
} else if (xoxo.textContent === 'π»'){
xoxo.textContent = 'π';
xoxo.direction = 'left';
} else if (xoxo.textContent === 'π'){
xoxo.textContent = 'π';
xoxo.direction = 'right';
} else if (xoxo.textContent === 'π'){
xoxo.textContent = 'π';
xoxo.direction = 'up';
} else if (xoxo.textContent === 'π'){
xoxo.textContent = 'π';
xoxo.direction = 'right';
} else if (xoxo.textContent === 'π'){
xoxo.textContent = 'π₯';
xoxo.direction = 'left';
} else if (xoxo.textContent === 'π₯'){
xoxo.textContent = 'π«';
xoxo.direction = 'left';
} else if (xoxo.textContent === 'π«'){
xoxo.textContent = 'π€';
xoxo.direction = 'right';
} else if (xoxo.textContent === 'π€'){
xoxo.textContent = 'π
';
xoxo.direction = 'up';
} else if (xoxo.textContent === 'π
'){
xoxo.textContent = 'π§ ';
xoxo.direction = 'down';
} else if (xoxo.textContent === 'π§ '){
xoxo.textContent = 'π©βπ»';
xoxo.direction = 'left';
} else if (xoxo.textContent === 'π©βπ»'){
xoxo.direction = 'up';
xoxo.textContent = 'π€Έ';
} else if (xoxo.textContent === 'π€Έ'){
xoxo.textContent = 'π₯';
xoxo.direction = 'right';
} else if (xoxo.textContent === 'π₯'){
xoxo.textContent = 'π·';
xoxo.direction = 'left';
} else if (xoxo.textContent === 'π·'){
xoxo.textContent = 'π£';
xoxo.direction = 'right';
} else if (xoxo.textContent === 'π£'){
xoxo.textContent = 'π¦';
xoxo.direction = 'up';
} else if (xoxo.textContent === 'π¦'){
xoxo.textContent = 'πΈ';
xoxo.direction = 'down';
} else if (xoxo.textContent === 'πΈ'){
xoxo.textContent = 'π';
xoxo.direction = 'left';
} else if (xoxo.textContent === 'π'){
xoxo.textContent = 'πΈ';
xoxo.direction = 'left';
} else if (xoxo.textContent === 'πΈ'){
xoxo.textContent = 'π©';
xoxo.direction = 'right';
} else if (xoxo.textContent === 'π©'){
xoxo.textContent = 'πΊ';
xoxo.direction = 'up';
} else if (xoxo.textContent === 'πΊ'){
xoxo.textContent = 'π§';
xoxo.direction = 'down';
} else if (xoxo.textContent === 'π§'){
xoxo.textContent = 'π½';
xoxo.direction = 'down';
} else {
xoxo.textContent = 'π²' ;
xoxo.direction = 'right';
}
}
let xoxo = document.getElementById('xoxo');
xoxo.addEventListener('click', nervig);
setTimeout(function(){
setInterval(nervig , 100);
} , 3500);