Skip to content
Snippets Groups Projects
Commit c7271ec3 authored by yangxvlin's avatar yangxvlin
Browse files

finish Q4c

parent ff9bafec
No related branches found
No related tags found
No related merge requests found
import bagel.*; import bagel.*;
import bagel.util.Point; import bagel.util.Point;
import java.text.DecimalFormat;
/** /**
* Xulin Yang, 904904 * Xulin Yang, 904904
* *
...@@ -44,6 +46,14 @@ public class Q4 extends AbstractGame { ...@@ -44,6 +46,14 @@ public class Q4 extends AbstractGame {
// add STEP_SIZE * xd to x1; // add STEP_SIZE * xd to x1;
// add STEP_SIZE * yd to y1; // 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 * 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 * @param Dest destination for the player to move to
...@@ -71,6 +81,8 @@ public class Q4 extends AbstractGame { ...@@ -71,6 +81,8 @@ public class Q4 extends AbstractGame {
// (b) // (b)
playerX += STEP_SIZE * this.playerDirectionX; playerX += STEP_SIZE * this.playerDirectionX;
playerY += STEP_SIZE * this.playerDirectionY; 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) { if (new Point(playerX, playerY).distanceTo(BALL_POSITION) <= SCORE_DISTANCE) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment