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:
@ -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
|
||||
|
||||
|
Reference in New Issue
Block a user