Move Monster to the object module
This commit is contained in:
parent
cf0b120fad
commit
cf9ec2d17e
2 changed files with 36 additions and 17 deletions
|
@ -1,11 +1,12 @@
|
||||||
# Eryn Wells <eryn@erynwells.me>
|
# Eryn Wells <eryn@erynwells.me>
|
||||||
|
|
||||||
|
'''Defines the Species type, which represents a class of monsters, and all the monster types the hero can encounter in
|
||||||
|
the dungeon.'''
|
||||||
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
|
|
||||||
from .geometry import Point
|
# pylint: disable=too-many-instance-attributes
|
||||||
from .object import Entity
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
class Species:
|
class Species:
|
||||||
'''A kind of monster.
|
'''A kind of monster.
|
||||||
|
@ -30,19 +31,19 @@ class Species:
|
||||||
symbol: str
|
symbol: str
|
||||||
maximum_hit_points: int
|
maximum_hit_points: int
|
||||||
sight_radius: int
|
sight_radius: int
|
||||||
|
# TODO: Rename these two attributes something better
|
||||||
|
attack_power: int
|
||||||
|
defense: int
|
||||||
foreground_color: Tuple[int, int, int]
|
foreground_color: Tuple[int, int, int]
|
||||||
background_color: Tuple[int, int, int] = None
|
background_color: Tuple[int, int, int] = None
|
||||||
|
|
||||||
class Monster(Entity):
|
Orc = Species(name='Orc', symbol='o',
|
||||||
'''An instance of a Species.'''
|
foreground_color=(63, 127, 63),
|
||||||
|
maximum_hit_points=10,
|
||||||
def __init__(self, species: Species, position: Point = None):
|
sight_radius=4,
|
||||||
super().__init__(species.symbol, position=position, fg=species.foreground_color, bg=species.background_color)
|
attack_power=4, defense=1)
|
||||||
self.species: Species = species
|
Troll = Species(name='Troll', symbol='T',
|
||||||
self.hit_points: int = species.maximum_hit_points
|
foreground_color=(0, 127, 0),
|
||||||
|
maximum_hit_points=16,
|
||||||
def __str__(self) -> str:
|
sight_radius=4,
|
||||||
return f'{self.symbol}[{self.species.name}][{self.position}][{self.hit_points}/{self.species.maximum_hit_points}]'
|
attack_power=3, defense=0)
|
||||||
|
|
||||||
Orc = Species(name='Orc', symbol='o', foreground_color=(63, 127, 63), maximum_hit_points=10, sight_radius=4)
|
|
||||||
Troll = Species(name='Troll', symbol='T', foreground_color=(0, 127, 0), maximum_hit_points=20, sight_radius=4)
|
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# Eryn Wells <eryn@erynwells.me>
|
# Eryn Wells <eryn@erynwells.me>
|
||||||
|
|
||||||
from typing import Optional, Tuple
|
from typing import TYPE_CHECKING, Optional, Tuple, Type
|
||||||
|
|
||||||
import tcod
|
import tcod
|
||||||
|
|
||||||
|
from .components import Fighter
|
||||||
from .geometry import Point
|
from .geometry import Point
|
||||||
|
from .monsters import Species
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from .ai import AI
|
||||||
|
|
||||||
class Entity:
|
class Entity:
|
||||||
'''A single-tile drawable entity with a symbol and position.'''
|
'''A single-tile drawable entity with a symbol and position.'''
|
||||||
|
@ -31,3 +36,16 @@ class Entity:
|
||||||
class Hero(Entity):
|
class Hero(Entity):
|
||||||
def __init__(self, position: Point):
|
def __init__(self, position: Point):
|
||||||
super().__init__('@', position=position, fg=tuple(tcod.white))
|
super().__init__('@', position=position, fg=tuple(tcod.white))
|
||||||
|
|
||||||
|
class Monster(Entity):
|
||||||
|
'''An instance of a Species.'''
|
||||||
|
|
||||||
|
def __init__(self, species: Species, ai_class: Type['AI'], position: Point = None):
|
||||||
|
super().__init__(species.symbol, ai=ai_class(self), position=position, fg=species.foreground_color, bg=species.background_color)
|
||||||
|
self.species = species
|
||||||
|
self.fighter = Fighter(maximum_hit_points=species.maximum_hit_points,
|
||||||
|
attack_power=species.attack_power,
|
||||||
|
defense=species.defense)
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
return f'{self.symbol}[{self.species.name}][{self.position}][{self.fighter.hit_points}/{self.fighter.maximum_hit_points}]'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue