Skip to content

joshjavier/hangman-game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Frontend Mentor - Hangman game solution

This is a solution to the Hangman game challenge on Frontend Mentor. Frontend Mentor challenges help you improve your coding skills by building realistic projects.

Table of contents

Overview

The challenge

Users should be able to:

  • Learn how to play Hangman from the main menu.
  • Start a game and choose a category.
  • Play Hangman with a random word selected from that category.
  • See their current health decrease based on incorrect letter guesses.
  • Win the game if they complete the whole word.
  • Lose the game if they make eight wrong guesses.
  • Pause the game and choose to continue, pick a new category, or quit.
  • View the optimal layout for the interface depending on their device's screen size.
  • See hover and focus states for all interactive elements on the page.
  • Navigate the entire game only using their keyboard.

Screenshot

Links

My process

Built with

What I learned

This is by far the prettiest game I've developed. Here are some of the things I've learned along the way:

  • how to use Motion's AnimatePresence to add exit animations to components
  • thinking in terms of "game UX" (vs. general website UX)
  • using the finite state machine pattern for the game logic
  • implementing a conditional polyfill for Set.prototype.isSubsetOf
  • vibe coding pair coding with ChatGPT

Regarding that last point, I'm generally against the idea of letting AI do your coding for you, but it's actually pretty helpful for generating initial ideas and building off of those.

In my case, I didn't know where to start coding the game logic, so I asked ChatGPT about the best way to organize the logic and app state for a hangman game. It gave me a general folder structure with a useHangman custom hook - good enough. But then I remembered reading about state machines and thought it might be a good fit since the game moves through explicitly defined states (main_menucategory_pickplayinggame_over). And so this back and forth with ChatGPT helped me refine my idea into something that I could easily implement in code.

Asking ChatGPT if implementing the game logic with finite state machines is a good idea.

For the list of words, I initially planned to implement an API that returns a random word based on a given category. But I decided not to do it when I realized that one could simply check the Network tab in the browser devtools to cheat. 😈

Useful resources

Author

Acknowledgments

I got the sound effects which are all licensed under CC0 1.0 from Freesound:

I'd also like to give some credit to Hangaroo for inspiring the sound and animation choices I've made for this project. I used to play it a lot when I was a kid, and it's still what comes to mind when I think of a good hangman game.

About

Hangman game built with React for a Frontend Mentor challenge

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published