From 58fdba4d827f44729b38b270db18274fd274f2d1 Mon Sep 17 00:00:00 2001 From: Plaza521 Date: Thu, 26 Oct 2023 02:38:17 +0300 Subject: [PATCH] Add game class --- main.py | 41 +++++++++++++++++++++++++++++++++++++++-- requirements.txt | 1 + 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 requirements.txt diff --git a/main.py b/main.py index 4c7173d..bfe7d39 100644 --- a/main.py +++ b/main.py @@ -1,7 +1,44 @@ +from threading import Thread +from screen import Screen +from timer import Timer +from getkey import getkey + + +class Tetris: + def __init__(self) -> None: + self.screen = Screen(10, 20, '..') + + self.last_char = '' + self.input_thread = Thread(target=self.input, daemon=True) + self.input_thread.start() + + self.timer = Timer() + + def start(self) -> None: + self.running = True + while self.running: + self.timer.control_fps(30) + self.screen.print() + + def stop(self) -> None: + self.running = False + self.timer.running = False + self.input_running = False + + def input(self) -> None: + self.input_running = True + while self.input_running: + self.last_char = getkey() + match self.last_char: + case 'q': + self.stop() + return + + def main() -> None: - pass + game = Tetris() + game.start() if __name__ == "__main__": main() - diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..f6d32b4 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +getkey==0.6.5