HangMan

Overview

Create an array list with 20 words.
Randomly determine the word and print _ for each letter.
Allow the user to guess a letter.
Display the correct letter if it exist.
Display part of an image if incorrect.
Determine if the player won or lost in the allowed number of guesses.
If they lost display the correct word.

 

 

Check out this Layout Guide

https://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html

 

 

In the Java Main Class

Create your panels, buttons, labels and set your images.
Note: It is easier if each image has the parts of the hangman and the gallows.

 

 

Template for Main Class

This is a template to follow. It is just a guide and does not give you everything required.


 

 

 

In the Java Event

Declare a String array to hold your 20 words.
Generate a Random number to determine the word.
Determine the Length of the word, create a string or string array of dashes and using a loop print out the dashes.
Get the guessed letter and find the index of it in the word. Note: -1 will be returned if the letter is not present.
Replace the dash at index with the letter.
Repeat until the index is = -1

 

 

HangMan Event Template

Button Check

Play Method

 

Guessing Method

 

This is one way to check

Note: I used *2 and +2 because I put spaces between my dashes

 

You are on your own for the rest!!!!!