Merge branch 'master' into 'ladders'
# Conflicts: # squirrelbattle/game.py # squirrelbattle/interfaces.py # squirrelbattle/tests/game_test.py
This commit is contained in:
@ -31,7 +31,7 @@ class Game:
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""
|
||||
Init the game.
|
||||
Initiates the game.
|
||||
"""
|
||||
self.state = GameMode.MAINMENU
|
||||
self.waiting_for_friendly_key = False
|
||||
@ -50,7 +50,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.maps = []
|
||||
@ -85,8 +85,8 @@ class Game:
|
||||
def run(self, screen: Any) -> None: # pragma no cover
|
||||
"""
|
||||
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.
|
||||
"""
|
||||
screen.refresh()
|
||||
while True:
|
||||
@ -105,7 +105,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:
|
||||
@ -127,6 +127,8 @@ class Game:
|
||||
self.settings_menu.handle_key_pressed(key, raw_key, self)
|
||||
elif self.state == GameMode.STORE:
|
||||
self.handle_key_pressed_store(key)
|
||||
elif self.state == GameMode.CREDITS:
|
||||
self.state = GameMode.MAINMENU
|
||||
self.display_actions(DisplayActions.REFRESH)
|
||||
|
||||
def handle_key_pressed_play(self, key: KeyValues) -> None:
|
||||
@ -135,16 +137,16 @@ class Game:
|
||||
"""
|
||||
if key == KeyValues.UP:
|
||||
if self.player.move_up():
|
||||
self.map.tick()
|
||||
self.map.tick(self.player)
|
||||
elif key == KeyValues.DOWN:
|
||||
if self.player.move_down():
|
||||
self.map.tick()
|
||||
self.map.tick(self.player)
|
||||
elif key == KeyValues.LEFT:
|
||||
if self.player.move_left():
|
||||
self.map.tick()
|
||||
self.map.tick(self.player)
|
||||
elif key == KeyValues.RIGHT:
|
||||
if self.player.move_right():
|
||||
self.map.tick()
|
||||
self.map.tick(self.player)
|
||||
elif key == KeyValues.INVENTORY:
|
||||
self.state = GameMode.INVENTORY
|
||||
elif key == KeyValues.SPACE:
|
||||
@ -205,8 +207,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
|
||||
@ -295,7 +298,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()
|
||||
@ -320,13 +323,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)
|
||||
@ -350,7 +353,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):
|
||||
@ -367,7 +370,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()))
|
||||
|
Reference in New Issue
Block a user