First pass on the logs
The newly-added logs manage a list of messages. Entities do register a message to it when hitting each other. Display is created, but not yet added to the layout actually displayed.
This commit is contained in:
@ -7,6 +7,26 @@ from typing import List, Optional
|
||||
from squirrelbattle.display.texturepack import TexturePack
|
||||
|
||||
|
||||
class Logs:
|
||||
"""
|
||||
The logs object stores the messages to display. It is encapsulating a list
|
||||
of such messages, to allow multiple pointers to keep track of it even if
|
||||
the list was to be reassigned.
|
||||
"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.messages = []
|
||||
|
||||
def add_message(self, msg: str) -> None:
|
||||
self.messages.append(msg)
|
||||
|
||||
def add_messages(self, msg: List[str]) -> None:
|
||||
self.messages += msg
|
||||
|
||||
def clear(self) -> None:
|
||||
self.messages = []
|
||||
|
||||
|
||||
class Map:
|
||||
"""
|
||||
Object that represents a Map with its width, height
|
||||
@ -18,6 +38,7 @@ class Map:
|
||||
start_x: int
|
||||
tiles: List[List["Tile"]]
|
||||
entities: List["Entity"]
|
||||
logs: Logs
|
||||
# coordinates of the point that should be
|
||||
# on the topleft corner of the screen
|
||||
currentx: int
|
||||
@ -362,19 +383,22 @@ class FightingEntity(Entity):
|
||||
def dead(self) -> bool:
|
||||
return self.health <= 0
|
||||
|
||||
def hit(self, opponent: "FightingEntity") -> None:
|
||||
def hit(self, opponent: "FightingEntity") -> str:
|
||||
"""
|
||||
Deals damage to the opponent, based on the stats
|
||||
"""
|
||||
opponent.take_damage(self, self.strength)
|
||||
return f"{self.name} hits {opponent.name}. "\
|
||||
+ opponent.take_damage(self, self.strength)
|
||||
|
||||
def take_damage(self, attacker: "Entity", amount: int) -> None:
|
||||
def take_damage(self, attacker: "Entity", amount: int) -> str:
|
||||
"""
|
||||
Take damage from the attacker, based on the stats
|
||||
"""
|
||||
self.health -= amount
|
||||
if self.health <= 0:
|
||||
self.die()
|
||||
return f"{self.name} takes {amount} damage."\
|
||||
+ (f" {self.name} dies." if self.health <= 0 else "")
|
||||
|
||||
def die(self) -> None:
|
||||
"""
|
||||
|
Reference in New Issue
Block a user