@@ -12,11 +12,12 @@ def __init__(self):
12
12
pygame .display .set_caption ("Snake" )
13
13
self .clock = pygame .time .Clock ()
14
14
15
- def update_ui (self , snake , food , score ):
15
+ def update_ui (self , snake , food , score , high_score ):
16
16
self .window .fill (RgbColors .BLACK )
17
17
self .draw_snake (snake )
18
18
self .draw_food (food )
19
19
self .draw_score (score )
20
+ self .render_high_score (high_score )
20
21
pygame .display .flip ()
21
22
22
23
def draw_snake (self , snake ):
@@ -37,6 +38,7 @@ def draw_food(self, food):
37
38
)
38
39
39
40
def draw_score (self , score ):
41
+ self .font = pygame .font .Font (None , 25 )
40
42
score_display = self .font .render (f"Score: { score } " , True , RgbColors .WHITE )
41
43
self .window .blit (score_display , [0 , 0 ]) # score in top left window corner
42
44
@@ -57,3 +59,17 @@ def render_play_again(self):
57
59
display_box = play_again_display .get_rect (center = (self .width // 2 , self .height // 2 ))
58
60
self .window .blit (play_again_display , display_box )
59
61
pygame .display .flip ()
62
+
63
+ def render_high_score (self , high_score ):
64
+ high_score_display = self .font .render (f"High Score: { high_score } " , True , RgbColors .WHITE )
65
+ self .window .blit (high_score_display , [self .width - high_score_display .get_width (), 0 ])
66
+
67
+ def render_new_high_score (self , new_high_score ):
68
+ new_high_score_display = self .font .render (f"New High Score: { new_high_score } " , True , RgbColors .WHITE )
69
+ text_width = new_high_score_display .get_width ()
70
+ text_height = new_high_score_display .get_height ()
71
+ text_x = (self .width - text_width ) // 2
72
+ text_y = (self .height // 3 ) - (text_height // 2 )
73
+ self .window .blit (new_high_score_display ,
74
+ [text_x , text_y ])
75
+ pygame .display .flip ()
0 commit comments