diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..504afef --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules/ +package-lock.json diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..a713cd4 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,2 @@ +## 2.0.0 [2021-02-25] +Init version diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ca1c103 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Alexander Popov + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ + diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..f70df92 --- /dev/null +++ b/TODO.md @@ -0,0 +1,2 @@ +[ ] Keyboard fit +[ ] iOS web app diff --git a/_media/css/chota.min.css b/_media/css/chota.min.css new file mode 120000 index 0000000..4c10fd2 --- /dev/null +++ b/_media/css/chota.min.css @@ -0,0 +1 @@ +../../node_modules/chota/dist/chota.min.css \ No newline at end of file diff --git a/_media/css/styles.css b/_media/css/styles.css new file mode 100644 index 0000000..4ecf42d --- /dev/null +++ b/_media/css/styles.css @@ -0,0 +1,30 @@ +@font-face { + font-family: 'F5.6'; + src: url('/_media/fonts/F5.6-Regular.eot'); + src: url('/_media/fonts/F5.6-Regular.eot?#iefix') format('embedded-opentype'), + url('/_media/fonts/F5.6-Regular.woff2') format('woff2'), + url('/_media/fonts/F5.6-Regular.woff') format('woff'); + font-weight: normal; + font-style: normal; + font-display: swap; +} + +:root { + /*--font-size: 2rem;*/ +} + +body.dark { + --bg-color: #000; + --bg-secondary-color: #131316; + --font-color: #f5f5f5; + --color-grey: #ccc; + --color-darkGrey: #777; +} + +body { + font-family: 'F5.6'; +} + +p#word { + font-size: 4rem; +} diff --git a/_media/fonts/F5.6-Regular.eot b/_media/fonts/F5.6-Regular.eot new file mode 100644 index 0000000..072c050 Binary files /dev/null and b/_media/fonts/F5.6-Regular.eot differ diff --git a/_media/fonts/F5.6-Regular.woff b/_media/fonts/F5.6-Regular.woff new file mode 100644 index 0000000..5249ceb Binary files /dev/null and b/_media/fonts/F5.6-Regular.woff differ diff --git a/_media/fonts/F5.6-Regular.woff2 b/_media/fonts/F5.6-Regular.woff2 new file mode 100644 index 0000000..84382a6 Binary files /dev/null and b/_media/fonts/F5.6-Regular.woff2 differ diff --git a/_media/js/game.js b/_media/js/game.js new file mode 100644 index 0000000..3fdc4eb --- /dev/null +++ b/_media/js/game.js @@ -0,0 +1,126 @@ +'use strict'; + +// keyboard layouts +const keyboardLayouts = { + 'usQwertyKeyboard' : 'abcdefghijklmnopqrstuvwxyz'.toUpperCase(), + 'ruQwertyKeyboard' : 'йцукеёнгшщзхъфывапролджэячсмитьбю'.toUpperCase() +} + +const pageCredits = '\ +

Font F5.6 by\ + DOT COLON\ +

\ + \ +

UI by\ + chota.css\ +

