From 0fb08748e5285e5d4adc6135eec8889887a63299 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Sun, 14 Jun 2015 22:31:48 +0100 Subject: use a python package instead of just modules The package is contained in the CAO/ folder. server.py is still at the root of the repository though. Signed-off-by: Olivier Gayot --- CAO/GameManager.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 CAO/GameManager.py (limited to 'CAO/GameManager.py') diff --git a/CAO/GameManager.py b/CAO/GameManager.py new file mode 100644 index 0000000..5600f1e --- /dev/null +++ b/CAO/GameManager.py @@ -0,0 +1,34 @@ +from CAO.Game import Game +from CAO.Cards import Cards + +import os + +class GameManager(): + def __init__(self): + self.langs = {} + + for filename in next(os.walk('lang'))[1]: + self.langs[filename] = {} + + for lang in self.langs: + self.langs[lang]['black_cards'] = Cards.get_black_cards(lang) + self.langs[lang]['white_cards'] = Cards.get_white_cards(lang) + + self.langs[lang]['games'] = {} + + def join_game(self, game_name, lang): + if self.langs.get(lang) is None: + return None + + games = self.langs[lang]['games'] + black_cards = self.langs[lang]['black_cards'] + white_cards = self.langs[lang]['white_cards'] + + game = games.get(game_name) + + if game is None: + print('Starting new game') + + game = games[game_name] = Game(white_cards, black_cards) + + return game -- cgit v1.2.3