bludiste/game.py
2023-11-22 21:43:16 +01:00

40 lines
959 B
Python

from gameobject import *
from world import *
class Game:
"""
Obsahuje logiku hry
@Author: zbyv
@Date: 22.11.2023
"""
def __init__(self, world: World, hero: GameObject, home: GameObject) -> None:
self.__world = world
self.__hero = hero
self.__home = home
"""
Spusti hru
Returns:
True: hrdina dosel na domovskou pozici
False: hrdina se dostal na prazdne pole
"""
def run(self) -> bool:
gui = Gui(self.__world.width, self.__world.height)
while True:
gui.clear()
self.__world.draw(gui)
self.__home.draw(gui)
self.__hero.draw(gui)
gui.show()
if self.__hero.position == self.__home.position:
return True
if not self.__world.is_empty(self.__hero.position):
return False
self.__hero.move(gui.input_direction())