├── .babelrc ├── .gitignore ├── LICENSE ├── README.md ├── package-lock.json ├── package.json ├── public ├── favicon.ico ├── index.html └── manifest.json └── src ├── App.js ├── App.test.js ├── components ├── AnswerBox │ ├── index.js │ └── styled.js ├── FailBox │ ├── index.js │ └── styled.js ├── Human │ ├── index.js │ └── styled.js └── Result │ ├── index.js │ └── styled.js ├── globalStyles.js ├── index.html ├── index.js ├── logo.svg ├── serviceWorker.js └── styled.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "es2015", 4 | "react" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Local History Files 2 | *.history 3 | build 4 | # Logs 5 | logs 6 | *.log 7 | npm-debug.log* 8 | 9 | # Runtime data 10 | pids 11 | *.pid 12 | *.seed 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 21 | .grunt 22 | 23 | # node-waf configuration 24 | .lock-wscript 25 | 26 | # Compiled binary addons (http://nodejs.org/api/addons.html) 27 | build/Release 28 | 29 | # Dependency directory 30 | node_modules 31 | 32 | # Optional npm cache directory 33 | .npm 34 | 35 | # Optional REPL history 36 | .node_repl_history 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Yusuf Özlü 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 2 | 3 | ## Available Scripts 4 | 5 | In the project directory, you can run: 6 | 7 | ### `npm start` 8 | 9 | Runs the app in the development mode.
10 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 11 | 12 | The page will reload if you make edits.
13 | You will also see any lint errors in the console. 14 | 15 | ### `npm test` 16 | 17 | Launches the test runner in the interactive watch mode.
18 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 19 | 20 | ### `npm run build` 21 | 22 | Builds the app for production to the `build` folder.
23 | It correctly bundles React in production mode and optimizes the build for the best performance. 24 | 25 | The build is minified and the filenames include the hashes.
26 | Your app is ready to be deployed! 27 | 28 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 29 | 30 | ### `npm run eject` 31 | 32 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 33 | 34 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 35 | 36 | Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 37 | 38 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 39 | 40 | ## Learn More 41 | 42 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 43 | 44 | To learn React, check out the [React documentation](https://reactjs.org/). 45 | 46 | ### Code Splitting 47 | 48 | This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting 49 | 50 | ### Analyzing the Bundle Size 51 | 52 | This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size 53 | 54 | ### Making a Progressive Web App 55 | 56 | This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app 57 | 58 | ### Advanced Configuration 59 | 60 | This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration 61 | 62 | ### Deployment 63 | 64 | This section has moved here: https://facebook.github.io/create-react-app/docs/deployment 65 | 66 | ### `npm run build` fails to minify 67 | 68 | This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify 69 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-hangman", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "react": "^16.8.6", 7 | "react-dom": "^16.8.6", 8 | "react-scripts": "3.0.1", 9 | "styled-components": "^4.2.0" 10 | }, 11 | "scripts": { 12 | "start": "react-scripts start", 13 | "build": "react-scripts build", 14 | "test": "react-scripts test", 15 | "eject": "react-scripts eject" 16 | }, 17 | "eslintConfig": { 18 | "extends": "react-app" 19 | }, 20 | "homepage": "http://ozluy.github.io/projects/react-hangman", 21 | "browserslist": { 22 | "production": [ 23 | ">0.2%", 24 | "not dead", 25 | "not op_mini all" 26 | ], 27 | "development": [ 28 | "last 1 chrome version", 29 | "last 1 firefox version", 30 | "last 1 safari version" 31 | ] 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ozluy/react-hangman/929850a84221922632004f17a5e495fb5184ae3e/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 22 | React Hangman 23 | 24 | 25 | 26 |
27 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | } 10 | ], 11 | "start_url": ".", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useRef } from 'react' 2 | import { Button } from './components/Result/styled' 3 | import AnswerBox from './components/AnswerBox' 4 | import FailBox from './components/FailBox' 5 | import Result from './components/Result' 6 | import Human from './components/Human' 7 | import { 8 | Gallow, 9 | DownPipe, 10 | RightBlueTriangle, 11 | Input, 12 | AppWrapper, 13 | GameInstruction, 14 | } from './styled' 15 | 16 | export default () => { 17 | const [wordFromAPI, setWordFromAPI] = useState([]) 18 | const [isPaused, setIsPaused] = useState(false) 19 | const [isGameOver, setIsGameOver] = useState(false) 20 | const [resultBox, setResultBox] = useState({ 21 | disabled: false, 22 | title: 'Hangman', 23 | buttonLabel: 'Start Game', 24 | }) 25 | const [failedLetters, setFailedLetters] = useState([]) 26 | const [correctLetters, setCorrectLetters] = useState([]) 27 | const [word, setWord] = useState('') 28 | const inputRef = useRef(null) 29 | 30 | const handOnKeyPress = event => { 31 | let keyChar = event.key 32 | event.preventDefault() 33 | if ( 34 | wordFromAPI.length > 0 && 35 | 'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM'.indexOf(keyChar) > 36 | -1 37 | ) { 38 | keyChar = keyChar.toUpperCase() 39 | if ( 40 | !failedLetters.find(x => x === keyChar) && 41 | !correctLetters.find(x => x === keyChar) 42 | ) { 43 | let count = 0 44 | for (let i = 0; i < wordFromAPI.length; i++) { 45 | if (keyChar === wordFromAPI[i]) { 46 | count++ 47 | const newCorrectLetters = correctLetters.concat([keyChar]) 48 | setCorrectLetters(newCorrectLetters) 49 | countCorrectLetters(newCorrectLetters) 50 | return 51 | } 52 | } 53 | if (count === 0) { 54 | if (failedLetters.length === 10) { 55 | setResultBox({ 56 | disabled: false, 57 | title: `Game Over { word: ${word} }`, 58 | buttonLabel: 'Restart Game', 59 | }) 60 | setIsGameOver(true) 61 | } 62 | setFailedLetters(failedLetters.concat([keyChar])) 63 | } 64 | } 65 | } 66 | } 67 | 68 | const emptyBoxList = () => { 69 | let arrayOfSpace = [] 70 | if (wordFromAPI.length > 0) { 71 | const arraySize = wordFromAPI.length 72 | for (let x = 0; x < 12 - arraySize; x++) { 73 | arrayOfSpace.push(' ') 74 | } 75 | } 76 | return arrayOfSpace 77 | } 78 | 79 | const startGame = () => { 80 | setResultBox({ 81 | disabled: true, 82 | }) 83 | setFailedLetters([]) 84 | setCorrectLetters([]) 85 | setWordFromAPI([]) 86 | setWord('') 87 | getDataFromAPI() 88 | setIsGameOver(false) 89 | inputRef.current.focus() 90 | } 91 | 92 | const continueGame = () => { 93 | setResultBox({ 94 | disabled: true, 95 | }) 96 | inputRef.current.focus() 97 | } 98 | 99 | const wordSetter = word => { 100 | let wordArr = word.toUpperCase().split('') 101 | wordArr.map(item => { 102 | item === '-' && wordArr.splice(wordArr.indexOf('-'), 1) 103 | item === ' ' && wordArr.splice(wordArr.indexOf(' '), 1) 104 | return item 105 | }) 106 | 107 | setWordFromAPI(wordArr) 108 | setWord(word) 109 | } 110 | 111 | const getDataFromAPI = () => { 112 | const params = { 113 | hasDictionaryDef: true, 114 | minCorpusCount: 0, 115 | maxCorpusCount: -1, 116 | maxDictionaryCount: -1, 117 | minLength: 3, 118 | maxLength: 12, 119 | api_key: 'a2a73e7b926c924fad7001ca3111acd55af2ffabf50eb4ae5', 120 | } 121 | let url = new URL('http://api.wordnik.com/v4/words.json/randomWord') 122 | Object.keys(params).forEach(key => 123 | url.searchParams.append(key, params[key]) 124 | ) 125 | fetch(url, { 126 | method: 'GET', 127 | }) 128 | .then(response => { 129 | const responseStatus = response.status 130 | if (responseStatus >= 400 && responseStatus <= 500) { 131 | throw Error('API error, creating random word localy!') 132 | } 133 | return response.json() 134 | }) 135 | .then(response => { 136 | wordSetter(response.word) 137 | return response.status 138 | }) 139 | .catch(error => { 140 | console.log(error) 141 | const fruits = [ 142 | 'Apple', 143 | 'Orange', 144 | 'Pear', 145 | 'Lemon', 146 | 'Kiwi', 147 | 'Watermelon', 148 | 'Strawberry', 149 | 'Banana', 150 | ] 151 | const randomFruit = fruits[Math.floor(Math.random() * fruits.length)] 152 | wordSetter(randomFruit) 153 | }) 154 | } 155 | 156 | const countCorrectLetters = correctLetters => { 157 | let uniqueLetters = filterUniqueItems(wordFromAPI) 158 | if (correctLetters.length === uniqueLetters.length) { 159 | setResultBox({ 160 | disabled: false, 161 | title: '★ You Won! ★', 162 | buttonLabel: 'Restart Game', 163 | }) 164 | setIsGameOver(true) 165 | } 166 | } 167 | 168 | const filterUniqueItems = items => { 169 | const obj = {}, 170 | uniqueItems = [] 171 | for (var i = 0, l = items.length; i < l; ++i) { 172 | if (obj.hasOwnProperty(items[i])) { 173 | continue 174 | } 175 | uniqueItems.push(items[i]) 176 | obj[items[i]] = 1 177 | } 178 | return uniqueItems 179 | } 180 | 181 | return ( 182 | 183 | Press any keys (letters) to play. 184 | 185 | 186 | 187 | setIsPaused(false)} 191 | onBlur={() => { 192 | if (!isGameOver) { 193 | setIsPaused(true) 194 | setResultBox({ 195 | title: 'Game is Paused', 196 | disabled: false, 197 | buttonLabel: 'continue', 198 | }) 199 | } 200 | }} 201 | /> 202 | 203 | 204 | 205 | 206 | 211 | 212 | 213 | 219 | {!isPaused && } 220 | 221 | ) 222 | } 223 | -------------------------------------------------------------------------------- /src/App.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import App from './App'; 4 | 5 | it('renders without crashing', () => { 6 | const div = document.createElement('div'); 7 | ReactDOM.render(, div); 8 | ReactDOM.unmountComponentAtNode(div); 9 | }); 10 | -------------------------------------------------------------------------------- /src/components/AnswerBox/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { Item, Wrapper } from './styled' 3 | 4 | export default ({ spaces, correctLetters, wordFromAPI }) => ( 5 | 6 | {spaces.map((item, index) => ( 7 | 8 | ))} 9 | {wordFromAPI.map((letter, index) => { 10 | return ( 11 | 12 | {correctLetters.find(x => x === letter) ? letter : ''} 13 | 14 | ) 15 | })} 16 | 17 | ) 18 | -------------------------------------------------------------------------------- /src/components/AnswerBox/styled.js: -------------------------------------------------------------------------------- 1 | import styled, { css } from 'styled-components' 2 | 3 | export const Wrapper = styled.div` 4 | z-index: 3; 5 | position: absolute; 6 | bottom: 40px; 7 | width: calc(100% - 50px); 8 | height: 70px; 9 | margin: 0 auto; 10 | text-align: center; 11 | left: 0; 12 | right: 0; 13 | ` 14 | 15 | export const Item = styled.div` 16 | float: left; 17 | background-color: var(--color-darkgrey); 18 | width: 65px; 19 | height: 70px; 20 | margin: 0 3px; 21 | border-radius: 5px; 22 | text-align: center; 23 | line-height: 70px; 24 | text-transform: uppercase; 25 | font-size: var(--font-size-large); 26 | color: var(--color-white); 27 | 28 | ${({ disabled }) => 29 | disabled && 30 | css` 31 | background-color: var(--color-lightgrey); 32 | `}; 33 | 34 | &:first-child { 35 | margin-left: 0; 36 | } 37 | 38 | &:last-child { 39 | margin-right: 0; 40 | } 41 | ` 42 | -------------------------------------------------------------------------------- /src/components/FailBox/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { Wrapper, List, ListItem, Title } from './styled' 3 | 4 | export default ({ failedLetters }) => ( 5 | 6 | You missed: 7 | 8 | {failedLetters.map(item => ( 9 | {item} 10 | ))} 11 | 12 | 13 | ) 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/components/FailBox/styled.js: -------------------------------------------------------------------------------- 1 | import styled from 'styled-components' 2 | 3 | export const Wrapper = styled.div` 4 | position: absolute; 5 | top: 40px; 6 | right: 0; 7 | width: 500px; 8 | ` 9 | export const Title = styled.h1` 10 | text-transform: uppercase; 11 | color: var(--color-darkgrey); 12 | ` 13 | export const List = styled.div` 14 | width: 100%; 15 | height: 70px; 16 | ` 17 | export const ListItem = styled.div` 18 | text-align: center; 19 | color: var(--color-blue); 20 | float: left; 21 | font-size: var(--font-size-large); 22 | height: 70px; 23 | margin: 10px; 24 | text-transform: uppercase; 25 | 26 | &:first-child { 27 | margin-left: 0; 28 | } 29 | 30 | &:last-child { 31 | margin-right: 0; 32 | } 33 | ` 34 | -------------------------------------------------------------------------------- /src/components/Human/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { 3 | Man, 4 | Head, 5 | Ear, 6 | Hair, 7 | Eye, 8 | Nose, 9 | Mouth, 10 | Neck, 11 | Arm, 12 | Hand, 13 | Corpus, 14 | Leg, 15 | Chest, 16 | Foot, 17 | } from './styled' 18 | 19 | const VisibilitySetter = ({ visible, component: Component, ...rest }) => 20 | visible ? : null 21 | 22 | export default ({ failedLetterCount }) => ( 23 | 24 | = 1} component={Head}> 25 | 26 | 27 | 28 | 29 | 30 | 31 | = 11} /> 32 | 33 | = 2} component={Neck} /> 34 | = 3} component={Corpus}> 35 | = 3} component={Chest}> 36 | = 4} component={Arm}> 37 | = 6} component={Hand} /> 38 | 39 | = 8} component={Leg}> 40 | = 10} 42 | component={Foot} 43 | /> 44 | 45 | 46 | = 3} 48 | component={Chest} 49 | right 50 | > 51 | = 5} 53 | component={Arm} 54 | right 55 | > 56 | = 7} component={Hand} /> 57 | 58 | = 9} 60 | component={Leg} 61 | right 62 | > 63 | = 11} 65 | component={Foot} 66 | right 67 | /> 68 | 69 | 70 | 71 | 72 | ) 73 | -------------------------------------------------------------------------------- /src/components/Human/styled.js: -------------------------------------------------------------------------------- 1 | import styled, { css } from 'styled-components' 2 | 3 | export const Man = styled.div` 4 | position: relative; 5 | margin: 70px 0 0 77.5px; 6 | width: 100px; 7 | ` 8 | export const Hair = styled.div` 9 | width: 100%; 10 | height: 15px; 11 | position: absolute; 12 | background-color: var(--color-hair); 13 | border-radius: 50% 0% 100% 0%; 14 | ` 15 | export const Eye = styled.div` 16 | width: 15px; 17 | height: 20px; 18 | background-color: var(--color-eye); 19 | border-radius: 50%; 20 | margin-top: 35px; 21 | position: absolute; 22 | border: solid 5px var(--color-white); 23 | left: 15px; 24 | 25 | ${({ right }) => 26 | right && 27 | css` 28 | left: auto; 29 | right: 15px; 30 | `}; 31 | ` 32 | 33 | export const Ear = styled.div` 34 | width: 15px; 35 | height: 20px; 36 | background-color: var(--color-ear); 37 | top: 40px; 38 | position: absolute; 39 | border-radius: 40% 40%; 40 | left: -15px; 41 | 42 | ${({ right }) => 43 | right && 44 | css` 45 | left: auto; 46 | right: -15px; 47 | `}; 48 | ` 49 | export const Nose = styled.div` 50 | top: 50px; 51 | width: 15px; 52 | height: 20px; 53 | background-color: var(--color-nose); 54 | left: 0; 55 | right: 0; 56 | position: absolute; 57 | margin: 0 auto; 58 | border-radius: 100% 100% 50% 50%; 59 | ` 60 | export const Mouth = styled.div` 61 | width: 40px; 62 | border: solid 5px var(--color-white); 63 | left: 0; 64 | right: 0; 65 | position: absolute; 66 | margin: 0 auto; 67 | top: 75px; 68 | border-radius: 0 0 50% 50%; 69 | 70 | ${({ sad }) => 71 | sad && 72 | css` 73 | border-radius: 50% 50% 0 0; 74 | height: 20px; 75 | border-width: 10px 0 0 0; 76 | `}; 77 | ` 78 | 79 | export const Head = styled.div` 80 | position: absolute; 81 | z-index: 2; 82 | margin: 0 auto; 83 | top: 0; 84 | left: 0; 85 | right: 0; 86 | width: 80px; 87 | height: 106px; 88 | background-color: var(--color-humanbody); 89 | border-radius: 30% 30% 50% 50%; 90 | ` 91 | export const Neck = styled.div` 92 | position: absolute; 93 | margin: 0 auto; 94 | top: 100px; 95 | left: 0; 96 | right: 0; 97 | width: 20px; 98 | height: 40px; 99 | background-color: var(--color-humanbody); 100 | ` 101 | export const Corpus = styled.div` 102 | position: absolute; 103 | margin: 0 auto; 104 | top: 112.5px; 105 | left: 0; 106 | right: 0; 107 | width: 60px; 108 | height: 95px; 109 | border-radius: 5px; 110 | background-color: var(--color-bodybg); 111 | ` 112 | export const Chest = styled.div` 113 | display: inline-block; 114 | width: 30px; 115 | height: 70px; 116 | background-color: var(--color-shirtLeft); 117 | border-radius: 5px 0 0 0; 118 | ${({ right }) => 119 | right && 120 | css` 121 | background-color: var(--color-shirtRight); 122 | border-radius: 0 5px 0 0; 123 | `} 124 | ` 125 | export const Arm = styled.div` 126 | position: relative; 127 | transform: rotate(45deg); 128 | margin-left: -27px; 129 | margin-top: -5px; 130 | width: 22px; 131 | height: 80px; 132 | background-color: var(--color-shirtLeft); 133 | border-radius: 5px; 134 | ${({ right }) => 135 | right && 136 | css` 137 | transform: rotate(-45deg); 138 | margin-left: 35px; 139 | background-color: var(--color-shirtRight); 140 | `} 141 | ` 142 | export const Hand = styled.div` 143 | position: absolute; 144 | bottom: -14px; 145 | border-radius: 0 0 50% 50%; 146 | left: 0; 147 | right: 0; 148 | margin: 0 auto; 149 | width: 15px; 150 | height: 15px; 151 | background-color: var(--color-humanbody); 152 | ` 153 | export const Leg = styled.div` 154 | background-color: var(--color-bodybg); 155 | 156 | height: 70px; 157 | width: 25px; 158 | margin-top: 10px; 159 | margin-left: -10px; 160 | transform: rotate(15deg); 161 | ${({ right }) => 162 | right && 163 | css` 164 | transform: rotate(-15deg); 165 | margin-left: 15px; 166 | `} 167 | ` 168 | export const Foot = styled.div` 169 | position: absolute; 170 | bottom: -14px; 171 | border-radius: 0 0 50% 50%; 172 | left: -15px; 173 | right: 0; 174 | margin: 0 auto; 175 | width: 40px; 176 | height: 15px; 177 | background-color: var(--color-humanbody); 178 | ${({ right }) => 179 | right && 180 | css` 181 | left: 0; 182 | `} 183 | ` 184 | -------------------------------------------------------------------------------- /src/components/Result/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { Wrapper, Content, Title, Button } from './styled' 3 | 4 | export default ({ buttonAction, disabled, title, buttonLabel }) => ( 5 | 6 | 7 | {title} 8 | 9 | 10 | 11 | ) 12 | -------------------------------------------------------------------------------- /src/components/Result/styled.js: -------------------------------------------------------------------------------- 1 | import styled, { css } from 'styled-components' 2 | 3 | export const Wrapper = styled.div` 4 | z-index: 10; 5 | position: absolute; 6 | background-color: rgba(0, 0, 0, 0.7); 7 | top: 0; 8 | left: 0; 9 | right: 0; 10 | bottom: 0; 11 | transition: all 400ms ease-in-out; 12 | 13 | ${({ disabled }) => 14 | disabled && 15 | css` 16 | visibility: 0; 17 | opacity: 0; 18 | z-index: -1; 19 | `} 20 | ` 21 | export const Content = styled.div` 22 | top: calc(50% - 75px); 23 | left: 0; 24 | right: 0; 25 | bottom: 0; 26 | position: absolute; 27 | margin: 0 auto; 28 | width: 300px; 29 | height: 150px; 30 | text-align: center; 31 | ` 32 | export const Title = styled.h1` 33 | text-transform: uppercase; 34 | color: var(--color-white); 35 | font-size: var(--color-large); 36 | ` 37 | export const Button = styled.button` 38 | text-transform: uppercase; 39 | border: dashed 2px var(--color-yellow); 40 | border-radius: 25px; 41 | background-color: transparent; 42 | color: var(--color-yellow); 43 | padding: 15px 40px; 44 | font-size: var(--color-default); 45 | font-weight: var(--color-bold); 46 | outline: none; 47 | cursor: pointer; 48 | 49 | &:hover { 50 | opacity: 0.6; 51 | } 52 | 53 | ${({ pause }) => 54 | pause && 55 | css` 56 | position: absolute; 57 | right: 16px; 58 | top: 16px; 59 | `} 60 | ` 61 | -------------------------------------------------------------------------------- /src/globalStyles.js: -------------------------------------------------------------------------------- 1 | import { createGlobalStyle } from 'styled-components' 2 | 3 | export default createGlobalStyle` 4 | :root { 5 | --color-bodybg: #3C3F64; 6 | --color-blue: #585DFE; 7 | --color-darkgrey: #53555D; 8 | --color-lightgrey: #E6E6E7; 9 | --color-humanbody: #FFCD82; 10 | --color-shirtLeft: #71CC54; 11 | --color-shirtRight: #12A56B; 12 | --color-appbg: #F5F5F5; 13 | --color-white: #FFFFFF; 14 | --color-yellow: #FFB800; 15 | --color-eye: #010000; 16 | --color-ear: #FFCD72; 17 | --color-hair: #000; 18 | --color-nose: #12A56B; 19 | --font-size-default: 14px; 20 | --font-size-large: 36px; 21 | } 22 | 23 | html{ 24 | height: 100%; 25 | width: 100%; 26 | } 27 | 28 | body { 29 | font-weight: bold; 30 | font-size: var(--font-size-default); 31 | background-color: var(--color-bodybg); 32 | margin: 0; 33 | font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; 34 | -webkit-font-smoothing: antialiased; 35 | -moz-osx-font-smoothing: grayscale; 36 | height: 100%; 37 | width: 100%; 38 | } 39 | 40 | #root { 41 | display: flex; 42 | justify-content: center; 43 | align-items: center; 44 | height: 100%; 45 | width: 100%; 46 | } 47 | ` 48 | -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Hangman || Adam Asmaca 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import ReactDOM from 'react-dom' 3 | import App from './App' 4 | import * as serviceWorker from './serviceWorker' 5 | import GlobalStyles from './globalStyles' 6 | 7 | ReactDOM.render( 8 | <> 9 | 10 | , 11 | document.getElementById('root') 12 | ) 13 | 14 | // If you want your app to work offline and load faster, you can change 15 | // unregister() to register() below. Note this comes with some pitfalls. 16 | // Learn more about service workers: https://bit.ly/CRA-PWA 17 | serviceWorker.unregister() 18 | -------------------------------------------------------------------------------- /src/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/serviceWorker.js: -------------------------------------------------------------------------------- 1 | // This optional code is used to register a service worker. 2 | // register() is not called by default. 3 | 4 | // This lets the app load faster on subsequent visits in production, and gives 5 | // it offline capabilities. However, it also means that developers (and users) 6 | // will only see deployed updates on subsequent visits to a page, after all the 7 | // existing tabs open on the page have been closed, since previously cached 8 | // resources are updated in the background. 9 | 10 | // To learn more about the benefits of this model and instructions on how to 11 | // opt-in, read https://bit.ly/CRA-PWA 12 | 13 | const isLocalhost = Boolean( 14 | window.location.hostname === 'localhost' || 15 | // [::1] is the IPv6 localhost address. 16 | window.location.hostname === '[::1]' || 17 | // 127.0.0.1/8 is considered localhost for IPv4. 18 | window.location.hostname.match( 19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ 20 | ) 21 | ); 22 | 23 | export function register(config) { 24 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { 25 | // The URL constructor is available in all browsers that support SW. 26 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href); 27 | if (publicUrl.origin !== window.location.origin) { 28 | // Our service worker won't work if PUBLIC_URL is on a different origin 29 | // from what our page is served on. This might happen if a CDN is used to 30 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374 31 | return; 32 | } 33 | 34 | window.addEventListener('load', () => { 35 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; 36 | 37 | if (isLocalhost) { 38 | // This is running on localhost. Let's check if a service worker still exists or not. 39 | checkValidServiceWorker(swUrl, config); 40 | 41 | // Add some additional logging to localhost, pointing developers to the 42 | // service worker/PWA documentation. 43 | navigator.serviceWorker.ready.then(() => { 44 | console.log( 45 | 'This web app is being served cache-first by a service ' + 46 | 'worker. To learn more, visit https://bit.ly/CRA-PWA' 47 | ); 48 | }); 49 | } else { 50 | // Is not localhost. Just register service worker 51 | registerValidSW(swUrl, config); 52 | } 53 | }); 54 | } 55 | } 56 | 57 | function registerValidSW(swUrl, config) { 58 | navigator.serviceWorker 59 | .register(swUrl) 60 | .then(registration => { 61 | registration.onupdatefound = () => { 62 | const installingWorker = registration.installing; 63 | if (installingWorker == null) { 64 | return; 65 | } 66 | installingWorker.onstatechange = () => { 67 | if (installingWorker.state === 'installed') { 68 | if (navigator.serviceWorker.controller) { 69 | // At this point, the updated precached content has been fetched, 70 | // but the previous service worker will still serve the older 71 | // content until all client tabs are closed. 72 | console.log( 73 | 'New content is available and will be used when all ' + 74 | 'tabs for this page are closed. See https://bit.ly/CRA-PWA.' 75 | ); 76 | 77 | // Execute callback 78 | if (config && config.onUpdate) { 79 | config.onUpdate(registration); 80 | } 81 | } else { 82 | // At this point, everything has been precached. 83 | // It's the perfect time to display a 84 | // "Content is cached for offline use." message. 85 | console.log('Content is cached for offline use.'); 86 | 87 | // Execute callback 88 | if (config && config.onSuccess) { 89 | config.onSuccess(registration); 90 | } 91 | } 92 | } 93 | }; 94 | }; 95 | }) 96 | .catch(error => { 97 | console.error('Error during service worker registration:', error); 98 | }); 99 | } 100 | 101 | function checkValidServiceWorker(swUrl, config) { 102 | // Check if the service worker can be found. If it can't reload the page. 103 | fetch(swUrl) 104 | .then(response => { 105 | // Ensure service worker exists, and that we really are getting a JS file. 106 | const contentType = response.headers.get('content-type'); 107 | if ( 108 | response.status === 404 || 109 | (contentType != null && contentType.indexOf('javascript') === -1) 110 | ) { 111 | // No service worker found. Probably a different app. Reload the page. 112 | navigator.serviceWorker.ready.then(registration => { 113 | registration.unregister().then(() => { 114 | window.location.reload(); 115 | }); 116 | }); 117 | } else { 118 | // Service worker found. Proceed as normal. 119 | registerValidSW(swUrl, config); 120 | } 121 | }) 122 | .catch(() => { 123 | console.log( 124 | 'No internet connection found. App is running in offline mode.' 125 | ); 126 | }); 127 | } 128 | 129 | export function unregister() { 130 | if ('serviceWorker' in navigator) { 131 | navigator.serviceWorker.ready.then(registration => { 132 | registration.unregister(); 133 | }); 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /src/styled.js: -------------------------------------------------------------------------------- 1 | import styled from 'styled-components' 2 | 3 | export const AppWrapper = styled.main` 4 | position: relative; 5 | overflow: hidden; 6 | height: 500px; 7 | width: 900px; 8 | background-color: var(--color-appbg); 9 | border-radius: 5px; 10 | ` 11 | 12 | export const GameInstruction = styled.p` 13 | position: absolute; 14 | top: 16px; 15 | left: 16px; 16 | margin: 0; 17 | ` 18 | 19 | export const Gallow = styled.div` 20 | position: relative; 21 | width: 150px; 22 | height: 15px; 23 | background-color: var(--color-darkgrey); 24 | top: 50px; 25 | border-radius: 0 5px 5px 0; 26 | ` 27 | 28 | export const DownPipe = styled.div` 29 | position: absolute; 30 | left: 120px; 31 | width: 15px; 32 | height: 40px; 33 | background-color: var(--color-darkgrey); 34 | border-radius: 5px; 35 | ` 36 | 37 | export const RightBlueTriangle = styled.div` 38 | position: absolute; 39 | width: 0; 40 | height: 0; 41 | right: 0; 42 | bottom: 0; 43 | border-style: solid; 44 | border-width: 0 0 250px 250px; 45 | border-color: transparent transparent var(--color-blue) transparent; 46 | ` 47 | export const Input = styled.input` 48 | position: absolute; 49 | opacity: 0; 50 | ` 51 | --------------------------------------------------------------------------------