Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Base layout template with Gulp, SCSS and Stylelint
1. Create a repo using this template
1. Replace `<your_account>` and `<repo_name>` with your Github username and the new repo name
- [DEMO LINK](https://<your_account>.github.io/<repo_name>/)
- [DEMO LINK](https://cutiekate.github.io/gulp-template/)
15 changes: 14 additions & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,20 @@
<link rel="stylesheet" href="./styles/main.css">
</head>
<body>
<h1>Hello Mate Academy</h1>
<h1>Tic Tac Toe</h1>
<div class="container">
<div class="area">
<div class="area__cell"></div>
<div class="area__cell"></div>
<div class="area__cell"></div>
<div class="area__cell"></div>
<div class="area__cell"></div>
<div class="area__cell"></div>
<div class="area__cell"></div>
<div class="area__cell"></div>
<div class="area__cell"></div>
</div>
</div>
<script type="text/javascript" src="scripts/main.js"></script>
</body>
</html>
57 changes: 57 additions & 0 deletions src/scripts/main.js
Original file line number Diff line number Diff line change
@@ -1 +1,58 @@
'use strict';

const area = document.querySelector('.area');
let move = 0;

area.addEventListener('click', function(e) {
if (e.target.innerHTML === 'X' || e.target.innerHTML === 'O') {
return;
}

if (move % 2 === 0) {
e.target.innerHTML = 'X';
} else {
e.target.innerHTML = 'O';
}
move++;
check();
});

function check() {
const cells = document.getElementsByClassName('area__cell');
const arr = [
[0, 1, 2],
[3, 4, 5],
[6, 7, 8],
[0, 3, 6],
[1, 4, 7],
[2, 5, 8],
[0, 4, 8],
[2, 4, 6],
];

for (let i = 0; i < arr.length; i++) {
if (cells[arr[i][0]].innerHTML === 'X' && cells[arr[i][1]].innerHTML === 'X'
&& cells[arr[i][2]].innerHTML === 'X') {
say('Победили хрестики!');
} else if (cells[arr[i][0]].innerHTML === 'O'
&& cells[arr[i][1]].innerHTML === 'O'
&& cells[arr[i][2]].innerHTML === 'O') {
say('Победили нолики!');
}
}

for (let i = 0; i < cells.length; i++) {
if (cells[i].innerHTML !== 'X' && cells[i].innerHTML !== 'O') {
return;
}
}

say('Ничья!');

function say(what) {
setTimeout(() => {
alert(what);
location.reload();
}, 50);
}
}
31 changes: 31 additions & 0 deletions src/styles/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,34 @@
body {
background: $c-gray;
}

h1 {
text-align: center;
}

.container {
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}

.area {
width: 450px;
height: 450px;
background-color: cornflowerblue;
display: flex;
flex-wrap: wrap;

&__cell {
width: 150px;
height: 150px;
border: 1px solid lightgray;
box-sizing: border-box;
display: flex;
justify-content: center;
align-items: center;
font-size: 60px;
}
}