예제 #1
0
파일: server.py 프로젝트: mfilmer/dominion
 def __init__(self, args, chanceCards):
     self.users = {}
     self.game = None
     self.maxPlayers = args.players
     self._args = args
     self._cardList = CardList()
     self._chanceCards = chanceCards
예제 #2
0
파일: server.py 프로젝트: mfilmer/dominion
class GameFactory(Factory):
    def __init__(self, args, chanceCards):
        self.users = {}
        self.game = None
        self.maxPlayers = args.players
        self._args = args
        self._cardList = CardList()
        self._chanceCards = chanceCards

    def buildProtocol(self, addr):
        return Player(self, self.users, self.maxPlayers)

    def getFullText(self, cardName):
        print("Getting full text for: " + cardName)
        return self._cardList.getCardText(cardName)

    def startGame(self):
        print("Starting Game...")
        chance = False
        if random.randint(0, 1) == 0:
            print("Playing with chance cards")
            chance = True
        self.game = Dominion.game(
            self.users.keys(),
            onlyWorking=self._args.workingCardsOnly,
            expansions=self._args.expansions,
            useChance=self._chanceCards,
        )
        turn = self.game.next()
        players = self.game.getPlayers()
        stores = self.game.getStores()
        dStores = {}
        for store in stores:
            try:
                dStores[store.getName()] = (store.getCost(), len(store))
            except OverflowError:
                dStores[store.getName()] = (store.getCost(), u"\u221E")
        stores = repr(dStores)
        currentPlayerName = turn.getPlayer().getName()
        print("starting player: " + currentPlayerName)
        for name, protocol in self.users.iteritems():
            protocol.sendLine("starting")
            protocol.player = [p for p in players if p.getName() == name][0]
            protocol.updatePiles(["Hand"])
            protocol.updateStash()
            protocol.sendLine("data: store: " + stores)
            if name == currentPlayerName:
                protocol.sendLine("your turn")
                protocol.phase = "Action"
            else:
                protocol.sendLine("turn: " + currentPlayerName)
                protocol.phase = "Wait"