This commit is contained in:
2021-05-26 16:36:59 -04:00
parent 3fff7ef498
commit d05eec6c03
5 changed files with 98 additions and 96 deletions

View File

@@ -5,12 +5,15 @@ from tcod.console import Console
from actions import EscapeAction, MovementAction
from entity import Entity
from game_map import GameMap
from input_handlers import EventHandler
class Engine:
def __init__(self, entities: Set[Entity], event_handler: EventHandler, player: Entity):
def __init__(self, entities: Set[Entity], event_handler: EventHandler, game_map: GameMap, player: Entity):
self.entities = entities
self.event_handler = event_handler
self.game_map = game_map
self.player = player
def handle_events(self, events: Iterable[Any]) -> None:
@@ -20,15 +23,14 @@ class Engine:
if action is None:
continue
if isinstance(action, MovementAction):
self.player.move(dx=action.dx, dy=action.dy)
elif isinstance(action, EscapeAction):
raise SystemExit()
action.perform(self, self.player)
def render(self, console: Console, context: Context) -> None:
self.game_map.render(console)
for entity in self.entities:
console.print(entity.x, entity.y, entity.char, fg=entity.color)
context.present(console)
console.clear()
console.clear()