Added documentation for some classes again

This commit is contained in:
eichhornchen 2020-11-18 12:27:59 +01:00 committed by Yohann D'ANELLO
parent 8f932604f6
commit aac01d8bef
6 changed files with 40 additions and 62 deletions

View File

@ -5,6 +5,9 @@ from ..interfaces import Entity, FightingEntity, Map
class Item(Entity): class Item(Entity):
"""
A class for items
"""
held: bool held: bool
held_by: Optional["Player"] held_by: Optional["Player"]
@ -13,6 +16,9 @@ class Item(Entity):
self.held = False self.held = False
def drop(self, y: int, x: int) -> None: def drop(self, y: int, x: int) -> None:
"""
The item is dropped from the inventory onto the floor
"""
if self.held: if self.held:
self.held_by.inventory.remove(self) self.held_by.inventory.remove(self)
self.held = False self.held = False
@ -21,6 +27,9 @@ class Item(Entity):
self.move(y, x) self.move(y, x)
def hold(self, player: "Player") -> None: def hold(self, player: "Player") -> None:
"""
The item is taken from the floor and put into the inventory
"""
self.held = True self.held = True
self.held_by = player self.held_by = player
self.map.remove_entity(self) self.map.remove_entity(self)
@ -28,6 +37,9 @@ class Item(Entity):
class Heart(Item): class Heart(Item):
"""
A heart item to return health to the player
"""
name: str = "heart" name: str = "heart"
healing: int = 5 healing: int = 5
@ -40,6 +52,9 @@ class Heart(Item):
class Bomb(Item): class Bomb(Item):
"""
A bomb item intended to deal damage to ennemies at long range
"""
name: str = "bomb" name: str = "bomb"
damage: int = 5 damage: int = 5
exploding: bool exploding: bool
@ -53,6 +68,9 @@ class Bomb(Item):
self.exploding = True self.exploding = True
def act(self, m: Map) -> None: def act(self, m: Map) -> None:
"""
Special exploding action of the bomb
"""
if self.exploding: if self.exploding:
for e in m.entities: for e in m.entities:
if abs(e.x - self.x) + abs(e.y - self.y) <= 1 and \ if abs(e.x - self.x) + abs(e.y - self.y) <= 1 and \

View File

@ -5,6 +5,9 @@ from ..interfaces import FightingEntity, Map
class Monster(FightingEntity): class Monster(FightingEntity):
"""
The class for all monsters in the dungeon
"""
def __init__(self) -> None: def __init__(self) -> None:
super().__init__() super().__init__()
@ -38,6 +41,9 @@ class Monster(FightingEntity):
class Beaver(Monster): class Beaver(Monster):
"""
A beaver monster
"""
def __init__(self) -> None: def __init__(self) -> None:
super().__init__() super().__init__()
name = "beaver" name = "beaver"
@ -46,6 +52,9 @@ class Beaver(Monster):
class Hedgehog(Monster): class Hedgehog(Monster):
"""
A really mean hedgehog monster
"""
def __init__(self) -> None: def __init__(self) -> None:
super().__init__() super().__init__()
name = "hedgehog" name = "hedgehog"
@ -54,6 +63,9 @@ class Hedgehog(Monster):
class Rabbit(Monster): class Rabbit(Monster):
"""
A rabbit monster
"""
def __init__(self) -> None: def __init__(self) -> None:
super().__init__() super().__init__()
name = "rabbit" name = "rabbit"
@ -62,6 +74,9 @@ class Rabbit(Monster):
class TeddyBear(Monster): class TeddyBear(Monster):
"""
A cute teddybear monster
"""
def __init__(self) -> None: def __init__(self) -> None:
super().__init__() super().__init__()
name = "teddy_bear" name = "teddy_bear"

View File

@ -5,6 +5,9 @@ from ..interfaces import FightingEntity
class Player(FightingEntity): class Player(FightingEntity):
"""
The class of the player
"""
name = "player" name = "player"
maxhealth: int = 20 maxhealth: int = 20
strength: int = 5 strength: int = 5

View File

@ -3,6 +3,10 @@ from types import TracebackType
class TermManager: # pragma: no cover class TermManager: # pragma: no cover
"""
The TermManager object initializes the terminal, returns a screen object and
de-initializes the terminal after use
"""
def __init__(self): def __init__(self):
self.screen = curses.initscr() self.screen = curses.initscr()
# convert escapes sequences to curses abstraction # convert escapes sequences to curses abstraction

View File

@ -1,45 +0,0 @@
1 1
##############################################################################################################
#............................................................................................................#
#............................................................................................................#
#............................................................................................................#
#............................................................................................................#
#............................................................................................................#
#............................................................................................................#
#............................................................................................................#
#............................................................................................................#
#............................................................................................................#
#............................................................................................................#
#............................................................................................................#
#............................................................................................................#
#............................................................................................................#
#............................................................................................................#
#............................................................................................................#
#............................................................................................................#
#............................................................................................................#
#............................................................................................................#
#............................................................................................................#
#............................................................................................................#
#............................................................................................................#
#............................................................................................................#
#............................................................................................................#
#............................................................................................................#
#............................................................................................................#
#............................................................................................................#
#............................................................................................................#
#............................................................................................................#
#............................................................................................................#
#............................................................................................................#
#............................................................................................................#
#............................................................................................................#
#............................................................................................................#
#............................................................................................................#
#............................................................................................................#
#............................................................................................................#
#............................................................................................................#
#............................................................................................................#
#............................................................................................................#
#............................................................................................................#
#............................................................................................................#
#............................................................................................................#
##############################################################################################################

17
test.py
View File

@ -1,17 +0,0 @@
import json
class hi:
PLOP = "hello"
PPPP = "ghjk"
def __init__(self):
self.bl = "zrfcv"
def prin(self) :
return json.dumps(self.__dict__)
def f() :
d = hi()
print(d.prin())
f()