-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
133 lines (125 loc) · 3.9 KB
/
index.html
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
128
129
130
131
132
133
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=400, user-scalable=no">
<title>Tic Tac Toe</title>
<script src="tic-tac-toe.js"></script>
<script src="https://code.jquery.com/jquery-3.4.1.js"></script>
</head>
<body>
<br />
<br />
<marquee behavior="alternate">Tic-Tac-Toe</marquee>
<br />
<br />
<center>
<table>
<tr>
<td width="33%" height="33%" align="center"></td>
<td width="33%" height="33%" align="center"></td>
<td width="33%" height="33%" align="center"></td>
</tr>
<tr>
<td width="33%" height="33%" align="center"></td>
<td width="33%" height="33%" align="center"></td>
<td width="33%" height="33%" align="center"></td>
</tr>
<tr>
<td width="33%" height="33%" align="center"></td>
<td width="33%" height="33%" align="center"></td>
<td width="33%" height="33%" align="center"></td>
</tr>
</table>
</center>
<br />
<br />
<button onclick="location.reload();">Restart</button>
<style>
html, body {
background: fuchsia;
font-family: Arial, serif;
text-align: center;
}
marquee {
max-width: 500px;
font-size: 60px;
font-weight: bold;
font-style: italic;
color: red;
text-shadow: 0 0 10px purple;
position: relative;
z-index: 1;
}
table {
width: 210px;
height: 210px;
border: 2px solid green;
background: aqua;
border-spacing: 0;
box-shadow: 0 0 90px 0 blue;
position: relative;
z-index: 1;
}
td {
font-size: 21px;
box-shadow: 0 0 2px 2px green inset;
color: #fff;
font-weight: bold;
text-shadow: 0 0 4px black;
}
td:hover {
background: #fff;
}
</style>
<script>
var cells = document.getElementsByTagName('td');
var gameEnd = false;
var filledCells = 0;
var getField = function() {
var field = '';
for (var i = 0; i < cells.length; i++) {
var value = cells[i].innerHTML;
field += value ? value : '-';
}
return field;
};
var winCheck = function() {
var winner = whoWins(getField());
if (winner !== false) {
gameEnd = true;
setTimeout(function() {
alert(winner === 'O' ? 'You lose' : 'You win');
}, 100);
} else if (filledCells === 9) {
gameEnd = true;
setTimeout(function() {
alert('Nobody wins');
}, 100);
}
};
var move = function() {
var pos = AI(getField());
cells[pos - 1].innerHTML = 'O';
filledCells++;
winCheck();
};
for (var i = 0; i < cells.length; i++) {
cells[i].addEventListener('click', function() {
if (gameEnd || this.innerHTML !== '') {
return;
}
this.innerHTML = 'X';
filledCells++;
winCheck();
if (!gameEnd) {
move();
}
});
}
</script>
<a target="_blank" style="position: fixed; top: 0; right: 0; z-index: 0;" href="https://github.com/lmcsu/tic-tac-toe">
<img width="149" height="149" src="https://github.blog/wp-content/uploads/2008/12/forkme_right_green_007200.png?resize=149%2C149" alt="Fork me on GitHub">
</a>
</body>
</html>