Skip to content

Commit 889e2fc

Browse files
authored
Update snake.py
1 parent 21935c6 commit 889e2fc

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

SnakeGame/snake.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,8 @@ def win_focus():
100100
# Create a list of all possible locations
101101
s = list(range(0, BOARD_SIZE ** 2))
102102
# Delete cells that are part of the snake
103-
try:
104-
for part in snake:
105-
s.remove(part.x * BOARD_SIZE + part.y)
106-
except:
107-
pass
103+
for part in snake:
104+
s.remove(part.x * BOARD_SIZE + part.y)
108105

109106
# Randomly pick from one of the remaining cells
110107
a = choice(s)
@@ -151,14 +148,16 @@ def win_focus():
151148

152149
if quit:
153150
break
154-
151+
152+
# The snake grows graduallly over multiple frames
153+
if grow > 0:
154+
snake.append(SnakePart(snake[-1], subx, suby))
155+
grow -= 1
156+
155157
# Grows the snake when it eats an apple
156158
if applex == head.x and appley == head.y:
157159
subx = snake[-1].x
158160
suby = snake[-1].y
159161
eaten = True
160162
grow += GROWTH
161-
# The snake grows graduallly over multiple frames
162-
if grow > 0:
163-
snake.append(SnakePart(snake[-1], subx, suby))
164-
grow -= 1
163+

0 commit comments

Comments
 (0)