-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscoreboard.py
34 lines (27 loc) · 1.06 KB
/
scoreboard.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from turtle import Turtle
class Scoreboard(Turtle):
"""Tracks and Displays the Score for Both Players"""
def __init__(self):
super().__init__()
self.color("White")
self.penup()
self.hideturtle()
self.l_score = 0
self.r_score = 0
def scoreboard(self):
"""Displays the current score on the screen"""
self.clear()
# Display left score
self.goto(-100, 220) # Adjust offset for better positioning
self.write(self.l_score, align="center", font=("courier", 50, "normal"))
# Display right score
self.goto(100, 220) # Adjust offset for better positioning
self.write(self.r_score, align="center", font=("courier", 50, "normal"))
def update_l(self):
"""Updates the left player's score and displays the scoreboard"""
self.l_score += 1
self.scoreboard()
def update_r(self):
"""Updates the right player's score and displays the scoreboard"""
self.r_score += 1
self.scoreboard()