1
0
Fork 0

Init - fix Randaustausch richtung, Adding Pause

This commit is contained in:
qvalentin 2022-03-27 18:11:51 +02:00
parent 1bca8c3c89
commit 50dca30a57
Signed by: qvalentin
GPG key ID: C979FA1EAFCABF1C
8 changed files with 61 additions and 24 deletions

View file

@ -1,5 +1,3 @@
import math
from Code.Communication.Direction import Direction
from Code.Config import GeneralConfig, SquareConfig
from Code.UI import Square
@ -8,8 +6,8 @@ from Code.UI.Square import Square
class Field:
def __init__(self):
self.width = GeneralConfig.fields_amount_x+2
self.height = GeneralConfig.fields_amount_y+2
self.width = GeneralConfig.fields_amount_x + 2
self.height = GeneralConfig.fields_amount_y + 2
self.field_shift = -10
self.squares = self._creat_squares()
@ -64,12 +62,12 @@ class Field:
def fill_ghost_edge(self, value: list):
edge_fn = {Direction.LEFT: self.fill_left_ghost_edge, Direction.RIGHT: self.fill_right_ghost_edge,
Direction.TOP: self.fill_top_ghost_edge, Direction.BOTTOM: self.fill_bottom_ghost_edge}
Direction.TOP: self.fill_top_ghost_edge, Direction.BOTTOM: self.fill_bottom_ghost_edge}
edge_fn(value)
def fill_right_ghost_edge(self, value: list):
#if len(value)== self.square.
# if len(value)== self.square.
for i in range(len(value)):
self.squares[len(self.squares[0]) - 1][i].active = value[i]
@ -77,8 +75,8 @@ class Field:
for i in range(len(value)):
self.squares[0][i].active = value[i]
def fill_top_ghost_edge(self,value):
def fill_top_ghost_edge(self, value):
pass
def fill_bottom_ghost_edge(self,value):
def fill_bottom_ghost_edge(self, value):
pass

View file

@ -2,6 +2,7 @@ import pygame as pygame
from Code.Communication.Direction import Direction
from Code.Communication.Neighbours import Neighbours
from Code.Config import Fonts
from Code.Config import GeneralConfig, Colors
from Code.GameLogic.Rules import Rules
from Code.UI.Field import Field
@ -24,6 +25,7 @@ class GameState:
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
self.pause_for_input = not self.pause_for_input
self.neighbours.toggle_pause(self.pause_for_input)
def update_field_with_input(self, event):
for line in self.field.squares:
@ -38,16 +40,24 @@ class GameState:
def redraw_field(self, window):
window.fill(Colors.BLACK)
self.field.draw_squares(window)
if not self.pause_for_input:
label_font = Fonts.monospace_80
label = label_font.render("Pause", 1, Colors.ORANGE)
window.blit(label, (100, 100))
def update_borders(self):
self.field.fill_right_ghost_edge(self.neighbours.get_edge(Direction.RIGHT))
self.field.fill_left_ghost_edge(self.neighbours.get_edge(Direction.LEFT))
def run_game(game_state: GameState):
pygame.init()
pygame.display.set_caption(GeneralConfig.window_caption)
window = pygame.display.set_mode((GeneralConfig.width, GeneralConfig.height))
clock = pygame.time.Clock()
time_elapsed_since_last_action = 0
while game_state.run:
game_state.event_handler()