PEP8 formatter changes

This commit is contained in:
Eryn Wells 2023-02-10 21:25:00 -08:00
parent 727a0737c6
commit f05dfdef55
5 changed files with 20 additions and 1 deletions

View file

@ -13,17 +13,20 @@ MAP_WIDTH, MAP_HEIGHT = 80, 45
FONT_CP437 = 'terminal16x16_gs_ro.png' FONT_CP437 = 'terminal16x16_gs_ro.png'
FONT_BDF = 'ter-u32n.bdf' FONT_BDF = 'ter-u32n.bdf'
def parse_args(argv, *a, **kw): def parse_args(argv, *a, **kw):
parser = argparse.ArgumentParser(*a, **kw) parser = argparse.ArgumentParser(*a, **kw)
parser.add_argument('--debug', action='store_true', default=True) parser.add_argument('--debug', action='store_true', default=True)
args = parser.parse_args(argv) args = parser.parse_args(argv)
return args return args
def walk_up_directories_of_path(path): def walk_up_directories_of_path(path):
while path and path != '/': while path and path != '/':
path = os.path.dirname(path) path = os.path.dirname(path)
yield path yield path
def find_fonts_directory(): def find_fonts_directory():
'''Walk up the filesystem tree from this script to find a fonts/ directory.''' '''Walk up the filesystem tree from this script to find a fonts/ directory.'''
for parent_dir in walk_up_directories_of_path(__file__): for parent_dir in walk_up_directories_of_path(__file__):
@ -36,6 +39,7 @@ def find_fonts_directory():
return possible_fonts_dir return possible_fonts_dir
def main(argv): def main(argv):
''' '''
Beginning of the game Beginning of the game
@ -68,6 +72,7 @@ def main(argv):
with tcod.context.new(columns=console.width, rows=console.height, tileset=tileset) as context: with tcod.context.new(columns=console.width, rows=console.height, tileset=tileset) as context:
engine.run_event_loop(context, console) engine.run_event_loop(context, console)
def run_until_exit(): def run_until_exit():
''' '''
Run main() and call sys.exit when it finishes. In practice, this function will never return. The game engine has Run main() and call sys.exit when it finishes. In practice, this function will never return. The game engine has
@ -76,4 +81,5 @@ def run_until_exit():
result = main(sys.argv) result = main(sys.argv)
sys.exit(0 if not result else result) sys.exit(0 if not result else result)
run_until_exit() run_until_exit()

View file

@ -17,6 +17,8 @@ if TYPE_CHECKING:
from .engine import Engine from .engine import Engine
# pylint: disable=too-few-public-methods # pylint: disable=too-few-public-methods
class AI(Component): class AI(Component):
'''An abstract class providing AI for an entity.''' '''An abstract class providing AI for an entity.'''
@ -28,6 +30,7 @@ class AI(Component):
'''Produce an action to perform''' '''Produce an action to perform'''
raise NotImplementedError() raise NotImplementedError()
class HostileEnemy(AI): class HostileEnemy(AI):
'''Entity AI for a hostile enemy. '''Entity AI for a hostile enemy.
@ -60,7 +63,8 @@ class HostileEnemy(AI):
direction_to_next_position = entity_position.direction_to_adjacent_point(next_position) direction_to_next_position = entity_position.direction_to_adjacent_point(next_position)
if engine.map.visible[tuple(self.entity.position)]: if engine.map.visible[tuple(self.entity.position)]:
log.AI.info('`-> Hero is visible to %s, bumping %s (%s)', self.entity, direction_to_next_position, next_position) log.AI.info('`-> Hero is visible to %s, bumping %s (%s)',
self.entity, direction_to_next_position, next_position)
return BumpAction(self.entity, direction_to_next_position) return BumpAction(self.entity, direction_to_next_position)
else: else:

View file

@ -7,6 +7,7 @@ from typing import Optional
class Component: class Component:
'''A base, abstract Component that implement some aspect of an Entity's behavior.''' '''A base, abstract Component that implement some aspect of an Entity's behavior.'''
class Fighter(Component): class Fighter(Component):
'''A Fighter is an Entity that can fight. That is, it has hit points (health), attack, and defense. '''A Fighter is an Entity that can fight. That is, it has hit points (health), attack, and defense.

View file

@ -14,6 +14,7 @@ from .geometry import Direction, Point
if TYPE_CHECKING: if TYPE_CHECKING:
from .engine import Engine from .engine import Engine
class EventHandler(tcod.event.EventDispatch[Action]): class EventHandler(tcod.event.EventDispatch[Action]):
'''Abstract event handler class''' '''Abstract event handler class'''
@ -49,6 +50,7 @@ class EventHandler(tcod.event.EventDispatch[Action]):
def ev_quit(self, event: tcod.event.Quit) -> Optional[Action]: def ev_quit(self, event: tcod.event.Quit) -> Optional[Action]:
return ExitAction() return ExitAction()
class MainGameEventHandler(EventHandler): class MainGameEventHandler(EventHandler):
''' '''
Handler of `tcod` events for the main game. Handler of `tcod` events for the main game.
@ -95,6 +97,7 @@ class MainGameEventHandler(EventHandler):
mouse_point = None mouse_point = None
self.engine.current_mouse_point = mouse_point self.engine.current_mouse_point = mouse_point
class GameOverEventHandler(EventHandler): class GameOverEventHandler(EventHandler):
'''When the game is over (the hero dies, the player quits, etc), this event handler takes over.''' '''When the game is over (the hero dies, the player quits, etc), this event handler takes over.'''

View file

@ -1,5 +1,10 @@
# Eryn Wells <eryn@erynwells.me> # Eryn Wells <eryn@erynwells.me>
'''
This module defines the level map, a number of basic building blocks (Rooms, etc), and objects that generate various
parts of a map.
'''
import random import random
import numpy as np import numpy as np