-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathengine.py
More file actions
executable file
·43 lines (31 loc) · 1.19 KB
/
engine.py
File metadata and controls
executable file
·43 lines (31 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Oct 12 13:17:51 2020
@author: nathaniellesage
"""
from typing import Set, Iterable, Any
from tcod.context import Context
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], game_map: GameMap, event_handler: EventHandler, 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:
for event in events:
action = self.event_handler.dispatch(event)
if action is None:
continue
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.n, entity.m, entity.char, fg=entity.color)
context.present(console)
console.clear()