main (#1)
Reviewed-on: #1 Co-authored-by: Daniel Dolezal <d.dolezal97@protonmail.com> Co-committed-by: Daniel Dolezal <d.dolezal97@protonmail.com>
This commit was merged in pull request #1.
This commit is contained in:
+12
-3
@@ -1,8 +1,10 @@
|
||||
from server.Files import save_file
|
||||
import os
|
||||
|
||||
class GameStorage:
|
||||
def __init__(self, snake:str):
|
||||
def __init__(self, snake:str, path:str):
|
||||
self.snake_type = snake
|
||||
self.folder = path
|
||||
|
||||
def start_new_game(self, game_type:dict, game_board:dict, snake:dict):
|
||||
self.game_type = game_type
|
||||
@@ -18,8 +20,14 @@ class GameStorage:
|
||||
self.game_board.append(game_board)
|
||||
self.snake_history = snake_history_state
|
||||
|
||||
def set_winner_snake_name(self, snakes:list[dict]):
|
||||
if self.start_position["id"] in [ x["id"] for x in snakes]:
|
||||
self.winner_snake_names = "me"
|
||||
else:
|
||||
self.winner_snake_names = [ x["name"] for x in snakes]
|
||||
|
||||
def save(self, path:str, callback=None, **kwargs):
|
||||
save_file(path, {
|
||||
save_file(os.path.join(self.folder, path), {
|
||||
"snake": {
|
||||
"type": self.snake_type,
|
||||
"choices": self.snake_history,
|
||||
@@ -29,5 +37,6 @@ class GameStorage:
|
||||
"snake_start": self.start_position,
|
||||
"gameboard": self.game_board,
|
||||
"my_moves": self.moves,
|
||||
}
|
||||
},
|
||||
"winner": self.winner_snake_names,
|
||||
}, callback=callback, **kwargs)
|
||||
|
||||
Reference in New Issue
Block a user