Merge branch 'master' into 'equipment'

# Conflicts:
#   squirrelbattle/display/statsdisplay.py
#   squirrelbattle/entities/items.py
#   squirrelbattle/entities/player.py
#   squirrelbattle/interfaces.py
#   squirrelbattle/locale/de/LC_MESSAGES/squirrelbattle.po
#   squirrelbattle/locale/es/LC_MESSAGES/squirrelbattle.po
#   squirrelbattle/locale/fr/LC_MESSAGES/squirrelbattle.po
#   squirrelbattle/tests/game_test.py
This commit is contained in:
2021-01-08 02:11:40 +01:00
34 changed files with 1167 additions and 333 deletions

View File

@ -10,8 +10,8 @@ from ..interfaces import FightingEntity, Map
class Monster(FightingEntity):
"""
The class for all monsters in the dungeon.
A monster must override this class, and the parameters are given
in the __init__ function.
All specific monster classes overwrite this class,
and the parameters are given in the __init__ function.
An example of the specification of a monster that has a strength of 4
and 20 max HP:
@ -21,7 +21,7 @@ class Monster(FightingEntity):
super().__init__(name="my_monster", strength=strength,
maxhealth=maxhealth, *args, **kwargs)
With that way, attributes can be overwritten when the entity got created.
With that way, attributes can be overwritten when the entity is created.
"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
@ -29,7 +29,7 @@ class Monster(FightingEntity):
def act(self, m: Map) -> None:
"""
By default, a monster will move randomly where it is possible
And if a player is close to the monster, the monster run on the player.
If the player is closeby, the monster runs to the player.
"""
target = None
for entity in m.entities:
@ -38,12 +38,12 @@ class Monster(FightingEntity):
target = entity
break
# A Dijkstra algorithm has ran that targets the player.
# With that way, monsters can simply follow the path.
# If they can't move and they are already close to the player,
# They hit.
# Monsters move according to a Dijkstra algorithm
# that targets the player.
# If they can not move and are already close to the player,
# they hit.
if target and (self.y, self.x) in target.paths:
# Move to target player by choosing the best avaliable path
# Moves to target player by choosing the best available path
for next_y, next_x in target.paths[(self.y, self.x)]:
moved = self.check_move(next_y, next_x, True)
if moved:
@ -52,8 +52,8 @@ class Monster(FightingEntity):
self.map.logs.add_message(self.hit(target))
break
else:
# Move in a random direction
# If the direction is not available, try another one
# Moves in a random direction
# If the direction is not available, tries another one
moves = [self.move_up, self.move_down,
self.move_left, self.move_right]
shuffle(moves)
@ -61,10 +61,17 @@ class Monster(FightingEntity):
if move():
break
def move(self, y: int, x: int) -> None:
"""
Overwrites the move function to recalculate paths.
"""
super().move(y, x)
self.recalculate_paths()
class Tiger(Monster):
"""
A tiger monster
A tiger monster.
"""
def __init__(self, name: str = "tiger", strength: int = 2,
maxhealth: int = 20, *args, **kwargs) -> None:
@ -74,7 +81,7 @@ class Tiger(Monster):
class Hedgehog(Monster):
"""
A really mean hedgehog monster
A really mean hedgehog monster.
"""
def __init__(self, name: str = "hedgehog", strength: int = 3,
maxhealth: int = 10, *args, **kwargs) -> None:
@ -84,7 +91,7 @@ class Hedgehog(Monster):
class Rabbit(Monster):
"""
A rabbit monster
A rabbit monster.
"""
def __init__(self, name: str = "rabbit", strength: int = 1,
maxhealth: int = 15, critical: int = 30,
@ -96,7 +103,7 @@ class Rabbit(Monster):
class TeddyBear(Monster):
"""
A cute teddybear monster
A cute teddybear monster.
"""
def __init__(self, name: str = "teddy_bear", strength: int = 0,
maxhealth: int = 50, *args, **kwargs) -> None: