Added documentation on a lot of classes and functions (and removed some files I commited by mistake)

This commit is contained in:
eichhornchen
2020-11-18 12:19:27 +01:00
parent f67eae3803
commit 4c4a140a45
5 changed files with 124 additions and 12 deletions

View File

@@ -12,6 +12,9 @@ from typing import Callable
class Game:
"""
The game object controls all actions in the game.
"""
map: Map
player: Player
display_actions: Callable[[DisplayActions], None]
@@ -42,8 +45,8 @@ class Game:
def run(self, screen: Any) -> None:
"""
Main infinite loop.
We wait for a player action, then we do what that should be done
when the given key got pressed.
We wait for the player's action, then we do what that should be done
when the given key gets pressed.
"""
while True: # pragma no cover
screen.clear()
@@ -69,7 +72,7 @@ class Game:
def handle_key_pressed_play(self, key: KeyValues) -> None:
"""
In play mode, arrows or zqsd should move the main character.
In play mode, arrows or zqsd move the main character.
"""
if key == KeyValues.UP:
if self.player.move_up():
@@ -107,15 +110,16 @@ class Game:
elif option == menus.MainMenuValues.EXIT:
sys.exit(0)
def game_to_str(self) -> str:
d = dict()
d["Map"] = game.map
d["Player"] = game.player
def save_state(self) -> dict():
"""
Saves the game to a dictionnary
"""
return self.map.save_state()
def load_state(self, d: dict) -> None:
"""
Loads the game from a dictionnary
"""
self.map.load_state(d)
def load_game(self) -> None:
@@ -128,7 +132,7 @@ class Game:
def save_game(self) -> None:
"""
Save the game to a file
Saves the game to a file
"""
with open("save.json", "w") as f:
f.write(json.dumps(self.save_state()))