-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame_tictac_vanilla.html
76 lines (66 loc) · 1.33 KB
/
game_tictac_vanilla.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>tic-tac-toe v0.1 plain dom / js</title>
<style>
* {
box-sizing: border-box;
}
table {
border-collapse: collapse;
}
td {
--cellsize: 6rem;
border: 3px solid gray;
width: var(--cellsize);
height: var(--cellsize);
font-size: calc(var(--cellsize) * 0.75);
color: blueviolet; /* https://www.quackit.com/css/css_color_codes.cfm */
text-transform: uppercase;
text-align: center;
cursor: pointer;
}
</style>
<script>
window.addEventListener('load', () => {
document.querySelector('#playfield table')
.addEventListener('click', (e) => {
const cell = e.target;
if(cell.localName != 'td') // sanity chk
return;
// console.log(cell.innerText);
switch(cell.innerText.toLowerCase()) {
case '': cell.innerText = 'x'; break;
case 'x': cell.innerText = 'o'; break;
default: cell.innerText = '';
}
});
});
</script>
</head>
<body>
<h1>tic tac toe</h1>
<p>manual: just click anywhere, it changes the fields between X -> O -> [empty] </p>
<br>
<div id="playfield">
<table>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</table>
</div>
</body>
</html>