HangmanGame

screenshot of hangman game

Project overview

The Hangman game is a web-based application I developed as part of a challenge in "The Modern React Bootcamp" by Colt Steele on Udemy. The challenge provided only the functionality specifications and an image of the hangman, leaving the implementation details up to the developer. Guided by the course but opting for a modern approach, I chose to utilize React hooks and functional components instead of the traditional class components.
The game starts with a start button that generates a random word for players to guess. Players use alphabet buttons to guess the word. When a letter is selected, the game either uncovers the correctly guessed letters within the word or updates the Hangman image to reflect the wrong guess. Six wrong guesses result in revealing the hangman and the word in red, accompanied by a loss message. Correctly guessing the word highlights it in green and displays a win message. After completion, players can reset and play again with a simple click.

Technologies used

Key features

When the player clicks the start button, a word is randomly chosen for them to guess. start page mobile view start page desktop view Players guess the word using dedicated alphabet buttons. game page with alphabet buttons and underscores to guess the word Once a button is selected, it becomes disabled and is crossed out in red.
Letters guessed correctly are immediately revealed in their respective positions.
Wrong guesses incrementally reveal parts of the hangman drawing. selected buttons crossed out in red, if incorrect - part of the hangman drawing revealed, if correct - letters instead of underscores After six incorrect guesses, the hangman is fully revealed, and the hidden word is shown in red, accompanied by a matching loss message. fully revealed hangman, word shown in red with a matching message A successfully guessed word is highlighted in green, followed by a win message.
Players can start a new game by clicking the "Play again" button, which generates a new word and resets the game. word shown in green with a matching message

Challenges and solutions

During the development process, I encountered several challenges. These included the dynamic generation of a word for each game, the management of the game's multiple states, ensuring proper interaction of the alphabet buttons, presenting the word dynamically with real-time feedback, and preserving a consistent style and responsiveness across components.

  1. To present a new challenge with every game iteration, I employed the 'getRandomWord' function from helperFunctions. This function extracts a random word from the words.json file. Using the 'setRandomWord' function, it is then set as the main word for the game.
  2. To handle states like 'startGame', 'gameOver', and 'incorrectlyGuessed', I used React's useState. Additionally, the useEffect hook helped monitor and respond to gameplay changes.
  3. To make sure that once a letter was selected, it couldn't be chosen again and to show clear feedback for selected letters, the 'AlphabetButtons' component checked the 'guessedLetters' list to see if a letter was already selected. The 'getButtonClass' function changed the button's appearance, and the disabled feature made sure selected letters couldn't be clicked again.
  4. A main game feature was revealing the secret word bit by bit as players made guesses. Using the 'WordDisplay' component, each letter was either shown (if guessed right) or hidden with a placeholder. How the word finally appeared depended on the 'revealWord' and 'isCorrect' settings, and 'getLetterClass' helped style it based on the game's result.
  5. I used modular CSS to organize the styles, putting them into specific files like 'Hangman.css' and 'App.css'. By using specific class names for each part, I made sure everything looked right and left room for future improvements.

Learning outcomes

Through this project, I have deepened my understanding and sharpened various existing skills:

Project source code and website URL: