summaryrefslogtreecommitdiff
path: root/swiftstory/game_manager.py
diff options
context:
space:
mode:
authorOlivier Gayot <olivier.gayot@sigexec.com>2021-12-23 15:27:43 +0100
committerOlivier Gayot <olivier.gayot@sigexec.com>2021-12-23 23:15:21 +0100
commit82cd09e010783b81ec58145c7682f4b8da49ac85 (patch)
tree83b3e61aaa4befcd340a01b2fb147a2306bdb29e /swiftstory/game_manager.py
parent1be5c49ae402b768f9206724abdd503c18933ae1 (diff)
Use lowercase module names
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
Diffstat (limited to 'swiftstory/game_manager.py')
-rw-r--r--swiftstory/game_manager.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/swiftstory/game_manager.py b/swiftstory/game_manager.py
new file mode 100644
index 0000000..a87f67e
--- /dev/null
+++ b/swiftstory/game_manager.py
@@ -0,0 +1,37 @@
+import logging
+import os
+
+from swiftstory.exception import UnsupportedLanguage
+from swiftstory.game import Game
+from swiftstory.cards import Cards
+
+
+class GameManager:
+ def __init__(self):
+ self.langs = {}
+
+ for filename in next(os.walk('usr/share/swiftstory/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:
+ raise UnsupportedLanguage(lang)
+
+ 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:
+ logging.info("Starting new game: %s (lang: %s)", game_name, lang)
+
+ game = games[game_name] = Game(white_cards, black_cards)
+
+ return game