@@ -12,11 +12,12 @@ def __init__(self):
1212 pygame .display .set_caption ("Snake" )
1313 self .clock = pygame .time .Clock ()
1414
15- def update_ui (self , snake , food , score ):
15+ def update_ui (self , snake , food , score , high_score ):
1616 self .window .fill (RgbColors .BLACK )
1717 self .draw_snake (snake )
1818 self .draw_food (food )
1919 self .draw_score (score )
20+ self .render_high_score (high_score )
2021 pygame .display .flip ()
2122
2223 def draw_snake (self , snake ):
@@ -37,6 +38,7 @@ def draw_food(self, food):
3738 )
3839
3940 def draw_score (self , score ):
41+ self .font = pygame .font .Font (None , 25 )
4042 score_display = self .font .render (f"Score: { score } " , True , RgbColors .WHITE )
4143 self .window .blit (score_display , [0 , 0 ]) # score in top left window corner
4244
@@ -57,3 +59,17 @@ def render_play_again(self):
5759 display_box = play_again_display .get_rect (center = (self .width // 2 , self .height // 2 ))
5860 self .window .blit (play_again_display , display_box )
5961 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