Skip to content

Commit 39fba51

Browse files
authored
Merge pull request #2 from TanHongIT/javascript-setup
Javascript setup
2 parents eea45d1 + d5fa8f2 commit 39fba51

2 files changed

Lines changed: 57 additions & 13 deletions

File tree

public/css/style.css

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,38 @@
11
td {
2-
border: 2px solid #333;
3-
height: 100px;
4-
width: 100px;
5-
text-align: center;
2+
border : 2px solid #333;
3+
height : 100px;
4+
width : 100px;
5+
text-align : center;
66
vertical-align: middle;
7-
font-family: "Comic Sans MS", cursive, sans-serif;
8-
font-size: 70px;
9-
cursor: pointer;
7+
font-family : "Comic Sans MS", cursive, sans-serif;
8+
font-size : 70px;
9+
cursor : pointer;
1010
}
11-
table{
11+
12+
table {
1213
border-collapse: collapse;
13-
position: absolute;
14-
left: 50%;
15-
margin-left: -155px;
16-
top: 50px;
14+
position : absolute;
15+
left : 50%;
16+
margin-left : -155px;
17+
top : 50px;
1718
}
18-
table tr:first-child td{
19+
20+
table tr:first-child td {
1921
/* border-top: 0; */
22+
}
23+
24+
.endgame {
25+
display : none;
26+
width : 200px;
27+
top : 120px;
28+
background-color: rgba(37, 167, 54, 0.8);
29+
position : absolute;
30+
left : 50%;
31+
margin-left : -100px;
32+
padding-top : 50px;
33+
padding-bottom : 50px;
34+
text-align : center;
35+
border-radius : 5px;
36+
color : white;
37+
font-size : 2em;
2038
}

public/js/script.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
var origBoard;
3+
const oPlayer = 'O';
4+
const cells = document.querySelectorAll('.cell');
5+
startGame();
6+
7+
function startGame() {
8+
document.querySelector(".endgame").style.display = "none";
9+
origBoard = Array.from(Array(9).keys());
10+
console.log(origBoard);
11+
for (var i = 0; i < cells.length; i++) {
12+
cells[i].innerText = ''; //clear
13+
cells[i].style.removeProperty('background-color');
14+
//add a event process vào click mouse event
15+
cells[i].addEventListener('click', turnClick, false);
16+
}
17+
}
18+
19+
20+
function turnClick(square) {
21+
// // write down the ID of any cell clicked
22+
console.log(square.target.id)
23+
24+
// pass in the ID that clicking
25+
turn(square.target.id,oPlayer)
26+
}

0 commit comments

Comments
 (0)