From 74e746812d2f2996499dd836427dac7585845ea8 Mon Sep 17 00:00:00 2001 From: Nicolas Sudres Date: Wed, 27 Jul 2022 11:22:58 +0200 Subject: [PATCH] add level init + rand spawn --- Snake/src/level.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Snake/src/level.py b/Snake/src/level.py index e69de29..b6167a5 100644 --- a/Snake/src/level.py +++ b/Snake/src/level.py @@ -0,0 +1,21 @@ +import numpy as np +import random + +# 0 = AIR +# 1 = SNAKE +# 2 = WALL +# 3 = APPLE + +def init_level(heigh, width): + return np.zeros((heigh, width)) + +def spawn_apple(M, heigh, width): + random.seed() + rand_heigh = random.randrange(0, heigh) + rand_width = random.randrange(0, width) + + if M[rand_heigh][rand_width] == 0: + M[rand_heigh][rand_width] = 3 + else: + spawn_apple(M, heigh, width) + \ No newline at end of file