Skip to content

ledmatrix_control: Fix snake #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions ledmatrix_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,15 +800,15 @@ def snake_embedded_keyscan():
send_command(dev, CommandVals.GameControl, [key_arg])


def game_over():
def game_over(dev):
global body
while True:
show_string('GAME ')
show_string(dev, 'GAME ')
time.sleep(0.75)
show_string('OVER!')
show_string(dev, 'OVER!')
time.sleep(0.75)
score = len(body)
show_string(f'{score:>3} P')
show_string(dev, f'{score:>3} P')
time.sleep(0.75)


Expand Down Expand Up @@ -850,7 +850,7 @@ def snake_embedded():
snake_embedded_keyscan()


def snake():
def snake(dev):
from getkey import keys
global direction
global body
Expand Down Expand Up @@ -892,7 +892,7 @@ def snake():
# Detect edge condition
(x, y) = head
if head in body:
return game_over()
return game_over(dev)
elif x >= WIDTH or x < 0 or y >= HEIGHT or y < 0:
if WRAP:
if x >= WIDTH:
Expand All @@ -905,7 +905,7 @@ def snake():
y = HEIGHT-1
head = (x, y)
else:
return game_over()
return game_over(dev)
elif head == food:
body.insert(0, oldhead)
while food == head:
Expand All @@ -922,7 +922,7 @@ def snake():
for bodypart in body:
(x, y) = bodypart
matrix[x][y] = 1
render_matrix(matrix)
render_matrix(dev, matrix)


def wpm_demo():
Expand All @@ -944,7 +944,7 @@ def wpm_demo():
if total_time < 10:
wpm = wpm / (total_time / 10)

show_string(' ' + str(int(wpm)))
show_string(dev, ' ' + str(int(wpm)))


def random_eq(dev):
Expand Down