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

finish Q5c

parent 1d0708a2
Branches
No related tags found
No related merge requests found
......@@ -45,6 +45,10 @@ public class Q5 extends AbstractGame {
// (b) When the player is within 20 pixels of the ball, the ball should move to another random position.
// (c) Keep track of the player's score, which starts at 0 and increases by 1 every time the player catches
// the ball. Draw this score (using Font) at the top-left of the window.
private int score = 0;
public static void main(String[] args) {
new Q5().run();
}
......@@ -66,7 +70,12 @@ public class Q5 extends AbstractGame {
// (b)
if (new Point(playerX, playerY).distanceTo(ball.getPosition()) <= SCORE_DISTANCE) {
ball.resetPosition();
// (c)
score++;
}
// (c)
font.drawString("Score: " + score, FONT_POSITION.x, FONT_POSITION.y);
}
playerImage.draw(playerX, playerY);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment