From eb765050c5f0966b5464cc7eb39469a1ecd4a88e Mon Sep 17 00:00:00 2001 From: Vadzim Valchkovich Date: Wed, 7 Jun 2023 13:01:04 +0200 Subject: [PATCH] SPACE_K - pause functionality --- src/Engine.py | 8 +++++++- src/controller/UserController.py | 9 +++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Engine.py b/src/Engine.py index 10a25da..308843b 100644 --- a/src/Engine.py +++ b/src/Engine.py @@ -38,6 +38,7 @@ class Engine: self.goals: list = [] self.runnin: bool = False + self.paused: bool = False def __init_squares_field__(self, num_squares, square_size): squares = [] @@ -66,12 +67,14 @@ class Engine: self.running = False def action(self): + self.user.handler(self) + if self.paused: + return if not self.state.path: if self.goals: if not self.state.graphsearch(self) and self.goals: self.objects.remove(self.goals.pop().parent) - self.user.handler(self) self.predict() else: # went path @@ -109,6 +112,9 @@ class Engine: self.action_clock += action_time def redraw(self): + if self.paused: + return + self.screen.fill((255, 255, 255)) for row in self.squares: diff --git a/src/controller/UserController.py b/src/controller/UserController.py index 35768a3..daf68ba 100644 --- a/src/controller/UserController.py +++ b/src/controller/UserController.py @@ -1,4 +1,6 @@ +import time import pygame +from termcolor import colored class UserController: @@ -9,3 +11,10 @@ class UserController: for event in pygame.event.get(): if event.type == pygame.QUIT: engine.quit() + elif event.type == pygame.KEYDOWN: + if event.key == pygame.K_SPACE: + engine.paused = not engine.paused + if engine.paused: + print(colored("Paused", "red")) + else: + print(colored("Continued", "green"))