@@ -47,19 +47,19 @@ def increment_score():
47
47
score_var .set (f"Score: { score } " )
48
48
49
49
def render_point (point , color ):
50
- coord_x , coord_y = point .x * TILE_WIDTH , point .y * TILE_WIDTH
51
- canvas .create_rectangle (coord_x , coord_y ,
52
- coord_x + TILE_WIDTH ,
53
- coord_y + TILE_WIDTH ,
54
- fill = color ,
55
- outline = 'white' )
50
+ coord_x , coord_y = point .x * TILE_WIDTH , point .y * TILE_WIDTH
51
+ canvas .create_rectangle (coord_x , coord_y ,
52
+ coord_x + TILE_WIDTH ,
53
+ coord_y + TILE_WIDTH ,
54
+ fill = color ,
55
+ outline = 'white' )
56
56
57
57
def render_food (food ):
58
58
render_point (food , 'red' )
59
59
60
60
def render_snake (snake ):
61
61
render_point (snake [- 1 ], 'blue' )
62
- for point in snake [: - 1 ] :
62
+ for point in snake . tail :
63
63
render_point (point , 'black' )
64
64
65
65
def game_loop ():
@@ -72,16 +72,21 @@ def game_loop():
72
72
else :
73
73
snake .move ()
74
74
75
- if snake [- 1 ] in snake [:- 1 ]:
76
- canvas .create_text (SCREEN_WIDTH / 2 , SCREEN_WIDTH / 2 ,
77
- fill = 'black' ,font = 'courier 80 bold' ,
78
- text = GAME_OVER_MSG )
75
+ if snake [- 1 ] in snake .tail :
76
+ text = canvas .create_text (SCREEN_WIDTH / 2 , SCREEN_WIDTH / 2 ,
77
+ fill = 'black' ,font = 'courier 80 bold' ,
78
+ text = GAME_OVER_MSG )
79
+ text_frame = canvas .create_rectangle (canvas .bbox (text ),
80
+ fill = 'white' ,
81
+ outline = 'white' )
82
+ canvas .tag_lower (text_frame , text )
83
+
79
84
else :
80
- canvas .delete ('all' )
81
- render_food (food )
82
- render_snake (snake )
83
- frame_updated = False
84
- root .after (FRAME_RATE , game_loop )
85
+ canvas .delete ('all' )
86
+ render_food (food )
87
+ render_snake (snake )
88
+ frame_updated = False
89
+ root .after (FRAME_RATE , game_loop )
85
90
86
91
def change_direction (event ):
87
92
global frame_updated
0 commit comments