├── img ├── smo'.avif ├── head-PhotoRoom.png ├── webstartview.jpg ├── mobilestartview.jpg ├── fullBody-PhotoRoom.png ├── hook-PhotoRoom (1).png ├── leftarm-PhotoRoom.png ├── leftleg-PhotoRoom.png ├── rightleg-PhotoRoom.png ├── midsection-PhotoRoom.png └── rightarm-PhotoRoom (1).png ├── readme.md ├── index.html ├── style.css └── script.js /img/smo'.avif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LatoyaHead/Hangman-Game/HEAD/img/smo'.avif -------------------------------------------------------------------------------- /img/head-PhotoRoom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LatoyaHead/Hangman-Game/HEAD/img/head-PhotoRoom.png -------------------------------------------------------------------------------- /img/webstartview.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LatoyaHead/Hangman-Game/HEAD/img/webstartview.jpg -------------------------------------------------------------------------------- /img/mobilestartview.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LatoyaHead/Hangman-Game/HEAD/img/mobilestartview.jpg -------------------------------------------------------------------------------- /img/fullBody-PhotoRoom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LatoyaHead/Hangman-Game/HEAD/img/fullBody-PhotoRoom.png -------------------------------------------------------------------------------- /img/hook-PhotoRoom (1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LatoyaHead/Hangman-Game/HEAD/img/hook-PhotoRoom (1).png -------------------------------------------------------------------------------- /img/leftarm-PhotoRoom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LatoyaHead/Hangman-Game/HEAD/img/leftarm-PhotoRoom.png -------------------------------------------------------------------------------- /img/leftleg-PhotoRoom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LatoyaHead/Hangman-Game/HEAD/img/leftleg-PhotoRoom.png -------------------------------------------------------------------------------- /img/rightleg-PhotoRoom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LatoyaHead/Hangman-Game/HEAD/img/rightleg-PhotoRoom.png -------------------------------------------------------------------------------- /img/midsection-PhotoRoom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LatoyaHead/Hangman-Game/HEAD/img/midsection-PhotoRoom.png -------------------------------------------------------------------------------- /img/rightarm-PhotoRoom (1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LatoyaHead/Hangman-Game/HEAD/img/rightarm-PhotoRoom (1).png -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Hangman Game Project 2 | 3 | ## Description 4 | Image of Hangman Game 5 | 6 | Hangman is a simple word guessing game. Players try to figure out an unknown word by guessing letters. If too many letters which do not appear in the word are guessed, the player is hanged (and loses). 7 | 8 | Let us see how this game works. Chose either 1 Player or 2 Player Game Mode. Next, choose from three options: ‘Fruits’, ‘Vegetables’ and ‘Animals’. Once the user selects the options, the computer chooses a word from the corresponding category. 9 | 10 | Now, the user(s) has to guess the chosen word using the letter buttons provided on the screen. The user can make six wrong attempts before he loses the game. Most frequently, the person is drawn in 6 parts (for 6 letter guesses) in the order: head, body, left leg, right leg, left arm, right arm. 11 | 12 | If the user(s) guesses the word, we display a winning message on the screen. If not, we display a lost message. Along with this message, we also provide the user with the solution and a button to start a ‘New Game’. 13 | 14 | ## Tech Stack 15 | 16 | - HTML 17 | - CSS 18 | - Javascript 19 | 20 | ## Upcoming Features 21 | 22 | - Add More Categories 23 | - Timed Game Mode 24 | - Seasonal Themes(Halloween, Thanksgiving, Christmas, etc.) 25 | 26 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Hangman Game 9 | 10 | 11 |

Hangman Game

12 |
13 |

14 |
15 |
16 |
17 |

PLAYER 1 TURN

18 |
19 |
20 |

GAME MODE

21 |
22 | 23 | 24 |
25 |
26 |
27 |
28 |
29 |
30 | Hangman Hook 31 |
32 | head 33 |
34 |
35 | body 36 |
37 |
38 | right-arm 39 |
40 |
41 | left-arm 42 |
43 |
44 | right-leg 45 |
46 |
47 | left-leg 48 |
49 |
50 |
51 | 52 |
53 |
54 | 55 |
56 |
57 | 58 |
59 |

PLAYER 2 TURN

