add auto refresh page
This commit is contained in:
1
docs/README.md
Normal file
1
docs/README.md
Normal file
@@ -0,0 +1 @@
|
||||

|
||||
94
docs/game.js
Normal file
94
docs/game.js
Normal file
@@ -0,0 +1,94 @@
|
||||
var words = ['google', 'speed', 'window', 'horizon'];
|
||||
|
||||
var lives = 6;
|
||||
var gameWord = words[Math.floor(Math.random() * words.length)].toUpperCase();
|
||||
var gameAnswered = new Array(gameWord.length + 1).join('-');
|
||||
|
||||
var keyboardLayouts = {
|
||||
'usQwertyKeyboard' : 'abcdefghijklmnopqrstuvwxyz'.toUpperCase(),
|
||||
'ruQwertyKeyboard' : 'йцукеёнгшщзхъфывапролджэячсмитьбю'.toUpperCase()
|
||||
}
|
||||
|
||||
// Функция генерации html кода клавиатуры
|
||||
function generateKeyboard(layout)
|
||||
{
|
||||
var htmlKeyboardStr = '';
|
||||
|
||||
keyboardLayouts[layout].split('').forEach(function(word)
|
||||
{
|
||||
htmlKeyboardStr = htmlKeyboardStr + '<button id="' + word +
|
||||
'" onclick="offChar(\'' + word + '\')">' + word + '</button>';
|
||||
})
|
||||
|
||||
document.getElementById("keyboard").innerHTML = htmlKeyboardStr;
|
||||
}
|
||||
|
||||
window.onload = function()
|
||||
{
|
||||
generateKeyboard('usQwertyKeyboard');
|
||||
|
||||
console.log(gameWord) // for DEBUG
|
||||
document.getElementById("WORD").innerHTML = gameAnswered;
|
||||
document.getElementById("lives").innerHTML = 'Lives ' + lives;
|
||||
|
||||
// init storage
|
||||
var storageNames = ['gamesWon', 'wordsAnswered', 'gamesFail'];
|
||||
storageNames.forEach(function(item)
|
||||
{
|
||||
if(null == localStorage.getItem(item))
|
||||
localStorage.setItem(item, 0);
|
||||
})
|
||||
}
|
||||
|
||||
function wrong()
|
||||
{
|
||||
if (lives <= 0)
|
||||
{
|
||||
var gamesFail = localStorage.getItem('gamesFail');
|
||||
localStorage.setItem('gamesFail', parseInt(gamesFail) + 1);
|
||||
alert('You dead');
|
||||
document.location.reload(true);
|
||||
}
|
||||
|
||||
lives -= 1;
|
||||
document.getElementById("lives").innerHTML = 'Lives ' + lives;
|
||||
}
|
||||
|
||||
function offChar(char)
|
||||
{
|
||||
var charButton = document.getElementById(char);
|
||||
charButton.disabled = true;
|
||||
|
||||
var indices = [];
|
||||
var idx = gameWord.split('').indexOf(char)
|
||||
|
||||
if (idx == -1)
|
||||
{
|
||||
wrong();
|
||||
return;
|
||||
}
|
||||
|
||||
while (idx != -1)
|
||||
{
|
||||
indices.push(idx);
|
||||
idx = gameWord.split('').indexOf(char, idx + 1);
|
||||
}
|
||||
|
||||
indices.forEach(function(item, indices)
|
||||
{
|
||||
var wordArray = gameAnswered.split('')
|
||||
wordArray[item] = char;
|
||||
gameAnswered = wordArray.join('');
|
||||
document.getElementById("WORD").innerHTML = gameAnswered;
|
||||
var wordsAnswered = localStorage.getItem('wordsAnswered');
|
||||
localStorage.setItem('wordsAnswered', parseInt(wordsAnswered) + 1);
|
||||
})
|
||||
|
||||
if (gameAnswered.split('').indexOf('-') == -1)
|
||||
{
|
||||
var gamesWon = localStorage.getItem('gamesWon');
|
||||
localStorage.setItem('gamesWon', parseInt(gamesWon) + 1);
|
||||
alert('You Win');
|
||||
document.location.reload(true);
|
||||
}
|
||||
}
|
||||
24
docs/genKeys.py
Normal file
24
docs/genKeys.py
Normal file
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
__author__ = 'Alexander Popov'
|
||||
__version__ = '1.0.0'
|
||||
__license__ = 'MIT'
|
||||
|
||||
usQwertyKeyboard = 'abcdefghijklmnopqrstuvwxyz'.upper()
|
||||
|
||||
def genKeys(alphabet):
|
||||
keys = list()
|
||||
|
||||
for letter in alphabet:
|
||||
keys.append(
|
||||
'<button id="{l}" onclick="offChar(\'{l}\')">{l}</button>'
|
||||
.format(l=letter))
|
||||
|
||||
return(keys)
|
||||
|
||||
if __name__ == '__main__':
|
||||
with open('keys.html', 'w+', encoding='utf-8') as f:
|
||||
keyboard = genKeys(usQwertyKeyboard)
|
||||
|
||||
for item in keyboard:
|
||||
f.write(item)
|
||||
38
docs/index.html
Normal file
38
docs/index.html
Normal file
@@ -0,0 +1,38 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<!--
|
||||
/_ ... _ /_
|
||||
/_//_/ ////_//_//_//\
|
||||
_/ _//
|
||||
-->
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||
<title>hgman</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||
<link rel="stylesheet" type="text/css" href="styles.css">
|
||||
<link rel="stylesheet" type="text/css" href="Play/play.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="wrap">
|
||||
<div id="WORD" class="word">
|
||||
LOADING
|
||||
</div>
|
||||
|
||||
<div id="lives" class="lives">
|
||||
...
|
||||
</div>
|
||||
|
||||
<div id="keyboard" class="keyboard">
|
||||
...
|
||||
</div>
|
||||
|
||||
<footer>
|
||||
2021 by <a href="//iiiypuk.me/">iiiypuk</a>
|
||||
<p>ver: 0.2.1</p>
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="game.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
BIN
docs/screen.png
Normal file
BIN
docs/screen.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.6 KiB |
60
docs/styles.css
Normal file
60
docs/styles.css
Normal file
@@ -0,0 +1,60 @@
|
||||
/* http://paletton.com/#uid=13w0u0kllllaFw0g0qFqFg0w0aF */
|
||||
|
||||
@import url('https://fonts.googleapis.com/css2?family=Play:wght@400;700&display=swap');
|
||||
|
||||
* {
|
||||
margin: 0; padding: 0; outline: 0;
|
||||
}
|
||||
|
||||
body {
|
||||
color: #032137;
|
||||
background-color: #29516D;
|
||||
font-family: 'Play';
|
||||
font-size: 32px;
|
||||
}
|
||||
|
||||
.wrap {
|
||||
max-width: 400px;
|
||||
margin: 10px auto;
|
||||
}
|
||||
|
||||
div.word {
|
||||
padding: 8px;
|
||||
border-top: 1px solid #032137;
|
||||
}
|
||||
|
||||
div.lives {
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
div.word, div.lives {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
div.keyboard {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
div.keyboard button {
|
||||
color: #032137;
|
||||
font-family: 'Play';
|
||||
border-radius: 4px;
|
||||
font-size: 16px;
|
||||
background-color: #708EA4;
|
||||
padding: 8px;
|
||||
border: 1px solid #032137;
|
||||
box-sizing: border-box;
|
||||
margin: 2px;
|
||||
}
|
||||
|
||||
div.keyboard button:disabled {
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
footer {
|
||||
border-top: 1px solid #032137;
|
||||
padding: 8px;
|
||||
margin-top: 20px;
|
||||
text-align: center;
|
||||
font-size: 16px;
|
||||
}
|
||||
Reference in New Issue
Block a user