
/*
 * File: HangmanCanvas.java
 * ------------------------
 * This file keeps track of the Hangman display.
 */

import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.shape.Line;
import javafx.stage.Stage;

public class HangmanCanvas {
    /* Constants for the simple version of the picture (in pixels) */
    private static final int SCAFFOLD_HEIGHT = 360;
    private static final int BEAM_LENGTH = 144;
    private static final int ROPE_LENGTH = 18;
    private static final int HEAD_RADIUS = 36;
    private static final int BODY_LENGTH = 144;
    private static final int ARM_OFFSET_FROM_HEAD = 28;
    private static final int UPPER_ARM_LENGTH = 72;
    private static final int LOWER_ARM_LENGTH = 44;
    private static final int HIP_WIDTH = 36;
    private static final int LEG_LENGTH = 108;
    private static final int FOOT_LENGTH = 28;

    private static final int CANVAS_HEIGHT = 800;
    private static final int CANVAS_WIDTH = 500;

    private Group rootGroup;

    public HangmanCanvas(Stage primaryStage) {
        rootGroup = new Group();

        Canvas canvas = new Canvas(CANVAS_WIDTH, CANVAS_HEIGHT);
        rootGroup.getChildren().add(canvas);

        primaryStage.setScene(new Scene(rootGroup));
        primaryStage.show();
    }

    /** Resets the display so that only the scaffold appears */
    public void reset() {
        drawScaffold();
    }

    /**
     * Updates the word on the screen to correspond to the current state of the
     * game. The argument string shows what letters have been guessed so far;
     * unguessed letters are indicated by hyphens.
     */
    public void displayWord(String word) {
        /* You fill this in */
    }

    /**
     * Updates the display to correspond to an incorrect guess by the user.
     * Calling this method causes the next body part to appear on the scaffold
     * and adds the letter to the list of incorrect guesses that appears at the
     * bottom of the window.
     */
    public void noteIncorrectGuess(char letter) {
        /* You fill this in */
    }

    private void drawScaffold() {
        drawVerticalBeam();
        drawHorizontalBeam();
        drawRope();
    }

    private void drawVerticalBeam() {
        double startX = CANVAS_WIDTH / 2 - BEAM_LENGTH;
        double endX = startX;
        double startY = (CANVAS_HEIGHT - SCAFFOLD_HEIGHT) * 1 / 3;
        double endY = startY + SCAFFOLD_HEIGHT;

        Line verticalBeam = new Line(startX, startY, endX, endY);

        rootGroup.getChildren().add(verticalBeam);
    }

    private void drawHorizontalBeam() {
        double startX = CANVAS_WIDTH / 2 - BEAM_LENGTH;
        double endX = startX + BEAM_LENGTH;
        double startY = (CANVAS_HEIGHT - SCAFFOLD_HEIGHT) * 1 / 3;
        double endY = startY;

        Line horizontalBeam = new Line(startX, startY, endX, endY);

        rootGroup.getChildren().add(horizontalBeam);
    }

    private void drawRope() {
        double startX = CANVAS_WIDTH / 2;
        double endX = startX;
        double startY = (CANVAS_HEIGHT - SCAFFOLD_HEIGHT) * 1 / 3;
        double endY = startY + ROPE_LENGTH;

        Line rope = new Line(startX, startY, endX, endY);

        rootGroup.getChildren().add(rope);
    }
}

@@ -107,16 +107,48 @@
 y.%0A */%0A%0A
+import javafx.geometry.Point2D;%0A
 import j
@@ -2181,75 +2181,181 @@
     
-drawVerticalBeam();%0A        drawHorizontalBeam();%0A        drawRope(
+Point2D verticalBeamEndPoint = drawVerticalBeam();%0A        Point2D horizontalBeamEndPoint = drawHorizontalBeam(verticalBeamEndPoint);%0A        drawRope(horizontalBeamEndPoint
 );%0A 
@@ -2368,28 +2368,31 @@
     private 
-void
+Point2D
  drawVertica
@@ -2544,32 +2544,50 @@
 _HEIGHT) * 1 / 3
+ + SCAFFOLD_HEIGHT
 ;%0A        double
@@ -2601,17 +2601,17 @@
  startY 
-+
+-
  SCAFFOL
@@ -2730,32 +2730,73 @@
 d(verticalBeam);
+%0A%0A        return new Point2D(endX, endY);
 %0A    %7D%0A%0A    priv
@@ -2795,28 +2795,31 @@
     private 
-void
+Point2D
  drawHorizon
@@ -2822,24 +2822,42 @@
 izontalBeam(
+Point2D startPoint
 ) %7B%0A        
@@ -2876,38 +2876,25 @@
 X = 
-CANVAS_WIDTH / 2 - BEAM_LENGTH
+startPoint.getX()
 ;%0A  
@@ -2963,49 +2963,25 @@
 Y = 
-(CANVAS_HEIGHT - SCAFFOLD_HEIGHT) * 1 / 3
+startPoint.getY()
 ;%0A  
@@ -3130,16 +3130,57 @@
 alBeam);
+%0A%0A        return new Point2D(endX, endY);
 %0A    %7D%0A%0A
@@ -3187,28 +3187,31 @@
     private 
-void
+Point2D
  drawRope() 
@@ -3208,16 +3208,34 @@
 rawRope(
+Point2D startPoint
 ) %7B%0A    
@@ -3254,32 +3254,33 @@
 tartX = 
-CANVAS_WIDTH / 2
+startPoint.getX()
 ;%0A      
@@ -3331,49 +3331,25 @@
 Y = 
-(CANVAS_HEIGHT - SCAFFOLD_HEIGHT) * 1 / 3
+startPoint.getY()
 ;%0A  
@@ -3492,16 +3492,57 @@
 d(rope);
+%0A%0A        return new Point2D(endX, endY);
 %0A    %7D%0A%7D

Use end points for scaffold components as start point for next component for more flexibility