Move the event loop to Engine.run_event_loop()
This commit is contained in:
parent
bd5e1bc3c1
commit
c44c4e7bc6
2 changed files with 17 additions and 9 deletions
|
@ -4,17 +4,21 @@
|
|||
|
||||
import random
|
||||
from dataclasses import dataclass
|
||||
from typing import MutableSet
|
||||
from typing import TYPE_CHECKING, MutableSet, NoReturn
|
||||
|
||||
import tcod
|
||||
|
||||
from . import log
|
||||
from . import monsters
|
||||
from .ai import HostileEnemy
|
||||
from .events import MainGameEventHandler
|
||||
from .geometry import Size
|
||||
from .map import Map
|
||||
from .object import Entity, Hero, Monster
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .events import EventHandler
|
||||
|
||||
@dataclass
|
||||
class Configuration:
|
||||
map_size: Size
|
||||
|
@ -45,6 +49,8 @@ class Engine:
|
|||
self.map = Map(configuration.map_size)
|
||||
self.hero = Hero(position=self.map.generator.rooms[0].center)
|
||||
|
||||
self.event_handler: 'EventHandler' = MainGameEventHandler(self)
|
||||
|
||||
self.entities: MutableSet[Entity] = {self.hero}
|
||||
for room in self.map.rooms:
|
||||
should_spawn_monster_chance = random.random()
|
||||
|
@ -82,6 +88,15 @@ class Engine:
|
|||
continue
|
||||
ent.print_to_console(console)
|
||||
|
||||
def run_event_loop(self, context: tcod.context.Context, console: tcod.Console) -> NoReturn:
|
||||
'''Run the event loop forever. This method never returns.'''
|
||||
while True:
|
||||
console.clear()
|
||||
self.print_to_console(console)
|
||||
context.present(console)
|
||||
|
||||
self.event_handler.wait_for_events()
|
||||
|
||||
def update_field_of_view(self) -> None:
|
||||
'''Compute visible area of the map based on the player's position and point of view.'''
|
||||
# FIXME: Move this to the Map class
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue