This commit is contained in:
Yohann D'ANELLO 2020-11-18 14:56:59 +01:00
parent be6c949b18
commit 958dcdfee0
5 changed files with 20 additions and 16 deletions

View File

@ -5,8 +5,9 @@ from dungeonbattle.term_manager import TermManager
class Bootstrap:
"""
The bootstrap object is used to bootstrap the game so that it starts properly.
(It was initially created to avoid circulary imports between the Game and
The bootstrap object is used to bootstrap the game so that it starts
properly.
(It was initially created to avoid circular imports between the Game and
Display classes)
"""

View File

@ -3,13 +3,13 @@ from typing import Optional
from dungeonbattle.settings import Settings
#This file contains a few useful enumeration classes used elsewhere in the code
# This file contains a few useful enumeration classes used elsewhere in the code
class DisplayActions(Enum):
"""
Display actions options for the callable displayaction Game uses
(it just calls the same action on the display object displayaction refers to)
It just calls the same action on the display object displayaction refers to.
"""
REFRESH = auto()
UPDATE = auto()

View File

@ -1,7 +1,8 @@
from random import randint
from typing import Any, Optional,Generator
from typing import Any, Optional
import json
import os
import sys
from .entities.player import Player
from .enums import GameMode, KeyValues, DisplayActions
@ -111,15 +112,15 @@ class Game:
elif option == menus.MainMenuValues.EXIT:
sys.exit(0)
def save_state(self) -> dict():
def save_state(self) -> dict:
"""
Saves the game to a dictionnary
Saves the game to a dictionary
"""
return self.map.save_state()
def load_state(self, d: dict) -> None:
"""
Loads the game from a dictionnary
Loads the game from a dictionary
"""
self.map.load_state(d)

View File

@ -146,7 +146,8 @@ class Map:
self.currentx = d["currentx"]
self.currenty = d["currenty"]
self.map = self.load_dungeon_from_string(d["map"])
#add entities
# add entities
class Tile(Enum):
"""
@ -168,7 +169,8 @@ class Tile(Enum):
def char(self, pack: TexturePack) -> str:
"""
Translates a Tile to the corresponding character according to the texture pack
Translates a Tile to the corresponding character according
to the texture pack
"""
return getattr(pack, self.name)
@ -300,7 +302,7 @@ class Entity:
d["y"] = self.y
return d
def recover_state(self, d : dict) -> None:
def recover_state(self, d: dict) -> None:
"""
Loads the coordinates of the entity from a dictionnary
"""
@ -364,18 +366,19 @@ class FightingEntity(Entity):
"""
Returns a fighting entities specific attributes
"""
return ["maxhealth", "health", "level", "dead", "strength", "intelligence", "charisma", "dexterity", "constitution"]
return ["maxhealth", "health", "level", "dead", "strength",
"intelligence", "charisma", "dexterity", "constitution"]
def save_state(self) -> dict:
"""
Saves the state of the entity into a dictionnary
Saves the state of the entity into a dictionary
"""
d = super().save_state()
for name in self.keys():
d[name] = self.__getattribute__(name)
return d
def recover_state(self, d : dict) -> None:
def recover_state(self, d: dict) -> None:
"""
Loads the state of an entity from a dictionary
"""

View File

@ -1,4 +1,3 @@
import sys
from enum import Enum
from typing import Any, Optional