commit
3775da301f
18
CHANGELOG.md
18
CHANGELOG.md
|
@ -1,5 +1,13 @@
|
||||||
|
## Legend
|
||||||
|
- 🐛 - Bug
|
||||||
|
- ✔️ - Fixed
|
||||||
|
- ❌ - Removed
|
||||||
|
- ➕ - Added
|
||||||
|
- ℹ️ - Information
|
||||||
|
- ♻️ - Edited
|
||||||
|
|
||||||
## 2.0.3 # Build 3 [Development]
|
## 2.0.3 # Build 3 [Development]
|
||||||
-
|
- ➕ - Show hidden word by Lose
|
||||||
|
|
||||||
## 2.0.2 # Build 2 [2021-02-25]
|
## 2.0.2 # Build 2 [2021-02-25]
|
||||||
- ➕ - Added game statistics
|
- ➕ - Added game statistics
|
||||||
|
@ -13,11 +21,3 @@
|
||||||
|
|
||||||
## 2.0.0 [2021-02-25]
|
## 2.0.0 [2021-02-25]
|
||||||
Init version
|
Init version
|
||||||
|
|
||||||
## Legend
|
|
||||||
- 🐛 - Bug
|
|
||||||
- ✔️ - Fixed
|
|
||||||
- ❌ - Removed
|
|
||||||
- ➕ - Added
|
|
||||||
- ℹ️ - Information
|
|
||||||
- ♻️ - Edited
|
|
||||||
|
|
2
TODO.md
2
TODO.md
|
@ -1,8 +1,8 @@
|
||||||
[ ] Loading page
|
[ ] Loading page
|
||||||
[ ] Localization
|
[ ] Localization
|
||||||
[ ] Fix GAME tab for not refresh page
|
[ ] Fix GAME tab for not refresh page
|
||||||
[ ] Show word if lose
|
|
||||||
[ ] Android manifest
|
[ ] Android manifest
|
||||||
|
[+] Show word if lose
|
||||||
[+] Keyboard fit
|
[+] Keyboard fit
|
||||||
[+] Game Statistics
|
[+] Game Statistics
|
||||||
[+] Restart scene
|
[+] Restart scene
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -80,7 +80,7 @@
|
||||||
ver: <a href="https://github.com/iiiypuk/hgman/blob/master/CHANGELOG.md" target="_blank">2.0.2</a>
|
ver: <a href="https://github.com/iiiypuk/hgman/blob/master/CHANGELOG.md" target="_blank">2.0.2</a>
|
||||||
</p>
|
</p>
|
||||||
<div id="statistics" class="is-hidden">
|
<div id="statistics" class="is-hidden">
|
||||||
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
|
<script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
|
||||||
<span id="busuanzi_container_site_uv">UV <span id="busuanzi_value_site_uv"></span></span>
|
<span id="busuanzi_container_site_uv">UV <span id="busuanzi_value_site_uv"></span></span>
|
||||||
<span id="busuanzi_container_site_pv">PV <span id="busuanzi_value_site_pv"></span></span>
|
<span id="busuanzi_container_site_pv">PV <span id="busuanzi_value_site_pv"></span></span>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,38 +1,42 @@
|
||||||
'use strict';
|
"use strict";
|
||||||
|
|
||||||
function updateStats(statParameter)
|
function updateStats(statParameter) {
|
||||||
{
|
let stTotalGames = JSON.parse(localStorage.getItem("stTotalGames"));
|
||||||
let stTotalGames = JSON.parse(localStorage.getItem('stTotalGames'));
|
let stWinWords = JSON.parse(localStorage.getItem("stWinWords"));
|
||||||
let stWinWords = JSON.parse(localStorage.getItem('stWinWords'));
|
let stLetterClick = JSON.parse(localStorage.getItem("stLetterClick"));
|
||||||
let stLetterClick = JSON.parse(localStorage.getItem('stLetterClick'));
|
let stCorrLetter = JSON.parse(localStorage.getItem("stCorrLetter"));
|
||||||
let stCorrLetter = JSON.parse(localStorage.getItem('stCorrLetter'));
|
switch (statParameter) {
|
||||||
|
case "stTotalGames":
|
||||||
|
localStorage.setItem("stTotalGames", stTotalGames + 1);
|
||||||
|
break;
|
||||||
|
|
||||||
switch(statParameter)
|
case "stWinWords":
|
||||||
{
|
localStorage.setItem("stTotalGames", stTotalGames + 1);
|
||||||
case 'stTotalGames':
|
localStorage.setItem("stWinWords", stWinWords + 1);
|
||||||
localStorage.setItem('stTotalGames', stTotalGames + 1);
|
break;
|
||||||
|
|
||||||
break;
|
|
||||||
case 'stWinWords':
|
|
||||||
localStorage.setItem('stTotalGames', stTotalGames + 1);
|
|
||||||
localStorage.setItem('stWinWords', stWinWords + 1);
|
|
||||||
|
|
||||||
break;
|
|
||||||
case 'stLetterClick':
|
|
||||||
localStorage.setItem('stLetterClick', stLetterClick + 1);
|
|
||||||
|
|
||||||
break;
|
|
||||||
case 'stCorrLetter':
|
|
||||||
localStorage.setItem('stLetterClick', stLetterClick + 1);
|
|
||||||
localStorage.setItem('stCorrLetter', stCorrLetter + 1);
|
|
||||||
|
|
||||||
break;
|
|
||||||
case 'stCheck':
|
|
||||||
if (stTotalGames == null) { localStorage.setItem('stTotalGames', 0); }
|
|
||||||
if (stWinWords == null) { localStorage.setItem('stWinWords', 0); }
|
|
||||||
if (stLetterClick == null) { localStorage.setItem('stLetterClick', 0); }
|
|
||||||
if (stCorrLetter == null) { localStorage.setItem('stCorrLetter', 0); }
|
|
||||||
|
|
||||||
break;
|
case "stLetterClick":
|
||||||
}
|
localStorage.setItem("stLetterClick", stLetterClick + 1);
|
||||||
}
|
break;
|
||||||
|
|
||||||
|
case "stCorrLetter":
|
||||||
|
localStorage.setItem("stLetterClick", stLetterClick + 1);
|
||||||
|
localStorage.setItem("stCorrLetter", stCorrLetter + 1);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "stCheck":
|
||||||
|
if (stTotalGames == null) {
|
||||||
|
localStorage.setItem("stTotalGames", 0);
|
||||||
|
}
|
||||||
|
if (stWinWords == null) {
|
||||||
|
localStorage.setItem("stWinWords", 0);
|
||||||
|
}
|
||||||
|
if (stLetterClick == null) {
|
||||||
|
localStorage.setItem("stLetterClick", 0);
|
||||||
|
}
|
||||||
|
if (stCorrLetter == null) {
|
||||||
|
localStorage.setItem("stCorrLetter", 0);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
181
js/index.js
181
js/index.js
|
@ -1,129 +1,96 @@
|
||||||
'use strict';
|
"use strict";
|
||||||
|
|
||||||
// keyboard layouts
|
// keyboard layouts
|
||||||
const keyboardLayouts = {
|
const keyboardLayouts = {
|
||||||
'usQwertyKeyboard' : 'abcdefghijklmnopqrstuvwxyz'.toUpperCase(),
|
usQwertyKeyboard: "abcdefghijklmnopqrstuvwxyz".toUpperCase(),
|
||||||
'ruQwertyKeyboard' : 'йцукеёнгшщзхъфывапролджэячсмитьбю'.toUpperCase()
|
ruQwertyKeyboard: "йцукеёнгшщзхъфывапролджэячсмитьбю".toUpperCase()
|
||||||
}
|
};
|
||||||
|
|
||||||
const words = [
|
const words = [ "google", "speed", "design", "forest", "forever", "love", "horizon", "defect" ];
|
||||||
'google', 'speed', 'design', 'forest', 'forever', 'love',
|
|
||||||
'horizon', 'defect'
|
|
||||||
];
|
|
||||||
|
|
||||||
// game variables
|
// game variables
|
||||||
let gameWord = words[Math.floor(Math.random() * words.length)].toUpperCase();
|
let gameWord = words[Math.floor(Math.random() * words.length)].toUpperCase();
|
||||||
let gameAnswered = new Array(gameWord.length + 1).join('-');
|
|
||||||
|
let gameAnswered = new Array(gameWord.length + 1).join("-");
|
||||||
|
|
||||||
let lives = 6;
|
let lives = 6;
|
||||||
|
|
||||||
// init keyboard
|
// init keyboard
|
||||||
function generateKeyboard(layout)
|
function generateKeyboard(layout) {
|
||||||
{
|
let keyboardHtmlStr = "";
|
||||||
let keyboardHtmlStr = '';
|
layout.split("").forEach(function(letter) {
|
||||||
|
keyboardHtmlStr = keyboardHtmlStr + '<button class="button clear is-marginless" id="' + letter + '" onclick="letterClick(\'' + letter + "')\"> " + letter + "</button>";
|
||||||
layout.split('').forEach(function(letter)
|
});
|
||||||
{
|
let keyboard = document.querySelector("#keyboard");
|
||||||
keyboardHtmlStr = keyboardHtmlStr + '<button class="button clear is-marginless" id="' + letter +
|
keyboard.classList.remove("is-hidden");
|
||||||
'" onclick="letterClick(\'' + letter + '\')"> ' + letter + '</button>';
|
document.querySelector("#keyboard").innerHTML = keyboardHtmlStr;
|
||||||
})
|
|
||||||
|
|
||||||
let keyboard = document.querySelector("#keyboard");
|
|
||||||
keyboard.classList.remove('is-hidden');
|
|
||||||
document.querySelector("#keyboard").innerHTML = keyboardHtmlStr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// letter click action
|
// letter click action
|
||||||
function letterClick(letter)
|
function letterClick(letter) {
|
||||||
{
|
let charButton = document.getElementById(letter);
|
||||||
let charButton = document.getElementById(letter);
|
charButton.disabled = true;
|
||||||
charButton.disabled = true;
|
let indices = [];
|
||||||
|
let idx = gameWord.split("").indexOf(letter);
|
||||||
let indices = [];
|
if (idx == -1) {
|
||||||
let idx = gameWord.split('').indexOf(letter)
|
wrongLetter();
|
||||||
|
updateStats("stLetterClick");
|
||||||
if (idx == -1)
|
return;
|
||||||
{
|
}
|
||||||
wrongLetter();
|
while (idx != -1) {
|
||||||
|
indices.push(idx);
|
||||||
updateStats('stLetterClick');
|
idx = gameWord.split("").indexOf(letter, idx + 1);
|
||||||
return;
|
}
|
||||||
}
|
indices.forEach(function(item, indices) {
|
||||||
|
let wordArray = gameAnswered.split("");
|
||||||
while (idx != -1)
|
wordArray[item] = letter;
|
||||||
{
|
gameAnswered = wordArray.join("");
|
||||||
indices.push(idx);
|
document.querySelector("#word").innerHTML = gameAnswered;
|
||||||
idx = gameWord.split('').indexOf(letter, idx + 1);
|
updateStats("stCorrLetter");
|
||||||
}
|
});
|
||||||
|
if (gameAnswered.split("").indexOf("-") == -1) {
|
||||||
indices.forEach(function(item, indices)
|
updateStats("stWinWords");
|
||||||
{
|
// display win scene
|
||||||
let wordArray = gameAnswered.split('')
|
document.querySelector("#keyboard").innerHTML = '\t\t<img src="https://icongr.am/clarity/happy-face.svg?size=128&color=28bd14">\t\t<h1 class="text-success">Your winner!!</h1>\t\t<button class="button error" onclick="document.location.reload(true);"\t\t>Restart game</button>';
|
||||||
wordArray[item] = letter;
|
}
|
||||||
gameAnswered = wordArray.join('');
|
|
||||||
document.querySelector("#word").innerHTML = gameAnswered;
|
|
||||||
|
|
||||||
updateStats('stCorrLetter');
|
|
||||||
})
|
|
||||||
|
|
||||||
if (gameAnswered.split('').indexOf('-') == -1)
|
|
||||||
{
|
|
||||||
updateStats('stWinWords');
|
|
||||||
|
|
||||||
document.querySelector('#keyboard').innerHTML = '\
|
|
||||||
<img src="https://icongr.am/clarity/happy-face.svg?size=128&color=28bd14">\
|
|
||||||
<h1 class="text-success">Your winner!!</h1>\
|
|
||||||
<button class="button error" onclick="document.location.reload(true);"\
|
|
||||||
>Restart game</button>';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// action by wrong letter
|
// action by wrong letter
|
||||||
function wrongLetter()
|
function wrongLetter() {
|
||||||
{
|
if (lives <= 0) {
|
||||||
if (lives <= 0)
|
updateStats("stTotalGames");
|
||||||
{
|
// display hidden word
|
||||||
updateStats('stTotalGames');
|
document.querySelector("#word").innerHTML = gameWord;
|
||||||
|
document.querySelector("#word").classList.add("text-success");
|
||||||
document.querySelector('#keyboard').innerHTML = '\
|
// display lose scene
|
||||||
<img src="https://icongr.am/clarity/sad-face.svg?size=128&color=d43939">\
|
document.querySelector("#keyboard").innerHTML = '\t\t<img src="https://icongr.am/clarity/sad-face.svg?size=128&color=d43939">\t\t<h1 class="text-error">Your lose!!</h1>\t\t<button class="button error" onclick="document.location.reload(true);"\t\t>Restart game</button>';
|
||||||
<h1 class="text-error">Your lose!!</h1>\
|
}
|
||||||
<button class="button error" onclick="document.location.reload(true);"\
|
lives -= 1;
|
||||||
>Restart game</button>';
|
document.querySelector("#lives").innerHTML = "Lives " + lives;
|
||||||
}
|
|
||||||
|
|
||||||
lives -= 1;
|
|
||||||
document.querySelector("#lives").innerHTML = 'Lives ' + lives;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// display tab content
|
// display tab content
|
||||||
function showPage(element, pageName)
|
function showPage(element, pageName) {
|
||||||
{
|
// alert(event.srcElement.id);
|
||||||
// alert(event.srcElement.id);
|
[ "gameButton", "statsButton", "creditsButton" ].forEach(function(item) {
|
||||||
|
document.querySelector("#" + item).classList.remove("active");
|
||||||
['gameButton', 'statsButton', 'creditsButton'].forEach(function(item)
|
});
|
||||||
{
|
document.querySelector("#" + element.id).classList.add("active");
|
||||||
document.querySelector("#" + item).classList.remove('active');
|
document.querySelector("#content").innerHTML = pageName;
|
||||||
});
|
if (pageName == pageStatistics) {
|
||||||
document.querySelector("#" + element.id).classList.add('active');
|
updateStatsPage();
|
||||||
|
}
|
||||||
document.querySelector("#content").innerHTML = pageName;
|
|
||||||
|
|
||||||
if (pageName == pageStatistics) { updateStatsPage(); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// game init
|
// game init
|
||||||
window.onload = function()
|
window.onload = function() {
|
||||||
{
|
updateStats("stCheck");
|
||||||
updateStats('stCheck');
|
generateKeyboard(keyboardLayouts["usQwertyKeyboard"]);
|
||||||
|
document.querySelector("#lives").innerHTML = "Lives " + lives;
|
||||||
generateKeyboard(keyboardLayouts['usQwertyKeyboard']);
|
console.log("Word:", gameWord.toLowerCase());
|
||||||
document.querySelector('#lives').innerHTML = 'Lives ' + lives;
|
document.querySelector("#word").innerHTML = gameAnswered;
|
||||||
console.log('Word:', gameWord.toLowerCase());
|
if (window.screen.availWidth <= 599) {
|
||||||
document.querySelector('#word').innerHTML = gameAnswered;
|
document.querySelector("#lives").classList.remove("error");
|
||||||
|
document.querySelector("#lives").classList.add("dark");
|
||||||
if (window.screen.availWidth <= 599)
|
}
|
||||||
{
|
};
|
||||||
document.querySelector('#lives').classList.remove('error');
|
|
||||||
document.querySelector('#lives').classList.add('dark');
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -17,7 +17,8 @@
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "uglifyjs js/_* js/index.js -o docs/game.js",
|
"build": "uglifyjs js/_* js/index.js -o docs/game.js",
|
||||||
"server": "python3.7 -m http.server --directory ./docs/"
|
"server": "python3.7 -m http.server --directory ./docs/",
|
||||||
|
"beautify": "uglifyjs -b beautify,comments ${} -o ${}"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"uglify-js": "^3.12.8"
|
"uglify-js": "^3.12.8"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user