SPACE_K - pause functionality
This commit is contained in:
parent
5842270806
commit
eb765050c5
@ -38,6 +38,7 @@ class Engine:
|
|||||||
self.goals: list = []
|
self.goals: list = []
|
||||||
|
|
||||||
self.runnin: bool = False
|
self.runnin: bool = False
|
||||||
|
self.paused: bool = False
|
||||||
|
|
||||||
def __init_squares_field__(self, num_squares, square_size):
|
def __init_squares_field__(self, num_squares, square_size):
|
||||||
squares = []
|
squares = []
|
||||||
@ -66,12 +67,14 @@ class Engine:
|
|||||||
self.running = False
|
self.running = False
|
||||||
|
|
||||||
def action(self):
|
def action(self):
|
||||||
|
self.user.handler(self)
|
||||||
|
if self.paused:
|
||||||
|
return
|
||||||
if not self.state.path:
|
if not self.state.path:
|
||||||
if self.goals:
|
if self.goals:
|
||||||
if not self.state.graphsearch(self) and self.goals:
|
if not self.state.graphsearch(self) and self.goals:
|
||||||
self.objects.remove(self.goals.pop().parent)
|
self.objects.remove(self.goals.pop().parent)
|
||||||
|
|
||||||
self.user.handler(self)
|
|
||||||
self.predict()
|
self.predict()
|
||||||
else:
|
else:
|
||||||
# went path
|
# went path
|
||||||
@ -109,6 +112,9 @@ class Engine:
|
|||||||
self.action_clock += action_time
|
self.action_clock += action_time
|
||||||
|
|
||||||
def redraw(self):
|
def redraw(self):
|
||||||
|
if self.paused:
|
||||||
|
return
|
||||||
|
|
||||||
self.screen.fill((255, 255, 255))
|
self.screen.fill((255, 255, 255))
|
||||||
|
|
||||||
for row in self.squares:
|
for row in self.squares:
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
|
import time
|
||||||
import pygame
|
import pygame
|
||||||
|
from termcolor import colored
|
||||||
|
|
||||||
|
|
||||||
class UserController:
|
class UserController:
|
||||||
@ -9,3 +11,10 @@ class UserController:
|
|||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
engine.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"))
|
||||||
|
Loading…
Reference in New Issue
Block a user