import java.awt.*; /** * Class to display the hangman game info for the game Hangman. * It draws a stick figure on a gallows and the right and wrong * guesses. It also tells the user when she wins or loses. * @author Barb Ericson * Gopyright 2005 Georgia Tech */ public class HangmanDisplay { ///////////////// fields /////////////////////////// /** the picture to draw on */ private Picture picture = new Picture(330,330); /** the graphics context to draw with */ private Graphics graphics = picture.getGraphics(); //////////// constructors ///////////////////////// /** * No argument constructor * just draw the set up and show the picture */ public HangmanDisplay() { this.drawGallows(); this.drawCorrectArea(); this.drawIncorrectArea(); picture.show(); } ////////////// methods ///////////////////////////// /** * Method to draw the gallows */ public void drawGallows() { graphics.setColor(Color.BLACK); graphics.drawLine(20,220,220,220); graphics.drawLine(170,220,170,20); graphics.drawLine(120,20,170,20); graphics.drawLine(130,20,130,50); } /** * Method to draw the underlines for the correct guess */ public void drawCorrectArea() { graphics.drawString("The word is:",20,250); graphics.drawLine(90,250,100,250); graphics.drawLine(105,250,115,250); graphics.drawLine(120,250, 130,250); graphics.drawLine(135,250,145,250); } /** * Method to draw the right guesses array */ public void drawRightGuess(char[] rightGuessArray) { graphics.drawString(String.valueOf(rightGuessArray[0]),93,240); graphics.drawString(String.valueOf(rightGuessArray[1]),108,240); graphics.drawString(String.valueOf(rightGuessArray[2]),123,240); graphics.drawString(String.valueOf(rightGuessArray[3]),138,240); picture.repaint(); } /** * Method to draw the string for the inncorect guesses */ public void drawIncorrectArea() { graphics.drawString("Wrong Guesses:",20,300); } /** * Method to draw the wrong guess string */ public void drawWrongGuess(String wrongGuesses) { graphics.drawString(wrongGuesses,120,300); picture.repaint(); } /** * Method to draw the head */ public void drawHead() { graphics.drawOval(115,50,30,30); picture.repaint(); } /** * Method to draw the body */ public void drawBody() { graphics.drawLine(130,80,130,150); picture.repaint(); } /** * Method to draw the left arm */ public void drawLeftArm() { graphics.drawLine(130,120,120,85); picture.repaint(); } /** * Method to draw the right arm */ public void drawRightArm() { graphics.drawLine(130,120,140,85); picture.repaint(); } /** * Method to draw the left leg */ public void drawLeftLeg() { graphics.drawLine(130,150,120,195); picture.repaint(); } /** * Method to draw the right leg */ public void drawRightLeg() { graphics.drawLine(130,150,140,195); picture.repaint(); } public void showLost() { graphics.drawString("You Lost!",5,20); picture.repaint(); } public void showWon() { graphics.drawString("You Won!",5,20); picture.repaint(); } // main for testing public static void main(String[] args) { HangmanDisplay display = new HangmanDisplay(); display.drawHead(); display.drawBody(); display.drawLeftArm(); display.drawRightArm(); display.drawLeftLeg(); display.drawRightLeg(); } }