COWQ2N1 – HangMan
Level 1
Create a BankLetter Class with the following attributes
Variables
char letter – the letter
boolean guessed – whether or not the letter has been guessed
boolean correctlyGuessed – whether the letter has been guessed and is in the word
Methods
Name: BankLetter
Input: char letter
Output: nothing
Action:a constructor that takes in the letter to store and calls reset
Name: reset
Input: nothing
Output: nothing
Action:sets guessed and correctlyGuessed to false
Name: getLetter
Input: nothing
Output: char letter
Action:returns the letter
Name: isGuessed
Input: nothing
Output: boolean
Action:returns whether or not the letter has been guessed
Name: isCorrectlyGuessed
Input: nothing
Output: boolean
Action:returns whether or not the letter has been correctly guessed
Name: markAsGuessed
Input: boolean isCorrect
Output: nothing
Action:sets guessed to true and correctlyGuess to isCorrect
Name: paint
Input: Graphics g, int x, int y
Output: nothing
Action:draws the letter to the screen at the indicated x, y position. If the letter has not been guessed, then it should be painted gray. If the has been guessed, then it should be either green or red depending on whether it was a correct guess. Use the following line of code to set the font before you draw it to the screen using drawString:
g.setFont(new Font("Courier New", Font.BOLD, 60));
Level 2
Create a HangMan class with the following attributes:
Variables
intnumParts – the total number of body parts that have been added to the hangman
intmaxParts – the maximum number of body parts that can be added to the hangman
Color theColor – the color of the hangman
Methods
Name: HangMan
Input: Color aColor
Output: nothing
Action:a constructor that takes in the color of the hangman, sets maxParts to 6, and calls the reset method
Name: reset
Input: nothing
Output: nothing
Action:sets numParts to 0
Name: isComplete
Input: nothing
Output: boolean
Action:returns whether or not the hangman is completely drawn. The hangman is complete once the numPartsequalsmaxParts
Name: addPart
Input: nothing
Output: nothing
Action:increments numParts by one
Name: paint
Input: Graphics g
Output: nothing
Action:draws the gallows and hangman to the screen is the upper left hand corner. The number of parts that are drawn for the hangman should be as follows 1-head, 2 body, 3-leg, 4-other leg, 5-arm, 6-other arm. The gallows should be black. The hangman should be the color stored in the class. The hangman and gallows should fit in a 300 by 300 square. To increase the line thickness to 3 use the following line of code:
((Graphics2D)g).setStroke(new BasicStroke(3));
Level 3
Create a LetterBank Class with the following attributes
Variables
BankLetter [] alphabet – the set of letters that the user can guess
Methods
Name: LetterBank
Input: String alphabet
Output: nothing
Action:a constructor that takes in a String that is storing the entire alphabet, creates an array the same size, and creates Letters at each location that correspond to the characters passed in the String.
Name: reset
Input: nothing
Output: nothing
Action:goes through and resets each Letter in alphabet
Name: isAvailable
Input: char letter
Output: boolean
Action:returns whether or not the letter is in the bank and has not been guessed
Name: markAsGuessed
Input: char letter, boolean isInPhrase
Output: boolean
Action:sets the Letter that stores the given letter to guessed, uses isInPhrase to indicate whether it was correctly guessed, and returns true. If the letter is not in the bank the it returns a false
Name: paint
Input: Graphics g, int x, int y
Output: nothing
Action:draws all the letters to the screen with x, y indicating the upper left hand corner. All the letters should be painted one after the other until the 6thone in the row has been reached at which time start over at the original x and shifted down one line. The letters and lines should have a spacing of 25.
Level 4
Create a SecretLetter Class with the following attributes
Variables
char letter – the letter
boolean guessed – whether or not the letter has been guessed
Methods
Name: SecretLetter
Input: char letter
Output: nothing
Action:a constructor that takes in the letter to store and sets guessed to false
Name: reveal
Input: nothing
Output: nothing
Action:sets guessed to true
Name: getLetter
Input: nothing
Output: char letter
Action:returns the letter
Name: isGuessed
Input: nothing
Output: boolean
Action:returns whether or not the letter has been guessed
Name: paint
Input: Graphics g, int x, int y
Output: nothing
Action:draws all the letters to the screen with x, y indicating the upper left hand corner. If the letter has not been guessed, then a black underscore should be painted instead. The color of the letters should be blue and the font should be set to size 30.
Create a SecretPhrase Class with the following attributes
Variables
SecretLetter [] phrase – an array of SecretLetters that stores the secret phrase
Methods
Name: SecretPhrase
Input: String phrase
Output: nothing
Action:a constructor that takes in a String that is storing the secret phrase, creates an array the same size, and creates SecretLetters at each location that correspond to the characters passed in the String. It then goes through and guesses each space.
Name: isInPhrase
Input: char letter
Output: boolean
Action:returns whether or not the letter is in the phrase
Name: reveal
Input: char letter
Output: nothing
Action:goes through and reveals each SecretLetter that contains the given char
Name: paint
Input: Graphics g, int x, int y
Output: nothing
Action:draws all the letters to the screen with x, y indicating the upper left hand corner. All the letters should be painted one after the other until the 25th one in the row has been reached.
Level 5
Add the following method to the SecretPhrase Class
Name: isDone
Input: nothing
Output: boolean
Action:returns whether or not every letter in the secret phrase has been guessed
Program the following methods of the HangManGame Class:
Name: play
Input: char letter
Output: nothing
Action:takes in the given letter and checks if it is available in the alphabet bank. If it available, then it checks if it is in the phrase and reveals it if it is. It should then mark that letter as guessed in the bank and pass in whether it was in the phrase or not. If the letter was available and not in the phrase it should also add a part to the hangman frank. Afterwards it should check the isDone method of the secretPhraseand whether frank is complete to see ifgameOvershould be set to true.
Name: reset
Input: String phrase
Output: nothing
Action:resets the hangman and alphabet bank, sets gameOver to false and calls the setPhrase method.
Name: paint
Input: Graphics g
Output: nothing
Action:modify the paint method to draw something appropriate once the game ends. The user should be able to tell if they won.