From 23b5a04dc80839102949937383c8ae6743714d85 Mon Sep 17 00:00:00 2001
From: yangxvlin <1768528843@qq.com>
Date: Wed, 31 Mar 2021 23:04:57 +1100
Subject: [PATCH] finish Q5c

---
 src/Q5.java | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/src/Q5.java b/src/Q5.java
index f9942f9..bee9bc6 100644
--- a/src/Q5.java
+++ b/src/Q5.java
@@ -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);
-- 
GitLab