From f9666c85abb56b8fd1ce8b7574066543148c8316 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Fri, 12 Nov 2021 18:25:20 +0100 Subject: Move playfield outside the Player class Signed-off-by: Olivier Gayot --- cameltris/playfield.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 cameltris/playfield.py (limited to 'cameltris/playfield.py') diff --git a/cameltris/playfield.py b/cameltris/playfield.py new file mode 100644 index 0000000..d1f4e9d --- /dev/null +++ b/cameltris/playfield.py @@ -0,0 +1,17 @@ +class PlayField: + def __init__(self): + self.grid = [[None for _ in range(10)] for _ in range(20)] + + def burn_rows(self) -> int: + """ Burn rows that can be filled and return how many of them were burnt """ + rows_to_burn = [] + + for row in self.grid: + if all(map(lambda element: element is not None, row)): + rows_to_burn.append(row) + + for row in rows_to_burn: + self.grid.insert(0, [None for _ in range(10)]) + self.grid.remove(row) + + return len(rows_to_burn) -- cgit v1.2.3