diff --git a/src/Q4.java b/src/Q4.java index d1883752558ed77234024b0f41d29753dcf8452e..7d8d92033d44f80adcc213f8bd6878c5f70cf3c6 100644 --- a/src/Q4.java +++ b/src/Q4.java @@ -1,6 +1,8 @@ import bagel.*; import bagel.util.Point; +import java.text.DecimalFormat; + /** * Xulin Yang, 904904 * @@ -44,6 +46,14 @@ public class Q4 extends AbstractGame { // add STEP_SIZE * xd to x1; // add STEP_SIZE * yd to y1; + // (c) After each movement, print to the console the position of the player in the form of + // x-coordinate, y-coordinate + //Keep 2 decimal digits for both x-coordinate and y-coordinate. To do so, you can use the format + //method in java.text.DecimalFormat class, e.g., define a static attribute + private static DecimalFormat df = new DecimalFormat("0.00"); + //and use it as + // System.out.println(df.format(playerX) +"," + df.format(playerY)); + /** * calculate the direction for the player based on the input point w.r.t. player's location * @param Dest destination for the player to move to @@ -71,6 +81,8 @@ public class Q4 extends AbstractGame { // (b) playerX += STEP_SIZE * this.playerDirectionX; playerY += STEP_SIZE * this.playerDirectionY; + // (c) + System.out.println(df.format(playerX) + "," + df.format(playerY)); } if (new Point(playerX, playerY).distanceTo(BALL_POSITION) <= SCORE_DISTANCE) {