import java.awt.*; import java.awt.event.*; public class Gallows extends Frame { int wrongGuesses; // number of wrong guesses String lettersUsed, // letters used by the player so far partialWord; // partially-guessed phrase, filled // with '-' characters where letters are // still missing and ' ' characters to int size; // show breaks between words // Open a graphics window and initialize the game's variables public Gallows (int s, int l) { setTitle("The Gallows"); setSize(s, s); setLocation(l,10); setVisible(true); size = s; } public void paint(Graphics g) { // This array identifies pixel locations inside the window that are relative to // the size of the window. For example, if size=300, then p[1]=30, p[2]=60, etc. // This allows the gallows and other information in the window to grow as the // window itself grows. int[] p = {0, size/10, 2*size/10, 3*size/10, 4*size/10, 5*size/10, 6*size/10, 7*size/10, 8*size/10, 9*size/10, 95*size/100}; // draw the gallows g.drawLine(p[1], p[8], p[4], p[8]); // bottom of gallows g.drawLine(p[2], p[1], p[2], p[8]); // vertical post g.drawLine(p[2], p[1], p[6], p[1]); // top bar g.drawLine(p[6], p[1], p[6], p[2]); // rope // draw head, torso, arms, legs, depending on the number of wrongGuesses // display the partially-guessed secret word g.drawString("Secret phrase: " + partialWord, p[1], p[9]); // display all the letters used so far g.drawString("Letters guessed so far: " + lettersUsed, p[1], p[10]); } public void showGallows (String pw, int wg, String lu) { partialWord = pw; wrongGuesses = wg; lettersUsed = lu; repaint(); } }