Fixed grammar, unified the docstring's format and added documentation to some classes that did not have any. Closes #32.

This commit is contained in:
eichhornchen
2020-12-13 21:29:25 +01:00
parent 3f62fbaa2b
commit 646e0063be
24 changed files with 254 additions and 170 deletions

View File

@ -7,7 +7,7 @@ from random import choice
class Merchant(InventoryHolder, FriendlyEntity):
"""
The class for merchants in the dungeon
The class of merchants in the dungeon.
"""
def keys(self) -> list:
"""
@ -28,13 +28,13 @@ class Merchant(InventoryHolder, FriendlyEntity):
def talk_to(self, player: Player) -> str:
"""
This function is used to open the merchant's inventory in a menu,
and allow the player to buy/sell objects
and allows the player to buy/sell objects.
"""
return _("I don't sell any squirrel")
def change_hazel_balance(self, hz: int) -> None:
"""
Change the number of hazel the merchant has by hz.
Changes the number of hazel the merchant has by hz.
"""
self.hazel += hz
@ -49,4 +49,7 @@ class Sunflower(FriendlyEntity):
@property
def dialogue_option(self) -> list:
"""
Lists all that a sunflower can say to the player.
"""
return [_("Flower power!!"), _("The sun is warm today")]

View File

@ -11,7 +11,7 @@ from ..translations import gettext as _
class Item(Entity):
"""
A class for items
A class for items.
"""
held: bool
held_by: Optional[InventoryHolder]
@ -27,7 +27,7 @@ class Item(Entity):
def drop(self) -> None:
"""
The item is dropped from the inventory onto the floor
The item is dropped from the inventory onto the floor.
"""
if self.held:
self.held_by.inventory.remove(self)
@ -48,7 +48,7 @@ class Item(Entity):
def hold(self, player: InventoryHolder) -> None:
"""
The item is taken from the floor and put into the inventory
The item is taken from the floor and put into the inventory.
"""
self.held = True
self.held_by = player
@ -57,7 +57,7 @@ class Item(Entity):
def save_state(self) -> dict:
"""
Saves the state of the entity into a dictionary
Saves the state of the item into a dictionary.
"""
d = super().save_state()
d["held"] = self.held
@ -65,13 +65,16 @@ class Item(Entity):
@staticmethod
def get_all_items() -> list:
"""
Returns the list of all item classes.
"""
return [BodySnatchPotion, Bomb, Heart, Sword]
def be_sold(self, buyer: InventoryHolder, seller: InventoryHolder) -> bool:
"""
Does all necessary actions when an object is to be sold.
Is overwritten by some classes that cannot exist in the player's
inventory
inventory.
"""
if buyer.hazel >= self.price:
self.hold(buyer)
@ -85,7 +88,7 @@ class Item(Entity):
class Heart(Item):
"""
A heart item to return health to the player
A heart item to return health to the player.
"""
healing: int
@ -96,14 +99,15 @@ class Heart(Item):
def hold(self, entity: InventoryHolder) -> None:
"""
When holding a heart, heal the player and don't put item in inventory.
When holding a heart, the player is healed and
the item is not put in the inventory.
"""
entity.health = min(entity.maxhealth, entity.health + self.healing)
entity.map.remove_entity(self)
def save_state(self) -> dict:
"""
Saves the state of the header into a dictionary
Saves the state of the heart into a dictionary.
"""
d = super().save_state()
d["healing"] = self.healing
@ -129,7 +133,7 @@ class Bomb(Item):
def use(self) -> None:
"""
When the bomb is used, throw it and explodes it.
When the bomb is used, it is thrown and then it explodes.
"""
if self.held:
self.owner = self.held_by
@ -138,7 +142,7 @@ class Bomb(Item):
def act(self, m: Map) -> None:
"""
Special exploding action of the bomb
Special exploding action of the bomb.
"""
if self.exploding:
if self.tick > 0:
@ -164,7 +168,7 @@ class Bomb(Item):
def save_state(self) -> dict:
"""
Saves the state of the bomb into a dictionary
Saves the state of the bomb into a dictionary.
"""
d = super().save_state()
d["exploding"] = self.exploding
@ -181,13 +185,13 @@ class Explosion(Item):
def act(self, m: Map) -> None:
"""
The explosion instant dies.
The bomb disappears after exploding.
"""
m.remove_entity(self)
def hold(self, player: InventoryHolder) -> None:
"""
The player can't hold any explosion.
The player can't hold an explosion.
"""
pass

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)
@ -64,7 +64,7 @@ class Monster(FightingEntity):
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 +74,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 +84,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, *args, **kwargs) -> None:
@ -94,7 +94,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:

View File

@ -11,7 +11,7 @@ from ..interfaces import FightingEntity, InventoryHolder
class Player(InventoryHolder, FightingEntity):
"""
The class of the player
The class of the player.
"""
current_xp: int = 0
max_xp: int = 10
@ -45,7 +45,7 @@ class Player(InventoryHolder, FightingEntity):
def level_up(self) -> None:
"""
Add levels to the player as much as it is possible.
Add as many levels as possible to the player.
"""
while self.current_xp > self.max_xp:
self.level += 1
@ -59,8 +59,8 @@ class Player(InventoryHolder, FightingEntity):
def add_xp(self, xp: int) -> None:
"""
Add some experience to the player.
If the required amount is reached, level up.
Adds some experience to the player.
If the required amount is reached, the player levels up.
"""
self.current_xp += xp
self.level_up()
@ -89,9 +89,8 @@ class Player(InventoryHolder, FightingEntity):
def recalculate_paths(self, max_distance: int = 8) -> None:
"""
Use Dijkstra algorithm to calculate best paths for monsters to go to
the player. Actually, the paths are computed for each tile adjacent to
the player then for each step the monsters use the best path avaliable.
Uses Dijkstra algorithm to calculate best paths for monsters to go to
the player.
"""
distances = []
predecessors = []