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

@ -30,7 +30,7 @@ class Game:
def __init__(self) -> None:
"""
Init the game.
Initiates the game.
"""
self.state = GameMode.MAINMENU
self.waiting_for_friendly_key = False
@ -48,7 +48,7 @@ class Game:
def new_game(self) -> None:
"""
Create a new game on the screen.
Creates a new game on the screen.
"""
# TODO generate a new map procedurally
self.map = Map.load(ResourceManager.get_asset_path("example_map.txt"))
@ -63,8 +63,8 @@ class Game:
def run(self, screen: Any) -> None:
"""
Main infinite loop.
We wait for the player's action, then we do what that should be done
when the given key gets pressed.
We wait for the player's action, then we do what should be done
when a key gets pressed.
"""
while True: # pragma no cover
screen.erase()
@ -81,7 +81,7 @@ class Game:
def handle_key_pressed(self, key: Optional[KeyValues], raw_key: str = '')\
-> None:
"""
Indicates what should be done when the given key is pressed,
Indicates what should be done when a given key is pressed,
according to the current game state.
"""
if self.message:
@ -133,8 +133,9 @@ class Game:
def handle_friendly_entity_chat(self, key: KeyValues) -> None:
"""
If the player is talking to a friendly entity, we get the direction
where the entity is, then we interact with it.
If the player tries to talk to a friendly entity, the game waits for
a directional key to be pressed, verifies there is a friendly entity
in that direction and then lets the player interact with it.
"""
if not self.waiting_for_friendly_key:
return
@ -210,7 +211,7 @@ class Game:
def handle_key_pressed_main_menu(self, key: KeyValues) -> None:
"""
In the main menu, we can navigate through options.
In the main menu, we can navigate through different options.
"""
if key == KeyValues.DOWN:
self.main_menu.go_down()
@ -235,13 +236,13 @@ class Game:
def save_state(self) -> dict:
"""
Saves the game to a dictionary
Saves the game to a dictionary.
"""
return self.map.save_state()
def load_state(self, d: dict) -> None:
"""
Loads the game from a dictionary
Loads the game from a dictionary.
"""
try:
self.map.load_state(d)
@ -265,7 +266,7 @@ class Game:
def load_game(self) -> None:
"""
Loads the game from a file
Loads the game from a file.
"""
file_path = ResourceManager.get_config_path("save.json")
if os.path.isfile(file_path):
@ -282,7 +283,7 @@ class Game:
def save_game(self) -> None:
"""
Saves the game to a file
Saves the game to a file.
"""
with open(ResourceManager.get_config_path("save.json"), "w") as f:
f.write(json.dumps(self.save_state()))