2023-10-26 02:38:17 +03:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2023-10-26 01:34:51 +03:00
|
|
|
def main() -> None:
|
2023-10-26 02:38:17 +03:00
|
|
|
game = Tetris()
|
|
|
|
game.start()
|
2023-10-26 01:34:51 +03:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|