From c74dfcc1a315189259e9643e10ca6df74ee943f1 Mon Sep 17 00:00:00 2001 From: Nicolas Sudres Date: Sun, 31 Jul 2022 19:48:16 +0200 Subject: [PATCH] start of snake movement --- Snake/main.py | 8 +++++--- Snake/src/snake.py | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Snake/main.py b/Snake/main.py index 01454a5..10e65f2 100644 --- a/Snake/main.py +++ b/Snake/main.py @@ -10,17 +10,19 @@ WIDTH = 20 def main(): test = snake.List((5, 5), None) - test = snake.List.List_add(test, 12) - test = snake.List.List_add(test, 14) - test = snake.List.List_add(test, 16) + test = snake.List.List_add(test, (6, 6)) + test = snake.List.List_add(test, (7, 7)) + test = snake.List.List_add(test, (8, 8)) print(test) print("Size : ", snake.List.List_size(test)) + matrix = level.init_level(HEIGH, WIDTH) matrix[5][5] = 1 level.spawn_apple(matrix, HEIGH, WIDTH) print(matrix) + snake.Snake_move(matrix, test, "left") if __name__ == "__main__": diff --git a/Snake/src/snake.py b/Snake/src/snake.py index 4ab16d8..ff56ca4 100644 --- a/Snake/src/snake.py +++ b/Snake/src/snake.py @@ -1,4 +1,6 @@ +DIRECTION = {'left': (0, -1), 'right': (0, 1), 'up': (-1, 0), 'down': (1, 0)} + class List: def __init__(self, val, next): self.val = val @@ -26,3 +28,16 @@ class List: L = L.next return i + +def Snake_move(M, L, dir): + L_save = L + + L.val = (DIRECTION[dir][0] + L.val[0], DIRECTION[dir][1] + L.val[1]) + + L = L.next + L_save = L_save.next + + while L is not None: + + + L = L.next \ No newline at end of file