summaryrefslogtreecommitdiff
path: root/GameView.py
diff options
context:
space:
mode:
Diffstat (limited to 'GameView.py')
-rw-r--r--GameView.py35
1 files changed, 17 insertions, 18 deletions
diff --git a/GameView.py b/GameView.py
index a670d7c..6ec69fe 100644
--- a/GameView.py
+++ b/GameView.py
@@ -101,25 +101,26 @@ class GameView:
def isRunning(self) -> bool:
- return not self.game.isLost()
+ #return not self.game.isLost()
+ return True
def width(self) -> int:
- return self.game.width() * self.cellWidth
+ return self.game.level.width() * self.cellWidth
def height(self) -> int:
- return self.game.height() * self.cellWidth
+ return self.game.level.height() * self.cellWidth
def render(self, surface: Surface) -> None:
surface.fill("black")
- for cell in self.game.walls.walls():
+ for cell in self.game.level.walls.walls():
self._drawBoxOfColor(surface, "white", cell.x, cell.y)
- for static in self.game.statics:
+ for static in self.game.level.statics:
match static:
case Door():
if static.isOpen():
@@ -134,14 +135,11 @@ class GameView:
else:
self._drawBoxOfColor(surface, "purple", static.pos.x, static.pos.y)
- for box in self.game.boxes:
+ for box in self.game.level.boxes:
self._drawBoxOfColor(surface, "brown", box.pos.x, box.pos.y)
- match self.game.snake:
- case None: raise ValueError("snake not found")
- case _:
- for cell in self.game.snake.cells:
- self._drawBoxOfColor(surface, "red", cell.x, cell.y)
+ for cell in self.game.level.snake.cells:
+ self._drawBoxOfColor(surface, "red", cell.x, cell.y)
def _drawBoxOfColor(self, surface: Surface, color: str, x: int, y: int) -> None:
pygame.draw.rect(surface, color, pygame.Rect(
@@ -158,21 +156,22 @@ class GameView:
match self.nextControlDirection:
case None: None
case _:
- get(self.game.snake).heading = self.nextControlDirection
+ self.game.level.snake.heading = self.nextControlDirection
self.nextControlDirection = None
-# match self.game.snake:
-# case None: return None
-# case _:
-# self.game.snake.heading = self.nextControlDirection
-# self.nextControlDirection = None
self.game.tick()
elif not self.timeBased:
match self.nextControlDirection:
case None: None
case _:
self._previousTick = time
- get(self.game.snake).heading = self.nextControlDirection
+ self.game.level.snake.heading = self.nextControlDirection
self.nextControlDirection = None
self.game.tick()
+ if self.game.level.isCompleted():
+ self.game.nextLevel()
+
+ if self.game.isLost():
+ self.game.restartLevel()
+