60 |
61 |
62 |
63 |
64 |
65 | Hangman Hook 66 |
67 | head 68 |
69 |
70 | body 71 |
72 |
73 | right-arm 74 |
75 |
76 | left-arm 77 |
78 |
79 | right-leg 80 |
81 |
82 | left-leg 83 |
84 |
85 |
86 |
87 |
88 | 89 | 90 | -------------------------------------------------------------------------------- /style.css: -------------------------------------------------------------------------------- 1 | * { 2 | padding: 0; 3 | margin: 0; 4 | box-sizing: border-box; 5 | font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; 6 | font-weight: bold; 7 | } 8 | body { 9 | background-image: url(./img/smo\'.avif); 10 | background-position: 0px 0px; 11 | background-repeat: repeat-x; 12 | animation: animatedBackground 10s linear infinite alternate; 13 | } 14 | @keyframes animatedBackground { 15 | from { 16 | background-position: 0 0; 17 | } 18 | to { 19 | background-position: 100% 0; 20 | } 21 | } 22 | .title { 23 | text-transform: uppercase; 24 | background-image: linear-gradient(-225deg, #231557 0%, #44107a 29%, #ff1361 67%, #fff800 100%); 25 | background-size: auto auto; 26 | background-clip: border-box; 27 | background-size: 200% auto; 28 | color: #fff; 29 | background-clip: text; 30 | padding-top: .5em; 31 | -webkit-background-clip: text; 32 | -webkit-text-fill-color: transparent; 33 | animation: textclip 2s linear infinite; 34 | font-size: 100px; 35 | display: flex; 36 | justify-content: center; 37 | align-items: center; 38 | text-align: center; 39 | } 40 | @media (max-width: 700px){ 41 | .title { 42 | font-size: 40px; 43 | } 44 | } 45 | @keyframes textclip { 46 | to { 47 | background-position: 100% center; 48 | } 49 | } 50 | #mode-container button { 51 | padding: 0.6em 1.2em; 52 | border: 1px solid white; 53 | background-color: #ffffff; 54 | color: #000000; 55 | border-radius: 0.9em; 56 | display: flex; 57 | flex-direction:row; 58 | justify-content: space-between; 59 | margin: 1.2em 0 1em 0; 60 | box-shadow: 2px 4px 3px 0 #777; 61 | } 62 | .modes { 63 | display: flex; 64 | justify-content: center; 65 | gap: 20px; 66 | width: 100%; 67 | } 68 | @media (max-width: 700px){ 69 | .modes { 70 | flex-direction: column; 71 | gap: 0px; 72 | } 73 | } 74 | #mode-container { 75 | display: flex; 76 | justify-content: space-between; 77 | flex-direction: column; 78 | align-items: center; 79 | } 80 | .container { 81 | font-size: 16px; 82 | background-color: transparent; 83 | width: 90vw; 84 | max-width: 34em; 85 | padding: 1.5em; 86 | border-radius: 0.6em; 87 | box-shadow: 0 4px 10px 0 rgb(209, 209, 209); 88 | transition: 0.3s; 89 | } 90 | .container2 { 91 | font-size: 16px; 92 | background-color: transparent; 93 | width: 90vw; 94 | max-width: 34em; 95 | padding: 1.5em; 96 | border-radius: 0.6em; 97 | box-shadow: 0 4px 10px 0 rgb(209, 209, 209); 98 | transition: 0.3s; 99 | display: block; 100 | margin: auto; 101 | } 102 | .parentContainer { 103 | display: flex; 104 | justify-content: center; 105 | align-content: center; 106 | gap: 50px; 107 | } 108 | @media (max-width: 1000px) { 109 | .parentContainer { 110 | flex-direction: column; 111 | } 112 | body { 113 | background-size: cover; 114 | } 115 | } 116 | #options-container { 117 | text-align: center; 118 | } 119 | #options-container div { 120 | width: 100%; 121 | display: flex; 122 | justify-content: space-between; 123 | margin: 1.2em 0 1em 0; 124 | } 125 | #options-container.active { 126 | display: flex; 127 | justify-content: center; 128 | width: 100%; 129 | flex-direction: column; 130 | align-items: center; 131 | display: none; 132 | } 133 | #options-container .center.active { 134 | display: none; 135 | justify-content: center; 136 | } 137 | @media (max-width: 700px){ 138 | #options-container .center { 139 | display: flex; 140 | flex-direction: column; 141 | gap: 30px; 142 | } 143 | } 144 | #options-container button { 145 | padding: 0.6em 1.2em; 146 | border: 1px solid white; 147 | background-color: #ffffff; 148 | color: #000000; 149 | border-radius: 0.9em; 150 | text-transform: capitalize; 151 | box-shadow: 2px 4px 3px 0 #777; 152 | } 153 | #options-container button:disabled { 154 | border: 1px solid white; 155 | border-radius: 0.9em; 156 | color: #777; 157 | background-color: #ccc; 158 | } 159 | #options-container button:active { 160 | background-color: orange; 161 | border: 3px solid #000000; 162 | color: #000000; 163 | } 164 | .letter-container { 165 | width: 100%; 166 | display: flex; 167 | flex-wrap: wrap; 168 | justify-content: center; 169 | gap: 0.6em; 170 | } 171 | .letter-container2 { 172 | width: 100%; 173 | display: flex; 174 | flex-wrap: wrap; 175 | justify-content: center; 176 | gap: 0.6em; 177 | } 178 | #letter-container button { 179 | height: 2.4em; 180 | width: 2.4em; 181 | border-radius: 0.3em; 182 | background-color: #b020d4; 183 | color: whitesmoke; 184 | border: none; 185 | } 186 | @media (max-width: 700px) { 187 | #letter-container button { 188 | height: 4.4em; 189 | width: 4.4em; 190 | } 191 | #letter-container button:disabled { 192 | height: 4.4em !important; 193 | width: 4.4em !important; 194 | } 195 | } 196 | #letter-container button:disabled { 197 | height: 2.4em; 198 | width: 2.4em; 199 | border-radius: 0.3em; 200 | background-color: #ccc; 201 | color: black; 202 | border: none; 203 | } 204 | #letter-container2 button { 205 | height: 2.4em; 206 | width: 2.4em; 207 | border-radius: 0.3em; 208 | background-color: #b020d4; 209 | color: whitesmoke; 210 | border: none; 211 | } 212 | #letter-container2 button:disabled { 213 | height: 2.4em; 214 | width: 2.4em; 215 | border-radius: 0.3em; 216 | background-color: #ccc; 217 | color: black; 218 | border: none; 219 | } 220 | @media (max-width: 700px) { 221 | #letter-container2 button { 222 | height: 4.4em; 223 | width: 4.4em; 224 | } 225 | #letter-container2 button:disabled { 226 | height: 4.4em !important; 227 | width: 4.4em !important; 228 | } 229 | } 230 | .new-game-popup { 231 | background-color: #ffffff; 232 | position: absolute; 233 | left: 0; 234 | top: 0; 235 | height: 100%; 236 | width: 100%; 237 | display: flex; 238 | align-items: center; 239 | justify-content: center; 240 | flex-direction: column; 241 | border-radius: 0.6em; 242 | } 243 | #options-container button.active:disabled { 244 | background-color: white; 245 | color: #000000; 246 | display: none; 247 | } 248 | #options-container button:not(.active):disabled { 249 | display: none; 250 | } 251 | #mode-container button:not(.active):disabled { 252 | display: none; 253 | } 254 | #user-input-section { 255 | display: flex; 256 | justify-content: center; 257 | font-size: 1.8em; 258 | margin: 0.6em 0 1.2em 0; 259 | gap: 10px; 260 | color: whitesmoke; 261 | } 262 | #user-input-section2 { 263 | display: flex; 264 | justify-content: center; 265 | font-size: 1.8em; 266 | margin: 0.6em 0 1.2em 0; 267 | gap: 10px; 268 | color: whitesmoke; 269 | } 270 | .hide { 271 | display: none; 272 | } 273 | #result-text h2 { 274 | font-size: 1.8em; 275 | text-align: center; 276 | } 277 | #result-text p { 278 | font-size: 1.25em; 279 | margin: 1em 0 2em 0; 280 | } 281 | #result-text span { 282 | font-weight: 600; 283 | } 284 | #new-game-button { 285 | font-size: 1.25em; 286 | padding: 0.5em 1em; 287 | background-color: #f4c531; 288 | border: 1px solid white; 289 | color: #000000; 290 | border-radius: 0.7em; 291 | } 292 | .win-msg { 293 | color: #b020d4; 294 | } 295 | .lose-msg { 296 | color: red; 297 | } 298 | h3 { 299 | color: white 300 | } 301 | .hook { 302 | background-color: white; 303 | border-radius: 10px; 304 | text-align: center; 305 | position: relative; 306 | } 307 | .head, .head1 { 308 | position: absolute; 309 | top: 48px; 310 | left: 48%; 311 | display: none; 312 | } 313 | .body, .body1 { 314 | position: absolute; 315 | top: 79px; 316 | left: 48%; 317 | display: none; 318 | } 319 | .right-arm, .right-arm1 { 320 | position: absolute; 321 | top: 73px; 322 | left: 53%; 323 | display: none; 324 | } 325 | .left-arm, .left-arm1 { 326 | position: absolute; 327 | top: 64px; 328 | left: 44%; 329 | display: none; 330 | } 331 | .right-leg, .right-leg1 { 332 | position: absolute; 333 | top: 123px; 334 | left: 50.5%; 335 | display: none; 336 | } 337 | .left-leg, .left-leg1 { 338 | position: absolute; 339 | top: 123px; 340 | left: 47%; 341 | display: none; 342 | } 343 | #player1Btn.active { 344 | background-color: orange; 345 | } 346 | #player2Btn.mode2 { 347 | background-color: orange; 348 | } 349 | #mode-container :disabled { 350 | display: none; 351 | } 352 | h2 { 353 | color: whitesmoke; 354 | text-align: center; 355 | margin-bottom: 40px; 356 | display: none; 357 | } 358 | h4 { 359 | color: whitesmoke; 360 | text-align: center; 361 | margin-bottom: 20px;; 362 | } 363 | .firstOuterContainer { 364 | display: flex; 365 | flex-direction: column; 366 | align-items: center; 367 | } 368 | .outer-container { 369 | flex-direction: column; 370 | align-items: center; 371 | } -------------------------------------------------------------------------------- /script.js: -------------------------------------------------------------------------------- 1 | //Initial References 2 | const player1Btn = document.getElementById('player1Btn') 3 | const player2Btn = document.getElementById('player2Btn') 4 | const letterContainer = document.getElementById('letter-container') 5 | const optionsContainer = document.getElementById('options-container') 6 | const userInputSection = document.getElementById('user-input-section') 7 | const newGameContainer = document.getElementById('new-game-container') 8 | const newGameButton = document.getElementById('new-game-button') 9 | const playerTurnHeaders = document.querySelectorAll('h4') 10 | const hangmanHead= document.querySelector('.head') 11 | const hangmanBody= document.querySelector('.body') 12 | const hangmanRightArm= document.querySelector('.right-arm') 13 | const hangmanLeftArm= document.querySelector('.left-arm') 14 | const hangmanRightLeg= document.querySelector('.right-leg') 15 | const hangmanLeftLeg= document.querySelector('.left-leg') 16 | const hangmanHead1= document.querySelector('.head1') 17 | const hangmanBody1= document.querySelector('.body1') 18 | const hangmanRightArm1= document.querySelector('.right-arm1') 19 | const hangmanLeftArm1= document.querySelector('.left-arm1') 20 | const hangmanRightLeg1= document.querySelector('.right-leg1') 21 | const hangmanLeftLeg1= document.querySelector('.left-leg1') 22 | const resultText = document.getElementById('result-text') 23 | const outerContainer = document.querySelector('.outer-container') 24 | const container2 = document.querySelector('.container2') 25 | const letterContainer2 = document.getElementById('letter-container2') 26 | const optionsContainer2 = document.getElementById('options-container2') 27 | const userInputSection2 = document.getElementById('user-input-section2') 28 | const category =document.querySelector('.category') 29 | 30 | player1Btn.addEventListener('click', function(){ 31 | if(player2Btn.classList.contains('mode2')){ 32 | player2Btn.classList.remove('mode2') 33 | } 34 | player1Btn.classList.add('active') 35 | }) 36 | player2Btn.addEventListener('click', function(){ 37 | if(player1Btn.classList.contains('active')){ 38 | player1Btn.classList.remove('active') 39 | } 40 | player2Btn.classList.add('mode2') 41 | }) 42 | 43 | 44 | //Options value for buttons 45 | let options = { 46 | Fruits: ["Apple", "Oranges", "Bananas", "Watermelon", "Pineapple", "Grapes"], 47 | Vegetables: ["Broccoli", "Carrot", "Avocado", "Cabbage", "Celery", "Corn", "Zucchini", "Radish", "Cauliflower", "Turnip", "Tomato"], 48 | Animals: ["Cat", "Dog", "Fish", "Wolf", "Rabbit", "Snake", "Deer", "Lion", "Turtle"] 49 | } 50 | 51 | //Count 52 | let winCount = 0 53 | let winCount2 = 0 54 | let count = 0 55 | let count2 = 0 56 | let chosenWord = "" 57 | let displayLettersCount = 0 58 | 59 | 60 | //Display option buttons 61 | const displayOptions = (shouldRunAgain) => { 62 | if(shouldRunAgain && displayLettersCount === 0) return //if this is TRUE leave the function 63 | player2Btn.disabled = false 64 | player1Btn.disabled = false 65 | optionsContainer.style.display = 'block' 66 | outerContainer.style.display = 'none' 67 | let headers = document.querySelectorAll('h3') 68 | headers.forEach(elemH => elemH.style.display='block') 69 | optionsContainer.innerHTML += `

Select A Category

`; 70 | let buttonCon = document.createElement("div"); 71 | buttonCon.classList.add('center') 72 | for (let value in options) { 73 | buttonCon.innerHTML += ``; 74 | } 75 | optionsContainer.appendChild(buttonCon); 76 | }; 77 | const removeHangman = () => { //Built this function to remove hangman body parts 78 | hangmanHead.style.display = 'none' 79 | hangmanHead1.style.display = 'none' 80 | hangmanBody.style.display = 'none' 81 | hangmanBody1.style.display = 'none' 82 | hangmanRightArm.style.display = 'none' 83 | hangmanRightArm1.style.display = 'none' 84 | hangmanLeftArm.style.display = 'none' 85 | hangmanLeftArm1.style.display = 'none' 86 | hangmanLeftLeg.style.display = 'none' 87 | hangmanLeftLeg1.style.display = 'none' 88 | hangmanRightLeg.style.display = 'none' 89 | hangmanRightLeg1.style.display = 'none' 90 | } 91 | 92 | //Block all the Buttons 93 | const blocker = () => { 94 | let optionsButtons = document.querySelectorAll(".options"); 95 | let letterButtons = document.querySelectorAll(".letters"); 96 | let letterButtons1 = document.querySelectorAll(".letters1"); 97 | let headers = document.querySelectorAll('h2') 98 | displayLettersCount = 0; 99 | 100 | //disable all options 101 | optionsButtons.forEach((button) => { 102 | button.disabled = true; 103 | }); 104 | //disable all letters 105 | letterButtons.forEach((button) => { 106 | button.disabled = true; 107 | }); 108 | letterButtons1.forEach((button) => { 109 | button.disabled = true; 110 | }) 111 | outerContainer.style.display = 'none' 112 | 113 | 114 | headers.forEach((header) => { 115 | header.style.display = 'block' 116 | }) 117 | 118 | removeHangman() 119 | newGameContainer.classList.remove("hide"); 120 | }; 121 | 122 | const displayLetters = (letterElement, userInputElement, optionValue, spanClass) => { 123 | letterElement.classList.remove("hide"); 124 | userInputElement.innerText = ""; 125 | let optionArray = options[optionValue]; 126 | if(displayLettersCount === 0){ 127 | chosenWord = optionArray[Math.floor(Math.random() * optionArray.length)]; 128 | } 129 | chosenWord = chosenWord.toUpperCase(); 130 | let displayItem = chosenWord.replace(/./g, `_`) //regex pattern /./g replacing the dot 131 | userInputElement.innerHTML = displayItem; 132 | displayLettersCount++ 133 | } 134 | 135 | //Word Generator 136 | const generateWord = (optionValue) => { 137 | if(player2Btn.classList.contains('mode2')){ //displays letters for player 2 container 138 | outerContainer.style.display = 'block' 139 | displayLetters(letterContainer2, userInputSection2, optionValue, 'dashes2') 140 | category.textContent = `CATEGORY: ${optionValue}` 141 | category.style.display ='block' 142 | playerTurnHeaders[0].style.visibility = 'visible' 143 | } 144 | let optionsButtons = document.querySelectorAll(".options"); 145 | let headers = document.querySelectorAll('h3') 146 | headers.forEach(elemH => elemH.style.display='none') 147 | //If optionValue matches the button innerText then highlight the button 148 | optionsButtons.forEach((button) => { 149 | if (button.innerText.toLowerCase() === optionValue.toLowerCase()) { 150 | button.classList.add("active"); 151 | optionsContainer.classList.add('active') 152 | const buttonDivs = document.querySelector('.center') 153 | buttonDivs.classList.add('active') 154 | } 155 | category.textContent = `CATEGORY: ${optionValue}` 156 | category.style.display ='block' 157 | button.disabled = true; 158 | }); 159 | 160 | // outerContainer.style.display = 'none' 161 | displayLetters(letterContainer, userInputSection, optionValue, 'dashes') //displays letters for Player 1 container 162 | }; 163 | 164 | //Correct Answer 165 | const correctAnswer = (charArray, dashes, button, event) => { 166 | charArray.forEach((char, index) => { 167 | //if character in array is same as clicked button 168 | if (char === button.innerText) { 169 | //replace dash with letter 170 | dashes[index].innerText = char; 171 | //increment counter 172 | if (event.target.className === 'letters1'){ 173 | winCount2 += 1; 174 | //if winCount equals word length 175 | if (winCount2 == charArray.length) { 176 | resultText.innerHTML = `

PLAYER 2 WINS!! PLAYER 1 LOST!!!

The word was ${chosenWord}

`; 177 | //block all buttons 178 | blocker(); 179 | } 180 | }else{ 181 | winCount += 1; 182 | //if winCount equals word length 183 | if (winCount == charArray.length) { 184 | if(player2Btn.classList.contains('mode2')) { 185 | resultText.innerHTML = `

PLAYER 1 WINS!! PLAYER 2 LOST!!!!

The word was ${chosenWord}

`; 186 | blocker(); 187 | }else { 188 | resultText.innerHTML = `

You Win!!

The word was ${chosenWord}

`; 189 | //block all buttons 190 | blocker(); 191 | } 192 | 193 | } 194 | } 195 | } 196 | }); 197 | } 198 | 199 | //WRONG 200 | const wrongAnswer = (event, chosenWord) => { 201 | if(event.target.className === 'letters1'){ 202 | playerTurnHeaders[0].style.visibility = 'visible' 203 | playerTurnHeaders[1].style.visibility = 'hidden' 204 | count2 += 1 205 | drawMan(count2, event); 206 | //Count==6 because head,body,left arm, right arm,left leg,right leg 207 | if (count2 == 6) { 208 | resultText.innerHTML = `

PLAYER 2 LOST!! PLAYER 1 WINS!!!!!!!

The word was ${chosenWord}

`; 209 | blocker(); 210 | } 211 | }else{ 212 | playerTurnHeaders[0].style.visibility = 'hidden' 213 | playerTurnHeaders[1].style.visibility = 'visible' 214 | count += 1 215 | drawMan(count, event); 216 | //Count==6 because head,body,left arm, right arm,left leg,right leg 217 | if (count == 6) { 218 | if(player2Btn.classList.contains('mode2')) { 219 | resultText.innerHTML = `

PLAYER 1 LOSE!!!! PLAYER 2 WINS!!!!

The word was ${chosenWord}

`; 220 | blocker(); 221 | }else { 222 | resultText.innerHTML = `

You Lose!!

The word was ${chosenWord}

`; 223 | blocker(); 224 | } 225 | 226 | } 227 | } 228 | } 229 | 230 | 231 | const createLetters = (letterContainer, buttonClass, spanClasses) => { 232 | for (let i = 65; i < 91; i++) { 233 | let button = document.createElement("button"); 234 | button.classList.add(buttonClass); 235 | //[A-Z] 236 | button.innerText = String.fromCharCode(i); 237 | //character button click 238 | button.addEventListener("click", (e) => { 239 | let charArray = chosenWord.split(""); 240 | let dashes = document.getElementsByClassName(spanClasses); 241 | //if array contains clicked value replace the matched dash with letter else dram on canvas 242 | if (charArray.includes(button.innerText)) { 243 | correctAnswer(charArray, dashes, button, e) 244 | } else { 245 | //lose count 246 | wrongAnswer(e, chosenWord) 247 | } 248 | //disable clicked button 249 | button.disabled = true; 250 | }); 251 | letterContainer.append(button); 252 | } 253 | } 254 | //Initial Function (Called when page loads/user presses new game) 255 | const initializer = (userInputSection, optionsContainer, letterContainer, shouldRunAgain, buttonClass, spanClasses) => { 256 | winCount = 0; 257 | winCount2 = 0; 258 | count = 0; 259 | count2 = 0; 260 | 261 | //Initially erase all content and hide letters and new game button 262 | userInputSection.innerHTML = ""; 263 | optionsContainer.innerHTML = ""; 264 | letterContainer.classList.add("hide"); 265 | newGameContainer.classList.add("hide"); 266 | playerTurnHeaders.forEach(h4 => { 267 | h4.style.visibility = 'hidden' 268 | }) 269 | letterContainer.innerHTML = ""; 270 | 271 | //For creating letter buttons 272 | createLetters(letterContainer, buttonClass, spanClasses) 273 | 274 | displayOptions(shouldRunAgain); 275 | }; 276 | 277 | const drawForSecondContainer = (event, bodyPart) => { 278 | if(event.target.className === 'letters1'){ 279 | bodyPart.style.display = 'block' 280 | return true 281 | } 282 | return false 283 | } 284 | 285 | //Canvas 286 | const buildHangman = (event) => { 287 | const head = () => { 288 | if(drawForSecondContainer(event, hangmanHead1)) return 289 | hangmanHead.style.display = 'block' 290 | }; 291 | 292 | const body = () => { 293 | if(drawForSecondContainer(event, hangmanBody1)) return 294 | hangmanBody.style.display = 'block' 295 | }; 296 | 297 | const leftArm = () => { 298 | if(drawForSecondContainer(event, hangmanLeftArm1)) return 299 | hangmanLeftArm.style.display = 'block' 300 | }; 301 | 302 | const rightArm = () => { 303 | if(drawForSecondContainer(event, hangmanRightArm1)) return 304 | hangmanRightArm.style.display = 'block' 305 | }; 306 | 307 | const leftLeg = () => { 308 | if(drawForSecondContainer(event, hangmanLeftLeg1)) return 309 | hangmanLeftLeg.style.display = 'block' 310 | }; 311 | 312 | const rightLeg = () => { 313 | if(drawForSecondContainer(event, hangmanRightLeg1)) return 314 | hangmanRightLeg.style.display = 'block' 315 | }; 316 | 317 | return { head, body, leftArm, rightArm, leftLeg, rightLeg }; 318 | }; 319 | 320 | //draw the man 321 | const drawMan = (count, event) => { 322 | let { head, body, leftArm, rightArm, leftLeg, rightLeg } = buildHangman(event); 323 | switch (count) { 324 | case 1: 325 | head(); 326 | break; 327 | case 2: 328 | body(); 329 | break; 330 | case 3: 331 | leftArm(); 332 | break; 333 | case 4: 334 | rightArm(); 335 | break; 336 | case 5: 337 | leftLeg(); 338 | break; 339 | case 6: 340 | rightLeg(); 341 | break; 342 | default: 343 | break; 344 | } 345 | }; 346 | 347 | //New Game 348 | newGameButton.addEventListener("click",() => { 349 | initializer(userInputSection, optionsContainer, letterContainer, false, 'letters', 'dashes') 350 | initializer(userInputSection2, optionsContainer2, letterContainer2, true, 'letters1', 'dashes2') 351 | }); 352 | window.onload = initializer(userInputSection, optionsContainer, letterContainer, false, 'letters', 'dashes'); 353 | window.onload = initializer(userInputSection2, optionsContainer2, letterContainer2, true, 'letters1', 'dashes2') 354 | 355 | --------------------------------------------------------------------------------