@@ -14,7 +14,12 @@ def __init__(self):
1414
1515 def update_ui (self , snake , food , score ):
1616 self .window .fill (RgbColors .BLACK )
17- # Draw snake
17+ self .draw_snake (snake )
18+ self .draw_food (food )
19+ self .draw_score (score )
20+ pygame .display .flip ()
21+
22+ def draw_snake (self , snake ):
1823 for block in snake .blocks :
1924 pygame .draw .rect (
2025 self .window , RgbColors .BLUE1 ,
@@ -23,13 +28,32 @@ def update_ui(self, snake, food, score):
2328 pygame .draw .rect (
2429 self .window , RgbColors .BLUE2 , pygame .Rect (block .x + 4 , block .y + 4 , 12 , 12 )
2530 )
26- # Draw food
31+
32+ def draw_food (self , food ):
2733 pygame .draw .rect (
2834 self .window ,
2935 RgbColors .RED ,
3036 pygame .Rect (food .x , food .y , GameSettings .BLOCK_SIZE , GameSettings .BLOCK_SIZE ),
3137 )
32- # Draw score
38+
39+ def draw_score (self , score ):
3340 score_display = self .font .render (f"Score: { score } " , True , RgbColors .WHITE )
34- self .window .blit (score_display , [0 , 0 ]) # score in top left corner of window
41+ self .window .blit (score_display , [0 , 0 ]) # score in top left window corner
42+
43+ def render_game_over (self ):
44+ self .font = pygame .font .Font (None , 48 )
45+ game_over_display = self .font .render ("GAME OVER" , True , RgbColors .WHITE )
46+ text_width = game_over_display .get_width ()
47+ text_height = game_over_display .get_height ()
48+ text_x = (self .width - text_width ) // 2
49+ text_y = (self .height // 4 ) - (text_height // 2 )
50+ self .window .blit (game_over_display ,
51+ [text_x , text_y ])
52+ pygame .display .flip ()
53+
54+ def render_play_again (self ):
55+ self .font = pygame .font .Font (None , 32 )
56+ play_again_display = self .font .render ("Play again? (Y/N)" , True , RgbColors .WHITE )
57+ display_box = play_again_display .get_rect (center = (self .width // 2 , self .height // 2 ))
58+ self .window .blit (play_again_display , display_box )
3559 pygame .display .flip ()
0 commit comments