-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.html
More file actions
160 lines (136 loc) · 4.38 KB
/
Copy patherror.html
File metadata and controls
160 lines (136 loc) · 4.38 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Error 404 - Tic Tac Toe</title>
<link href="https://fonts.googleapis.com/css?family=Quicksand&display=swap" rel="stylesheet">
<style>
body {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
background-color: #282c34;
color: white;
font-family: 'Arial', sans-serif;
}
h1 {
font-family: 'Quicksand', sans-serif;
margin: 10px 0;
font-size: 4rem;
}
p {
font-family: 'Quicksand', sans-serif;
font-size: 1.3rem;
}
#board {
margin-top: 20px;
display: grid;
grid-template-columns: repeat(3, 100px);
grid-gap: 5px;
}
.cell {
width: 100px;
height: 100px;
display: flex;
align-items: center;
justify-content: center;
font-size: 2em;
background-color: #61dafb;
cursor: pointer;
}
.cell:hover {
background-color: #4fa3d1;
}
#winner {
margin-top: 20px;
font-size: 1.5em;
}
button {
display: inline-block;
padding: 10px 20px;
font-size: 16px;
font-weight: bold;
text-align: center;
text-decoration: none;
cursor: pointer;
border: none;
border-radius: 5px;
color: #fff;
background-color: #4caf50;
transition: background-color 0.3s ease;
}
button:hover {
background-color: #45a049;
}
a{
text-decoration: none;
}
</style>
</head>
<body>
<h1>Error 404 - Page Not Found</h1>
<p>Sorry, the page you are looking for might be in another universe till that time you can play a game here.</p>
<div id="board"></div>
<div id="winner"></div>
<br/>
<br/>
<button><a href="./index.html">Go Back</a></button>
<script>
const board = document.getElementById('board');
const cells = [];
const winnerDisplay = document.getElementById('winner');
for (let i = 0; i < 9; i++) {
const cell = document.createElement('div');
cell.classList.add('cell');
cell.setAttribute('data-index', i);
cells.push(cell);
board.appendChild(cell);
}
let currentPlayer = 'X';
board.addEventListener('click', (event) => {
const clickedCell = event.target;
const index = clickedCell.dataset.index;
if (cells[index].textContent === '') {
cells[index].textContent = currentPlayer;
currentPlayer = currentPlayer === 'X' ? 'O' : 'X';
}
if (checkWinner()) {
winnerDisplay.textContent = `Player ${currentPlayer === 'X' ? 'O' : 'X'} wins!`;
resetBoard();
} else if (isBoardFull()) {
winnerDisplay.textContent = "It's a tie!";
resetBoard();
} else {
winnerDisplay.textContent = ''; // Clear the winner display if there's no winner
}
});
function checkWinner() {
const winningCombinations = [
[0, 1, 2], [3, 4, 5], [6, 7, 8], // rows
[0, 3, 6], [1, 4, 7], [2, 5, 8], // columns
[0, 4, 8], [2, 4, 6] // diagonals
];
for (const combination of winningCombinations) {
const [a, b, c] = combination;
if (cells[a].textContent && cells[a].textContent === cells[b].textContent && cells[a].textContent === cells[c].textContent) {
return true;
}
}
return false;
}
function isBoardFull() {
return cells.every(cell => cell.textContent !== '');
}
function resetBoard() {
cells.forEach(cell => {
cell.textContent = '';
});
currentPlayer = 'X';
}
</script>
</body>
</html>