\ +'; + +const pageStatistics = ''; + +const words = [ + 'google', 'speed', 'design', 'forest', 'forever', 'love', + 'horizon', 'defect' +]; + +// game variables +let gameWord = words[Math.floor(Math.random() * words.length)].toUpperCase(); +let gameAnswered = new Array(gameWord.length + 1).join('-'); +let lives = 6; + +// Функция генерации html кода клавиатуры +function generateKeyboard(layout) +{ + var keyboardHtmlStr = ''; + + layout.split('').forEach(function(letter) + { + keyboardHtmlStr = keyboardHtmlStr + ''; + }) + + let keyboard = document.querySelector("#keyboard"); + keyboard.classList.remove('is-hidden'); + document.querySelector("#keyboard").innerHTML = keyboardHtmlStr; +} + +function offChar(letter) +{ + var charButton = document.getElementById(letter); + charButton.disabled = true; + + var indices = []; + var idx = gameWord.split('').indexOf(letter) + + if (idx == -1) + { + wrong(); + return; + } + + while (idx != -1) + { + indices.push(idx); + idx = gameWord.split('').indexOf(letter, idx + 1); + } + + indices.forEach(function(item, indices) + { + var wordArray = gameAnswered.split('') + wordArray[item] = letter; + gameAnswered = wordArray.join(''); + document.querySelector("#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); + } +} + +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.querySelector("#lives").innerHTML = 'Lives ' + lives; +} + + +function showPage(element, pageName) +{ + // alert(event.srcElement.id); + + ['gameButton', 'statsButton', 'creditsButton'].forEach(function(item) + { + document.querySelector("#" + item).classList.remove('active'); + }); + document.querySelector("#" + element.id).classList.add('active'); + + document.querySelector("#content").innerHTML = pageName; +} + + + +// game +window.onload = function() +{ + generateKeyboard(keyboardLayouts['usQwertyKeyboard']); + document.querySelector('#lives').innerHTML = 'Lives ' + lives; + console.log('Word:', gameWord.toLowerCase()); + document.querySelector('#word').innerHTML = gameAnswered; + + // fix load empty word + // if (gameWord === 0) { document.location.reload(true); } +} diff --git a/docs/README.md b/docs/README.md deleted file mode 100644 index 61e83f0..0000000 --- a/docs/README.md +++ /dev/null @@ -1 +0,0 @@ -![Screenshot](screen.png) diff --git a/docs/game.js b/docs/game.js deleted file mode 100644 index 43f6f3e..0000000 --- a/docs/game.js +++ /dev/null @@ -1,96 +0,0 @@ -"use strict"; - -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 + ''; - }) - - 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); - } -} diff --git a/docs/genKeys.py b/docs/genKeys.py deleted file mode 100644 index 25b78a6..0000000 --- a/docs/genKeys.py +++ /dev/null @@ -1,24 +0,0 @@ -#!/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( - '' - .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) diff --git a/docs/index.html b/docs/index.html deleted file mode 100644 index eba506b..0000000 --- a/docs/index.html +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - hgman - - - - - -
-
- LOADING -
- -
- ... -
- -
- ... -
- - -
- - - - diff --git a/docs/screen.png b/docs/screen.png deleted file mode 100644 index 427cbc9..0000000 Binary files a/docs/screen.png and /dev/null differ diff --git a/hgman.py b/hgman.py deleted file mode 100644 index 53d24c8..0000000 --- a/hgman.py +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/env python3 - -import sys -import random - -__author__ = 'Alexander Popov' -__version__ = '1.0.0' -__license__ = 'MIT' - -wordsDb = list() - -# for count, line in enumerate(sys.stdin): -# if not line in wordsDb: -# wordsDb.append(line.rstrip()) -with open('words.txt', 'r', encoding='utf-8') as f: - for count, line in enumerate(f.readlines()): - if line not in wordsDb: - wordsDb.append(line.rstrip()) - - -class Player: - def __init__(self, gameWord): - self.Health = 6 - self.Word = '-' * len(gameWord) - - def answer(self, newWords=None): - if newWords: - self.Word = newWords - return(self.Word) - - def lives(self): - return(self.Health) - - def crap(self): - self.Health -= 1 - pass - -gameWord = random.choice(wordsDb) -Gamer = Player(gameWord) - -while Gamer.answer() != gameWord: - if Gamer.lives() < 0: - print('You are dead') - break - - print('%d : %s' % (Gamer.lives(), Gamer.answer(),)) - - offWord = input() - - wordIndex = [index for index, char in enumerate(gameWord) - if char == offWord] - - if len(wordIndex) != 0: - for index in wordIndex: - aaa = list(Gamer.answer()) - aaa[index] = offWord - Gamer.answer("".join(aaa)) - else: - Gamer.crap() - -if not Gamer.lives() < 0: - print('Won!') diff --git a/index.html b/index.html new file mode 100644 index 0000000..37091cb --- /dev/null +++ b/index.html @@ -0,0 +1,76 @@ + + + + + + Hangman + + + + + + +
+
+ +
+ + + +
+ +
+

+ Loading word... +

+ + +
+ +
+ +
+ + + + + diff --git a/package.json b/package.json new file mode 100644 index 0000000..33f7144 --- /dev/null +++ b/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "chota": "0.8.0" + } +} diff --git a/docs/styles.css b/styles.css similarity index 100% rename from docs/styles.css rename to styles.css diff --git a/words.txt b/words.txt deleted file mode 100644 index 2ddc854..0000000 --- a/words.txt +++ /dev/null @@ -1,3 +0,0 @@ -google -window -horizon