Vous êtes sur la page 1sur 3

Model

Class HangManGame()
Private:
 String[] words - array of words to be selected from. This can be just a list of words, should be over 10 letters in
length. Don’t want to make it too easy.
 HangmanIcons object – based on the class description below
 AlphabetIcons object – based on the class description below.
 String word - the randomly selected word
 Char[] usedLetters – An array of characters representing the letters that the player has already selected.
 Int usedLetterCount – because the usedLetters array needs to be initialized at 26, the number of letters possible,
an integer needs to be included for the number of usedLetters have been added.
 Static int[100] scores - stores the scores of all games played. This isn’t going to be used, but is included for the
possibility of adding highest/lowest score later to the final screen.
 Static final int MAX_SCORE – should be set to 7.
 Static final int MIN_SCORE – should be set to 0.
Public:
 Default constructor only – runs the init() method. Very simple.
 getWord() - randomly selects a word from the word array
 Accessors for hangman and alphabet icons, space and the line icons. Also for the score and word.
 Init() - creates a new game. Creates a new hangmanIcons and alphabetIcons object, selects the random word with
the getWord() method and sets the score to 0.
 getLowestScore() - gets the lowest scores of all played games (optional, if there is time)
 getCurrentScore() - gets the score of the current game being played (optional, if there is time)
 getScores() - returns an array of all scores (optional, if there is time. Not entirely sure this will be necessary)
 bool isInWord(char letter) - checks to see if the letter is actually in the word.
 Bool letterCheck(char letter, int position) - checks for a letter match at a given position in the word.
 Int getWordLength() – returns the length of the word. Needed for the “_” icons.
 Int incrementScore() – increments the score by 1 and returns the new value of the score.
 Bool isUsedLetter(char letter) - checks if a letter is in usedLetters array.
 Bool addUsedLetter() - adds a character to the used letter array. Checks if the letter is already in the array and
returns false if it is there already. Increments the usedLetterCount also.
 Boolean isDone() – looks to see if the score has reached the MAX_SCORE or if all the letters have been found in
the word.
 Boolean isWon() – looks to see if all the letters have been found and the score is less than the MAX_SCORE.
 Boolean allLettersFound() – runs two sets of for loops to see if the letters in the usedLetters array include all
letters in the word in play.

Class HangmanIcons()
Private
 Array of icons for the phases in order
 Static final int MAX_ICONS, for the maximum number of icons
Public:
 Default constructor only – puts the icons into the array
 Icon getIcon(int num) - returns the icon in the icon array at num position. Checks invalid number. If the number is
invalid returns blank icon or space

Class AlphabetIcons()
Private:
 Array of icons for the alphabet images
 Icon Underscore - the icon for the _
 Icon space - the icon for " " (optional, this is for potentially making the game so that when the letters are
selected the are changed to spaces with no listener or action event.)
 Static String LETTERS – a string of all the letters in the alphabet uppercase. “ABCDEFG…etc.”
 Int letterNum(char letter) - takes a letter and returns the number of the letter in the aphabetIcon array. If the
char is not a letter A-Z, then it returns -1. Sets the char to an uppercase letter. (use wrapper class)
Public:
 Constructor default only - Pulls the cards and stores them into array of icons
 Icon getLetter(char letter) - takes a letter and returns an icon. Uses the letterNum() method to get the number
and then returns the icon at point x in the alphabetIcon array. Checks for valid number from the letterNum
method.
 Icon getSpace() - returns the space icon
 Icon getLine() - returns underscore icon

View
Class HangmanView()
Public:
 static final int WIDTH = 600; - window window
 static final int HEIGHT = 800; - window height
 accessors and mutators for the
Private:
 The JFrame for the window
 Panels for the top area, hangman image area, area for the random word lines, and letters to be guessed from
 An array of JLabels for the random word “_” images, alphabet images.
 Other necessary JLabels for the score, hangman image, titles, CSUMB logo, won/lost text.
 Jbutton for selecting “Play again”.

Examples:
View
Class hangmanController()

Data:

 HangmanGame object and HangmanView object to get the game going


 String Constant representing the alphabet. “ABCD…etc.”.
 constructor() – this will create the game board, and add the listener for the “play again” button.
 addListener() – the listener code for the letter icons. This should go here so that it can be added into the listener
for the button and the initial game setup without duplicating code.
 setGame() – reset the hangman image to the 0 point and reset the “_” word icons. As above, this is included
here to avoid duplication of code.

Vous aimerez peut-être aussi