Skip to content

Commit f8e811a

Browse files
authored
migrated the entire project from local machine
1 parent 36e0847 commit f8e811a

File tree

3 files changed

+172
-0
lines changed

3 files changed

+172
-0
lines changed

index.html

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="Author" content="Sarthak Jain">
6+
<meta name="description" content="a simple javascript based tic tac toe game">
7+
<meta name="keywords" content="game, tic tac toe">
8+
<meta name="viewport" content="width = device-width, initial-scale = 1.0">
9+
<title>Tic Tac Toe</title>
10+
<link rel="stylesheet" type="text/css" href="style.css">
11+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
12+
<script src="script.js"></script>
13+
</head>
14+
<body>
15+
<center>
16+
<h1>Play Tic Tac Toe</h1><br><br>
17+
<table id="board">
18+
<tr>
19+
<td id="c1" onclick="play(this)"></td>
20+
<td id="c2" onclick="play(this)"></td>
21+
<td id="c3" onclick="play(this)"></td>
22+
</tr>
23+
<tr>
24+
<td id="c4" onclick="play(this)"></td>
25+
<td id="c5" onclick="play(this)"></td>
26+
<td id="c6" onclick="play(this)"></td>
27+
</tr>
28+
<tr>
29+
<td id="c7" onclick="play(this)"></td>
30+
<td id="c8" onclick="play(this)"></td>
31+
<td id="c9" onclick="play(this)"></td>
32+
</tr>
33+
</table><br><br>
34+
35+
<div>
36+
<a href='https://github.com/Sarthakj0805', target="_blank">
37+
<i class="fa fa-github" style="font-size:48px;color:white"></i>
38+
</a>
39+
</div>
40+
<div id="panel">
41+
<h1 id="player"></h1>
42+
<button type="button" onclick="restart()" id="restart">Restart</button>
43+
</div>
44+
</center>
45+
</body>
46+
</html>

script.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
var turn = 0;
2+
var board = ['', '', '', '', '', '', '', '', ''];
3+
var win = false;
4+
var winner = '';
5+
6+
function play(cell) {
7+
if (cell.innerHTML == '') {
8+
if (turn % 2 == 0) {
9+
cell.innerHTML = 'X';
10+
} else {
11+
cell.innerHTML = 'O';
12+
}
13+
turn++;
14+
checkWin(cell.innerHTML);
15+
}
16+
}
17+
18+
function checkWin(p) {
19+
for (i = 1; i < 10; i++) {
20+
board[i - 1] = document.getElementById('c' + i).innerHTML;
21+
}
22+
23+
if ((board[0] == p && board[1] == p && board[2] == p) ||
24+
(board[3] == p && board[4] == p && board[5] == p) ||
25+
(board[6] == p && board[7] == p && board[8] == p) ||
26+
(board[0] == p && board[3] == p && board[6] == p) ||
27+
(board[1] == p && board[4] == p && board[7] == p) ||
28+
(board[2] == p && board[5] == p && board[8] == p) ||
29+
(board[0] == p && board[4] == p && board[8] == p) ||
30+
(board[2] == p && board[4] == p && board[6] == p)) {
31+
winner = 'Player ' + p + ' won!';
32+
win = true;
33+
gameOver();
34+
}
35+
36+
if (win == false && turn == 9) {
37+
winner = 'Draw';
38+
gameOver();
39+
}
40+
41+
console.log(turn);
42+
}
43+
44+
function gameOver() {
45+
document.getElementById('player').innerHTML = winner;
46+
document.getElementById('panel').style.display = 'block';
47+
}
48+
49+
function restart() {
50+
document.getElementById('panel').style.display = 'none';
51+
restore();
52+
}
53+
54+
function restore() {
55+
for (i = 1; i < 10; i++) {
56+
document.getElementById('c' + i).innerHTML = '';
57+
}
58+
turn = 0;
59+
win = false;
60+
}

style.css

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
body {
2+
background-color: #000000;
3+
background-image: linear-gradient(147deg, #000000 0%, #04619f 74%);;
4+
font-family: monospace;
5+
}
6+
7+
h1 {
8+
color: white;
9+
font-size: 32px;
10+
}
11+
12+
a {
13+
text-decoration: none;
14+
color: white;
15+
font-size: 21px;
16+
}
17+
18+
19+
#board td {
20+
background-color: #5b6467;
21+
background-image: linear-gradient(315deg, grey 0%, rgba(0, 0, 0, 0.795) 74%);
22+
color: rgba(0, 204, 255, 0.877);
23+
width: 125px;
24+
height: 125px;
25+
text-align: center;
26+
font-size: 100px;
27+
cursor: pointer;
28+
border-radius: 20px;
29+
}
30+
31+
#board td:hover {
32+
background-color: #1F5B59;
33+
-webkit-transition: background-color, 0.3s ease-in-out;
34+
transition: background-color, 0.3s ease-in-out;
35+
}
36+
37+
#panel {
38+
display: none;
39+
position: fixed;
40+
left: 0;
41+
top: 0;
42+
width: 100%;
43+
height: 100%;
44+
overflow: auto;
45+
background-color: rgb(0, 0, 0);
46+
background-color: rgba(0, 0, 0, 0.4);
47+
padding-top: 7%;
48+
}
49+
50+
#restart {
51+
background-color: #2ECC71;
52+
border: none;
53+
color: white;
54+
padding: 15px 32px;
55+
text-align: center;
56+
text-decoration: none;
57+
display: inline-block;
58+
font-size: 16px;
59+
cursor: pointer;
60+
}
61+
62+
#restart:hover {
63+
background-color: #27AE60;
64+
-webkit-transition: background-color, 0.3s ease-in-out;
65+
transition: background-color, 0.3s ease-in-out;
66+
}

0 commit comments

Comments
 (0)