Move the action perform logic to Action.perform() on each Action subclass

Rename Object to Entity to avoid name clashes with Python.object
This commit is contained in:
Eryn Wells 2022-05-01 09:29:30 -07:00
parent cde6ea2065
commit 5ce26e310b
4 changed files with 49 additions and 57 deletions

View file

@ -2,42 +2,16 @@
# Eryn Wells <eryn@erynwells.me>
import tcod
from .geometry import Point, Vector
from .geometry import Point
from typing import Optional
class Object:
'''A drawable object with a symbol and (x, y) position.'''
class Entity:
'''A single-tile drawable entity with a symbol and position.'''
def __init__(self, symbol: str, color: tcod.Color = (255, 255, 255), x: int = 0, y: int = 0):
self.__x = int(x)
self.__y = int(y)
self.__color = color
self.__symbol = symbol
@property
def x(self):
return self.__x
@x.setter
def x(self, value):
self.__x = int(value)
@property
def y(self):
return self.__y
@y.setter
def y(self, value):
self.__y = int(value)
def move(self, delta: Vector):
'''Move this object by (dx, dy).'''
self.__x += delta.dx
self.__y += delta.dy
def move_to(self, point: Point) -> None:
'''Move this object directly to the given position.'''
self.__x = point.x
self.__y = point.y
def __init__(self, symbol: str, *, position: Optional[Point] = None, color: Optional[tcod.Color] = None):
self.position = position if position else Point()
self.color = color if color else tcod.white
self.symbol = symbol
def print_to_console(self, console: tcod.Console) -> None:
console.print(x=self.__x, y=self.__y, string=self.__symbol, fg=self.__color)