replace game_lists with games_list

This commit is contained in:
Thomas Rubini 2022-11-29 12:07:54 +01:00
parent 1bcc552756
commit 657a90955f
No known key found for this signature in database
GPG Key ID: C7D287C8C1CAC373

View File

@ -5,8 +5,8 @@ from datetime import datetime, timedelta
import truthseeker import truthseeker
# Map of all actively running games # Map of all actively running games
# game_lists["game.id"]-> game info linked to that id # games_list["game.id"]-> game info linked to that id
game_lists = {} games_list = {}
def random_string(length: int) ->str: def random_string(length: int) ->str:
""" """
@ -70,7 +70,7 @@ class GameInfo:
def create_game(): def create_game():
""" """
This function creates a new game by creating a GameInfo object and stores This function creates a new game by creating a GameInfo object and stores
it into the game_lists dictionnary it into the games_list dictionnary
: return : a new GameInfo : return : a new GameInfo
: return type : GameInfo : return type : GameInfo
@ -78,13 +78,13 @@ def create_game():
game = GameInfo() game = GameInfo()
game.id = random_string(6) game.id = random_string(6)
game.start_token = random_string(64) game.start_token = random_string(64)
game_lists[game.id] = game games_list[game.id] = game
#TODO ADD A WEBSOCKET IF THE GAME IS KNOWN TO BE MULTIPLAYER #TODO ADD A WEBSOCKET IF THE GAME IS KNOWN TO BE MULTIPLAYER
return game return game
def get_game(game_id): def get_game(game_id):
if game_id in game_lists: if game_id in games_list:
return game_lists[game_id] return games_list[game_id]
else: else:
return None return None
@ -98,7 +98,7 @@ def get_game_info(game_id):
: return : The GameInfo Object linked to the game_id : return : The GameInfo Object linked to the game_id
: return type : GameInfo : return type : GameInfo
""" """
if game_id in game_lists: if game_id in games_list:
return game_lists[game_id] return games_list[game_id]
else: else:
return None return None