summaryrefslogtreecommitdiff
path: root/swiftstory/GameManager.py
blob: a7098bc1657205eb5157f082ae3d9e5d5c31bdd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import logging
import os

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:
            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:
            logging.info("Starting new game: %s (lang: %s)", game_name, lang)

            game = games[game_name] = Game(white_cards, black_cards)

        return game