diff --git a/Public/Word Guessing Game/css/style.css b/Public/Word Guessing Game/css/style.css new file mode 100644 index 00000000..3e7ae69c --- /dev/null +++ b/Public/Word Guessing Game/css/style.css @@ -0,0 +1,360 @@ +*{ + font-family: 'baloo chettan'; + text-align: center; + margin: 0; + padding: 0 +} + +body{ + display: flex; + align-items: center; + justify-content: center; + flex-direction: column; + color: #08ed1b; + text-shadow: 1px 1px 1px #298632; + height: 100vh; + background: url('/libs/img/background.jpg') +} + +.container{ + width: 600px; + height: 500px; + border-radius: 15px; + box-shadow: 10px 10px 10px #3f11bf; + background-image: linear-gradient(to bottom, #b0b0b0, #707070, #515152) +} + +.header{ + height: 50px; +} + +.letters{ + width: 100%; + height: 130px; + display: flex; + flex-direction: row; + align-items: center; + justify-content: center; +} + +.letter{ + width: 60px; + height: 130px; + margin: 3px; +} + +.letter div:nth-child(1){ + margin-top: 30px; + height: 70px; + font-size: 3.5em; + color: #f0a80f; + text-shadow: 2px 2px 2px #533a04 +} + +.letter div:nth-child(2) { + background: rgb(30,30,30); + height: 10px; + width: 100%; + border-radius: 3px; + background-image: linear-gradient(to bottom, #e8c277, #75623c, #5c4413, #493205); + box-shadow: 1px 2px 2px #614918 +} + +.wordMeaning { + height: 75px; + width: 100%; + display: flex; + flex-direction: column; + color: orange; + text-shadow: 1px 1px 1px #533a04; + +} + +.bottom { + height: 240px; + width: 100%; +} + +.keys { + width: 65%; + height: 240px; + float: left; + display: flex; + flex-direction: row; + align-items: center; + justify-content: center; +} + +.keysPlacer{ + width: 250px; + height: 210px; +} + +.keyText { + width: 52px; + height: 60px; + margin: 5px 5px; + float: left; + border-radius: 5px; + background-image: linear-gradient(to bottom, #f2d7a1, #bea97f, #8c774c); + font-size: 2.5em; + box-shadow: 3px 3px 3px #614918; + color: #49854e; + text-shadow: 1px 1px 1px #014f07; +} + +.score { + width: 35%; + height: 240px; + float: left; + color: #8cbe90; +} + +.score .stats { + height: 100px; + width: 100%; + display: flex; + flex-direction: row; + align-items: center; + margin-top: 20px +} + +.stats div:nth-child(2) { + margin-left: 20px; +} + +.highsc{ + width: 75% +} + +.score p{ + font-size: 2.5em +} + +.clicked{ + transition: all 0.2s; + background-image: linear-gradient(to bottom, #b43e3e, #9d2424, #881515, #610303); + color: #ffdddd; +} +/* end of main css full screen */ + + +/* media screen 800px */ +@media screen and (max-width: 800px) { + .container { + width: 500px; + height: 450px; + border-radius: 12px; + } + + .header{ + height: 45px; + } + + .letters{ + height: 110px; + } + + .letter{ + width: 50px; + height: 110px; + margin: 2px; + } + + .letter div:nth-child(1){ + margin-top: 25px; + height: 60px; + font-size: 3.1em; + } + + .letter div:nth-child(2) { + height: 8px; + border-radius: 2px; + } + .wordMeaning { + + height: 60px; + font-size: 0.85em; + } + + .bottom { + height: 230px; + } + + .keys { + height: 230px; + } + + .keysPlacer{ + width: 240px; + height: 200px; + } + + .keyText { + width: 50px; + height: 55px; + font-size: 2.3em; + } + + + +} +/* media screen 800px end */ + + + + + +/* media screen 600px */ +@media screen and (max-width: 600px) { + .container { + width: 450px; + } + + .header { + font-size: 0.9em + } + + .letters { + height: 100px; + } + + .letter { + width: 45px; + height: 100px; + margin: 2px; + } + + .letter div:nth-child(1) { + margin-top: 18px; + height: 60px; + font-size: 2.8em; + } + + .letter div:nth-child(2) { + height: 8px; + border-radius: 2px; + } + + + .wordMeaning { + height: 60px; + font-size: 0.8em; + } + + .bottom { + height: 230px; + } + + .keys { + height: 230px; + } + + .keysPlacer { + width: 230px; + height: 190px; + + } + + .keyText { + width: 45px; + height: 50px; + font-size: 2.2em; + } + + .score span{ + font-size: 0.85em + } + + .score p { + font-size: 2.2em + } +} + +@media screen and (max-width: 450px) { + .container { + width: 300px; + height: 360px + } + + .header { + font-size: 0.75em + } + + .letters { + height: 80px; + } + + .letter { + width: 30px; + height: 90px; + margin: 2px; + } + + .letter div:nth-child(1) { + margin-top: 5px; + height: 50px; + font-size: 2.4em; + } + + .letter div:nth-child(2) { + height: 7px; + border-radius: 2px; + } + + + .wordMeaning { + height: 55px; + font-size: 0.5em; + } + + .bottom { + height: 180px; + } + + .keys{ + width: 70%; + height: 200px; + } + + .keysPlacer { + + height: 190px; + margin-left: 7px; + } + + .keyText { + width: 40px; + height: 42px; + margin: 4px; + font-size: 1.7em; + } + + .score{ + width: 30%; + height: 180px; + } + + .stats div:nth-child(2) { + margin-left: 0px; + } + + .score div:nth-child(1) { + height: 75px; + width: 100%; + } + + .score div:nth-child(2) { + height: 75px; + width: 100% + } + + .score span { + font-size: 0.5em + } + + .score p { + font-size: 1.5em + } + +} diff --git a/Public/Word Guessing Game/index.html b/Public/Word Guessing Game/index.html new file mode 100644 index 00000000..5370bd1f --- /dev/null +++ b/Public/Word Guessing Game/index.html @@ -0,0 +1,107 @@ + + + + + + + + + + + + + + + + + + + Word Guess + + +
+ + +
+

Word Guess

+
+ + +
+
+
+
+
+
+
R
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
I
+
+
+
+
+
+
+
+
+
+
+
+ + + +
+

a

+

meaning:

+

synonyms:

+
+ + + +
+
+
+ +
+
+ + +
+
+
+ Your Score +

0

+
+
+ Lives +

10

+
+
+
+ Highscore +

0

+
+
+ +
+ + +
+ + + + \ No newline at end of file diff --git a/Public/Word Guessing Game/js/script.js b/Public/Word Guessing Game/js/script.js new file mode 100644 index 00000000..3b1eed1b --- /dev/null +++ b/Public/Word Guessing Game/js/script.js @@ -0,0 +1,302 @@ + +class Game { + + constructor(state){ + this.state = state + } + + // game ready + ready(){ + const word = this.state.words[this.state.nextWord] + this.filterWord(word.word) + } + + // filter the word + filterWord(word){ + console.log(this.state) + this.state.highScore = this.getHighScore() + + let letters = word.split('') + let chars = [] + let randLet = [] + + const rNum = randNum(letters.length) + + letters.map((letter, i)=>{ + chars.push({ + letter: letter, + isSame: i === rNum[0] || i === rNum[1] ? true : false + }) + }) + + const randomText = generateMixText(letters, rNum) + + randomText.map(ran => { + randLet.push({ + letter: ran, + isClicked: false + }) + }) + + this.state.letters.letters = chars + this.state.ranLetters = randLet + this.render() + + } + + + getHighScore() { + let storage = localStorage.getItem('highscore') + const now = new Date().getTime() + if (storage) { + storage = JSON.parse(storage) + if(storage.exp > now){ + return storage + } + } + } + + // check letter + checkLetter(l){ + + let randL = this.state.ranLetters + let letters = this.state.letters.letters + let letra = this.state.letters.letters.map(l =>{ + return l.letter + }) + + randL.map(ran => { + if(ran.letter === l){ + ran.isClicked = true + } + }) + + letters.map(letter => { + if(letter.letter === l){ + this.state.letters.length = this.state.letters.length + 1 + letter.isSame = true + } + }) + + const n = letra.includes(l) + n ? this.state.score = this.state.score + 1 : this.state.lives = this.state.lives - 1 + + this.state.letters.letters = letters + this.state.ranLetters = randL + + this.render() + + } + + + render(){ + + const header = document.querySelector('.header') + header.innerHTML = `

Word Guess

` + + + const keyPlacer = document.querySelector('.keysPlacer') + const l = document.querySelector('.letters') + + keyPlacer.innerHTML = this.state.ranLetters.map(t => + `
${t.letter.toUpperCase(0)}
` + ).join('') + + const keyText = document.querySelectorAll('.keyText') + + keyText.forEach(k => { + k.addEventListener('click', ()=>{ + if(!k.classList.contains('clicked')){ + this.checkLetter(k.dataset.letter, k) + } + }) + }) + + + l.innerHTML = this.state.letters.letters.map(l => + `
+
${l.isSame ? l.letter.toUpperCase() : ''}
+
+
`).join('') + + + wordMeanings(this.state) + + + if (this.state.letters.length === this.state.letters.letters.length - 2) { + this.state.letters.length = 0 + this.state.nextWord = this.state.nextWord + 1 + setTimeout(() => { + this.ready() + }, 800) + } + + if(this.state.lives == 0){ + + header.innerHTML = `

Game Over!

` + + setLocalStorage(this.state.highScore, this.state.score) + + + this.state.letters.length = 0 + this.state.nextWord = 0 + this.state.lives = 10 + this.state.score = 0 + + setTimeout(() => { + this.ready() + }, 2000) + } + + } + +} +// end of Class Game + +const setLocalStorage = (highsc, val) => { + if(highsc == null){ + const time = new Date().getTime() + const highScore = { + score: val, + exp: time + 3600000 + } + localStorage.setItem('highscore', JSON.stringify(highScore)) + return + } + if(highsc){ + if(val > highsc.score){ + const time = new Date().getTime() + const highScore = {score: val, exp: time+3600000} + localStorage.setItem('highscore', JSON.stringify(highScore)) + } + return + } +} + + + + +const wordMeanings = (state) => { + if(state.lives >= 0){ + + const type = document.querySelector('.type') + const meaning = document.querySelector('.meaning') + const synonyms = document.querySelector('.synonyms') + const lives = document.querySelector('.lives') + const score = document.querySelector('.scores') + + type.textContent = state.words[state.nextWord].type + meaning.textContent = state.words[state.nextWord].meaning + synonyms.textContent = state.words[state.nextWord].synonyms.map(s => `${s},`).join(' ') + lives.textContent = state.lives + score.textContent = state.score + + if(state.highScore){ + const now = new Date().getTime() + + if(state.highScore.exp > now){ + const highscore = document.querySelector('.highscore') + highscore.textContent = state.highScore.score + } + + } + + + } + +} + +const randNum = (num) => { + const n = [] + const n1 = Math.floor(Math.random() * num) + + n.push(n1) + let n2 = (n1 - 2) + n2 < 0 ? n2 = num - 2 : n2 + n.push(n2) + + return n.sort() + +} + + + +// generate random text +const generateMixText = (letters, rand) => { + // removes the array from the random number + let z = letters.filter((l, i) => { + return rand.indexOf(i) == -1 + }) + // filter duplicate values in the array + let c = z.filter((l, i)=>{ + return z.indexOf(l) === i + }) + const l = new Words().words(alphabets) + // filters alphabets from duplication + let d = l.filter(x => { + return !letters.includes(x) + }) + + let n = 12 - c.length + + for (var x=0; x < n; x++){ + c.push(d[x]) + } + + // return a scrambled word + return new Words().words(c) + +} + + +// state class start +class State { + + constructor(words, lives, score, highScore, nextWord, letters, ranLetters ){ + this.words = words; + this.lives = lives; + this.score = score; + this.highScore = highScore; + this.nextWord = nextWord; + this.letters = letters; + this.ranLetters = ranLetters + } + + static generateWords(){ + return new Words().words(words) + } + + + + static words(){ + const letters = { + letters: [{ + letter: '', + isSame: false + }], + length: 0, + correctLength: 0 + } + return letters + } + + static ready(){ + return new State(this.generateWords(), 10, 0, {}, 0, this.words(), []) + } + +} +// end of class state + + +// start of words class +class Words{ + words(words){ + words.sort(() => Math.random() - 0.5) + return words + } +} +// end of word class + +// start Game +const start = new Game(State.ready()).ready() \ No newline at end of file diff --git a/Public/Word Guessing Game/js/word.js b/Public/Word Guessing Game/js/word.js new file mode 100644 index 00000000..c0d717a1 --- /dev/null +++ b/Public/Word Guessing Game/js/word.js @@ -0,0 +1,126 @@ +const words = [ + { + word: 'atomic', + type: 'adjective', + meaning: 'relating to an atom or atoms', + synonyms: ['small', 'micro', 'tiny'] + }, + { + word: 'hijack', + type: 'verb', + meaning: 'unlawfully seize (an aircraft) in transit and force it to go to a different destination for one own purposes.', + synonyms: ['seize', 'commandeer', 'take over'] + }, + { + word: 'jumble', + type: 'verb', + meaning: 'mix up in a confused or untidy way', + synonyms: ['mix up', 'muddle up', 'disarrange'] + }, + { + word: 'quench', + type: 'verb', + meaning: `satisfy (one's thirst) by drinking.`, + synonyms: ['put out', 'smother', 'extinguish'] + }, + { + word: 'sample', + type: 'noun', + meaning: 'a small part or quantity intended to show what the whole is like.', + synonyms: ['specimen', 'representative', 'trial'] + }, + { + word: 'frenzy', + type: 'noun', + meaning: 'a state or period of uncontrolled excitement or wild behavior.', + synonyms: ['hysteria', 'madness', 'wildness'] + }, + { + word: 'object', + type: 'noun', + meaning: 'a material thing that can be seen and touched.', + synonyms: ['thing', 'item', 'piece'] + }, + { + word: 'acquire', + type: 'verb', + meaning: 'to obtain an asset or object for oneself.', + synonyms: ['possess', 'take in', 'capture'] + }, + { + word: 'chariot', + type: 'noun', + meaning: 'a two-wheeled horse-drawn vehicle used in ancient warfare and racing.', + synonyms: ['carraige', 'wheeled cart', 'horse-drawn vehicle'] + }, + { + word: 'garnish', + type: 'verb', + meaning: 'a two-wheeled horse-drawn vehicle used in ancient warfare and racing.', + synonyms: ['decoration', 'adornment', 'embellish'] + }, + { + word: 'country', + type: 'noun', + meaning: 'a nation with its own government, occupying a particular territory.', + synonyms: ['state', 'nation', 'kingdom'] + }, + { + word: 'picture', + type: 'noun', + meaning: 'represent (someone or something) in a photograph or picture', + synonyms: ['sketch', 'print', 'canvas'] + }, + { + word: 'mailbox', + type: 'noun', + meaning: 'a private box into which mail is delivered.', + synonyms: ['post box', 'pillar box', 'letter drop'] + }, + { + word: 'mediator', + type: 'noun', + meaning: 'a person who attempts to make people involved in a conflict come to an agreement.', + synonyms: ['arbiter', 'middleman', 'moderator'] + }, + { + word: 'sandwich', + type: 'noun', + meaning: 'an item of food consisting of two pieces of bread with meat, cheese, or other filling between them, eaten as a light meal.', + synonyms: ['bread', 'burger', 'tunaburger'] + }, + { + word: 'computer', + type: 'noun', + meaning: 'an electronic device for storing and processing data, typically in binary form, according to instructions given to it in a variable program.', + synonyms: ['number cruncher', 'computing machine', 'imformation processor'] + }, + { + word: 'outbreak', + type: 'noun', + meaning: 'the sudden or violent start of something unwelcome, such as war, disease.', + synonyms: ['outburst', 'upsurge', 'eruption'] + }, + { + word: 'oculars', + type: 'adjective', + meaning: 'of or connected with the eyes or vision.', + synonyms: ['optical', 'visual', 'seeable'] + }, + { + word: 'repolish', + type: 'verb', + meaning: 'to polish something again', + synonyms: ['reshine', 'glaze', 'luster'] + }, + { + word: 'donuts', + type: 'noun', + meaning: 'a small fried cake of sweetened dough, typically in the shape of a ball or ring.', + synonyms: ['sweet roll', 'bun', 'dunker'] + }, + +] + + +const alphabets = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' ] \ No newline at end of file diff --git a/Public/Word Guessing Game/libs/img/background.jpg b/Public/Word Guessing Game/libs/img/background.jpg new file mode 100644 index 00000000..f0618e78 Binary files /dev/null and b/Public/Word Guessing Game/libs/img/background.jpg differ diff --git a/Public/Word Guessing Game/libs/img/js.png b/Public/Word Guessing Game/libs/img/js.png new file mode 100644 index 00000000..17efa256 Binary files /dev/null and b/Public/Word Guessing Game/libs/img/js.png differ