console_snake/main.py

48 lines
1.0 KiB
Python
Raw Permalink Normal View History

2022-10-26 21:57:29 +03:00
# from frame import Frame
from settings import *
from player import Player
import keyboard as kb
from out import Out
2022-10-26 22:40:18 +03:00
from os import system
2022-10-26 21:57:29 +03:00
class Game:
def __init__(self) -> None:
self.running = True
self.pl = Player()
self.out = Out()
kb.add_hotkey(QUIT_BUTTON, self.stop_game)
kb.add_hotkey(LEFT_BUTTON, self.pl.left)
kb.add_hotkey(RIGHT_BUTTON, self.pl.right)
kb.add_hotkey(UP_BUTTON, self.pl.up)
kb.add_hotkey(DOWN_BUTTON, self.pl.down)
def stop_game(self) -> None:
self.running = False
def update(self) -> None:
pass
def output(self) -> None:
pass
def play(self) -> None:
2022-10-26 22:40:18 +03:00
system("clear||cls")
2022-10-26 21:57:29 +03:00
while self.running:
try:
self.pl.update()
self.out.draw(self.pl)
except IndexError as e:
self.running = False
print(e)
def main() -> None:
Game().play()
if __name__ == '__main__':
main()