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

finish Q3c

parent 0856194a
No related branches found
No related tags found
No related merge requests found
...@@ -30,6 +30,11 @@ public class Q3 extends AbstractGame { ...@@ -30,6 +30,11 @@ public class Q3 extends AbstractGame {
private double playerX = PLAYER_POSITION.x; private double playerX = PLAYER_POSITION.x;
private double playerY = PLAYER_POSITION.y; private double playerY = PLAYER_POSITION.y;
// (c) If the player comes within 20 pixels of the ball, we say the player catches the ball and you should
// print to the console "Great job!". Remember, the Euclidean distance between points (x1; y1) and
// (x2; y2) is given by: d_12 = Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2))
private static final double SCORE_DISTANCE = 20;
public static void main(String[] args) { public static void main(String[] args) {
new Q3().run(); new Q3().run();
} }
...@@ -50,6 +55,11 @@ public class Q3 extends AbstractGame { ...@@ -50,6 +55,11 @@ public class Q3 extends AbstractGame {
playerY += STEP_SIZE; playerY += STEP_SIZE;
} }
// (d)
if (new Point(playerX, playerY).distanceTo(BALL_POSITION) <= SCORE_DISTANCE) {
System.out.println("Great job!");
}
playerImage.draw(playerX, playerY); playerImage.draw(playerX, playerY);
ballImage.draw(BALL_POSITION.x, BALL_POSITION.y); ballImage.draw(BALL_POSITION.x, BALL_POSITION.y);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment