Lots of comment and type documentation in object.py
This commit is contained in:
parent
e1562b2b2b
commit
6bb5d819bf
1 changed files with 24 additions and 4 deletions
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/env python3
|
||||
# Eryn Wells <eryn@erynwells.me>
|
||||
|
||||
from typing import TYPE_CHECKING, Optional, Tuple, Type
|
||||
|
@ -13,7 +12,21 @@ if TYPE_CHECKING:
|
|||
from .ai import AI
|
||||
|
||||
class Entity:
|
||||
'''A single-tile drawable entity with a symbol and position.'''
|
||||
'''A single-tile drawable entity with a symbol and position.
|
||||
|
||||
Attributes
|
||||
----------
|
||||
position : Point
|
||||
The Entity's location on the map
|
||||
foreground : Tuple[int, int, int]
|
||||
The foreground color used to render this Entity
|
||||
background : Tuple[int, int, int], optional
|
||||
The background color used to render this Entity
|
||||
symbol : str
|
||||
A single character string that represents this character on the map
|
||||
ai : Type[AI], optional
|
||||
If an entity can act on its own behalf, an instance of an AI class
|
||||
'''
|
||||
|
||||
def __init__(self, symbol: str, *,
|
||||
position: Optional[Point] = None,
|
||||
|
@ -27,19 +40,26 @@ class Entity:
|
|||
self.ai = ai
|
||||
|
||||
def print_to_console(self, console: tcod.Console) -> None:
|
||||
'''Render this Entity to the console'''
|
||||
console.print(x=self.position.x, y=self.position.y, string=self.symbol, fg=self.foreground, bg=self.background)
|
||||
|
||||
def __str__(self):
|
||||
def __str__(self) -> str:
|
||||
return f'{self.symbol}[{self.position}]'
|
||||
|
||||
def __repr__(self):
|
||||
def __repr__(self) -> str:
|
||||
return f'{self.__class__.__name__}({self.symbol}, position={self.position}, fg={self.foreground}, bg={self.background})'
|
||||
|
||||
class Hero(Entity):
|
||||
'''The hero, the player character'''
|
||||
|
||||
def __init__(self, position: Point):
|
||||
super().__init__('@', position=position, fg=tuple(tcod.white))
|
||||
self.fighter = Fighter(maximum_hit_points=30, attack_power=5, defense=2)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f'{self.symbol}[{self.position}][{self.fighter.hit_points}/{self.fighter.maximum_hit_points}]'
|
||||
|
||||
|
||||
class Monster(Entity):
|
||||
'''An instance of a Species.'''
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue