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
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"css.validate": true,
"editor.quickSuggestions": {
"other": true,
"comments": false,
"strings": true
}
}
14 changes: 14 additions & 0 deletions 3-typing-game/typing-game-solution/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Paining game</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="container" class="container"></div>
<button id="reset" onclick="reset()">Reset</button>
<script src="script.js"></script>
</body>
</html>
76 changes: 76 additions & 0 deletions 3-typing-game/typing-game-solution/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
const arr = []
let r = 8, c = 8;
const container = document.getElementById('container');

for(var i = 0 ; i < 16 ; i++){
const row = document.createElement('div');
const rowArr = []
for(var j = 0 ; j < 16 ; j++){
const pixel = document.createElement('div');
pixel.style.display = 'inline-block';
pixel.style.width = '20px';
pixel.style.height = '20px';
pixel.style.margin = '1px';
pixel.style.background = 'white';
pixel.style.border = '1px solid black';
row.appendChild(pixel);
rowArr.push(pixel);
}
arr.push(rowArr);
container.appendChild(row);
}

focusOn(r,c);

function changeColor(i, j){
const pixel = arr[i][j];
pixel.style.background = pixel.style.background === 'white' ? 'black' : 'white';
}

function focusOn(i, j){
const pixel = arr[i][j];
pixel.style.border = '1px dashed blue';
}

function unFocus(i, j){
const pixel = arr[i][j];
pixel.style.border = '1px solid black';
}

function reset(){
arr.forEach(row => {
row.forEach(pixel => {
pixel.style.background = 'white';
})
})
resetElement = document.getElementById('reset');
resetElement.blur();
}

document.addEventListener('keydown', (e) => {
const key = e.key;
if (key === 'a' && c > 0){
unFocus(r,c);
c--;
focusOn(r,c);
}
else if (key === 'd' && c < 15){
unFocus(r,c);
c++;
focusOn(r,c);
}
else if (key === 's' && r < 15){
unFocus(r,c);
r++;
focusOn(r,c);
}
else if (key === 'w' && r > 0){
unFocus(r,c);
r--;
focusOn(r,c);
}
else if (key === 'Enter'){
changeColor(r,c);
}
});

9 changes: 9 additions & 0 deletions 3-typing-game/typing-game-solution/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.container{
justify-items: center;
padding-top: 220px;
}

#reset{
margin-top: 30px;
margin-left: 48.55%;
}