0.2.2 #14
@@ -26,6 +26,9 @@ class Colors(Enum):
|
|||||||
Blue = (0, 0, 255)
|
Blue = (0, 0, 255)
|
||||||
Cyan = (0, 255, 255)
|
Cyan = (0, 255, 255)
|
||||||
Magenta = (255, 0, 255)
|
Magenta = (255, 0, 255)
|
||||||
|
WHITE = (255, 255, 255)
|
||||||
|
RED = (255, 0, 0)
|
||||||
|
# add others as needed
|
||||||
|
|
||||||
class GhostColor(Enum):
|
class GhostColor(Enum):
|
||||||
BLINKY = (255, 0, 0)
|
BLINKY = (255, 0, 0)
|
||||||
|
@@ -1,18 +1,42 @@
|
|||||||
import pygame
|
import pygame
|
||||||
|
import os
|
||||||
|
from enums import Color
|
||||||
|
|
||||||
class Scoreboard:
|
class Scoreboard:
|
||||||
def __init__(self, font_size=24):
|
def __init__(self, font_size=24, highscore_file="highscore.txt"):
|
||||||
self.score = 0
|
self.score = 0
|
||||||
|
self.highscore_file = highscore_file
|
||||||
|
self.highscore = self.load_highscore()
|
||||||
|
|
||||||
self.font = pygame.font.Font(None, font_size)
|
self.font = pygame.font.Font(None, font_size)
|
||||||
self.color = (255, 255, 255)
|
self.color = Color.WHITE.value
|
||||||
self.position = (10, 10)
|
self.score_pos = (10, 10)
|
||||||
|
self.highscore_pos = (10, 40)
|
||||||
|
|
||||||
|
def load_highscore(self):
|
||||||
|
if os.path.exists(self.highscore_file):
|
||||||
|
with open(self.highscore_file, 'r') as file:
|
||||||
|
try:
|
||||||
|
return int(file.read())
|
||||||
|
except ValueError:
|
||||||
|
return 0
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def save_highscore(self):
|
||||||
|
with open(self.highscore_file, 'w') as file:
|
||||||
|
file.write(str(self.highscore))
|
||||||
|
|
||||||
def add_points(self, points):
|
def add_points(self, points):
|
||||||
self.score += points
|
self.score += points
|
||||||
|
if self.score > self.highscore:
|
||||||
|
self.highscore = self.score
|
||||||
|
self.save_highscore()
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
self.score = 0
|
self.score = 0
|
||||||
|
|
||||||
def draw(self, screen):
|
def draw(self, screen):
|
||||||
score_text = self.font.render(f"Score: {self.score}", True, self.color)
|
score_text = self.font.render(f"Score: {self.score}", True, self.color)
|
||||||
screen.blit(score_text, self.position)
|
highscore_text = self.font.render(f"High Score: {self.highscore}", True, self.color)
|
||||||
|
screen.blit(score_text, self.score_pos)
|
||||||
|
screen.blit(highscore_text, self.highscore_pos)
|
Reference in New Issue
Block a user