Skip to content
Hangman game to help teach programming to beginners
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


This is a big challenge for you now but if you can understand the topics fully up until Lesson 6 and practice more, you will be able to make this game! You can work on this anytime and we can help you to think through making the game.

Hangman is a game where we try to guess a word. The word has it’s letters replaced with blanks and we guess a letter to try to fill each blank until we know the word!

hangman example

A word may contain a letter more than once, so sometimes we can fill in more than one blank by guessing a letter!

You can see a flash player version of the game here. This version gives you a certain number of guesses, if you make an incorrect guess it will draw some of the hangman (like the picture below). And you cannot guess with the same letter more than once.

For our first version, we will allow the user to keep guessing until the word is complete. We will allow the user to use the same letter more than once.

What do I need to know to complete the project?

You need to understand all the topics we have covered so far, but in particular you need to use String methods and loops from Lesson 6.

You will also need to use a StringBuilder. A StringBuilder is a class that is similar to a String, it holds text; but StringBuilder has methods for editing that a String does not have such as:

  • we can add letters to the end
  • we can replace a letter at a particular position
  • we can delete a letter at a particular position

For example, if I want to create an empty StringBuilder, and then add some letters I would do this:

        public class Example{
           public static void main(String[] args) {
               StringBuilder noText = new StringBuilder();

Will print:


How to start?

What we need is a String for our word. We need to create a copy of the String that is the same length but has all blanks (you can use a minus sign for a blank). Print this to the Output. Try to do this first.

Next, we want to ask the user to enter a letter as their guess. With this letter, we want to check our word to see if it has the same letter. The word can have the letter more than once, so, we need to continue to check our word until we have no more matches (you will need a loop). Test this with a word that has a letter more than 1 time like “sausage” (a 2 times, s 2 times). See if you can do this.

I will let you try to identify the next steps. It can be a good idea to write out the steps you’d like to do on paper, or as comments inside your program. Plan a bit before you start, and try to use methods.

Extra Features

If you want to improve the game to be more complete, we can add the following features:

  1. Make the program ignore if there is a big or small letter in your word and the guess letter.
  2. You can give the user 8 lives (whatever number you like). If a guess is correct, they do not lose a life. If they guess is wrong, they lose a life. Tell the user how many lives they have left on each turn.
  3. When the user makes an incorrect guess, you can print some ascii art to show the hangman to describe how close to the end they are! This is an example for 3 lives:

hangman example

  1. You can allow a user to enter a string that is multiple words. You must ignore any space!

  2. You can store which letters are available and print them to the output! With every turn, you can check if the user has entered that letter before. If the letter is not used, remove if as an available letter. If the letter is already used, you can tell the user and we will not count it as a guess.

  3. You can have a collection of words and select one word randomly when the user starts the game. NOTE: You will need to know how to use arrays/collections to do this! We will cover this in later lessons.

  4. You could have categories for words e.g. movie stars, beer brands. You can create a menu where the user can select a category and a random word will be selected from that group. NOTE: You will need to know how to use arrays/collections to do this! We will cover this in later lessons.

You can’t perform that action at this time.