From c7271ec33073228c8772935c7d30ba8524b08960 Mon Sep 17 00:00:00 2001
From: yangxvlin <1768528843@qq.com>
Date: Wed, 31 Mar 2021 22:59:31 +1100
Subject: [PATCH] finish Q4c

---
 src/Q4.java | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/Q4.java b/src/Q4.java
index d188375..7d8d920 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) {
-- 
GitLab