This commit is contained in:
Yohann D'ANELLO 2020-12-18 17:46:38 +01:00
parent e1918ab066
commit 0394c5d15d
5 changed files with 27 additions and 22 deletions

View File

@ -54,21 +54,23 @@ class Sunflower(FriendlyEntity):
"""
return [_("Flower power!!"), _("The sun is warm today")]
class Familiar(FightingEntity):
"""
A friendly familiar that helps the player defeat monsters.
"""
def __init__(self, maxhealth: int = 25,
*args, **kwargs) -> None:
super().__init__(*args, **kwargs)
super().__init__(maxhealth=maxhealth, *args, **kwargs)
self.target = None
def act(self, p: Player, m : Map) :
def act(self, p: Player, m: Map) -> None:
"""
By default, the familiar tries to stay at distance at most 2 of the
player and if a monster comes in range 3, it focuses on the monster
and attacks it.
"""
if self.target == None:
if self.target is None:
self.target = p
if self.target == p:
for entity in m.entities:
@ -78,7 +80,6 @@ class Familiar(FightingEntity):
entity.paths = dict() # Allows the paths to be calculated.
break
# Familiars move according to a Dijkstra algorithm
# that targets their target.
# If they can not move and are already close to their target,
@ -106,6 +107,7 @@ class Familiar(FightingEntity):
if move():
break
class Trumpet(Familiar):
"""
A class of familiars.

View File

@ -60,6 +60,7 @@ class Monster(FightingEntity):
for move in moves:
if move():
break
def move(self, y: int, x: int) -> None:
"""
Overwrites the move function to recalculate paths.
@ -67,6 +68,7 @@ class Monster(FightingEntity):
super().move(y, x)
self.recalculate_paths()
class Tiger(Monster):
"""
A tiger monster.

View File

@ -2,7 +2,6 @@
# SPDX-License-Identifier: GPL-3.0-or-later
from random import randint
from typing import Dict, Tuple
from ..interfaces import FightingEntity, InventoryHolder

View File

@ -100,7 +100,8 @@ class Map:
@staticmethod
def load(filename: str) -> "Map":
"""
Reads a file that contains the content of a map, and builds a Map object.
Reads a file that contains the content of a map,
and builds a Map object.
"""
with open(filename, "r") as f:
file = f.read()
@ -307,7 +308,7 @@ class Entity:
Uses Dijkstra algorithm to calculate best paths for other entities to
go to this entity. If self.paths is None, does nothing.
"""
if self.paths == None :
if self.paths is None:
return
distances = []
predecessors = []

View File

@ -13,7 +13,8 @@ from .translations import gettext as _
class Settings:
"""
This class stores the settings of the game.
Settings can be obtained by using for example settings.TEXTURE_PACK directly.
Settings can be obtained by using for example settings.TEXTURE_PACK
directly.
The comment can be obtained by using settings.get_comment('TEXTURE_PACK').
We can set the setting by simply using settings.TEXTURE_PACK = 'new_key'
"""