示例#1
0
    def gameStub(self):

        print("Welcome to {} Engine Stub".format(self.getGame()))

        if not db.isConnected():
            db.connectDB("../db/gamelog.db")

        playersOrder = []
        validPlayers = db.getPlayerNicks()
        maxPlayers = self.getGameMaxPlayers()

        nplayers = readInput(
            "Number of players: ",
            int,
            lambda x: x >= 2 and x <= maxPlayers,
            "Sorry, number of players must be between 2 and {}.".format(self.getGameMaxPlayers()),
        )

        for i in range(1, nplayers + 1):
            print("Player {} Info:".format(i))
            nick = readInput("Nick: ", str, lambda x: x in validPlayers, "Sorry, player not found in DB")
            self.addPlayer(nick)
            playersOrder.append(nick)

        self.begin()
        option = readInput("Dealing policy[0:None/1:RoundRobin/2:Winner]: ", int, lambda x: x in [0, 1, 2])
        if option == 0:
            self.setDealingPolicy(RoundGameEngine.NoDealer)
        elif option == 1:
            self.setDealingPolicy(RoundGameEngine.RRDealer)
        elif option == 2:
            self.setDealingPolicy(RoundGameEngine.WinnerDealer)
        self.extraStubConfig()
        self.runStubRoundLoop()
示例#2
0
            
        for idMatch,match in self.candidates.items():
            cur = db.execute("SELECT nick FROM MatchPlayer WHERE idMatch={}".format(idMatch))
            for row in cur:
                match['players'].append(str(row['nick']))

    def getCandidates(self): return self.candidates
    
    def resume(self,idMatch):
        engine = GameEngineFactory.createMatch(self.game)
        if engine and engine.resume(idMatch): return engine
        return None
        
        
if __name__ == "__main__":
    if not db.isConnected(): db.connectDB("../db/gamelog.db")
    game = readInput('Game to play (Phase10/Phase10Master/Remigio/Ratuki/Carcassone): ',str,lambda x: x in ['Phase10','Phase10Master','Remigio','Ratuki','Carcassone'])
    re = ResumeEngine(game)
    candidates = re.getCandidates()
    if not len(candidates):
        print("No {} matches to restore found".format(game))
        exit()
    else:
        print("Matches to restore:")
        for idMatch,match in candidates.items():
            print("{}) {} player match started at {}. Time played: {}. Players:{}".format(idMatch,len(match['players']),match['started'],match['elapsed'],match['players']))
        print("")
        idMatch = readInput('idMatch to resume: ',int,lambda x: x in candidates.keys())
        print("Restoring match #{}".format(idMatch))
        engine = re.resume(idMatch)
        if not engine:
示例#3
0
                "SELECT nick FROM MatchPlayer "
                "WHERE idMatch={}".format(idMatch))
            for row in cur:
                match['players'].append(str(row['nick']))

    def getCandidates(self): return self.candidates

    def resume(self, idMatch):
        engine = GameEngineFactory.createMatch(self.game)
        if engine and engine.resume(idMatch):
            return engine
        return None


if __name__ == "__main__":
    if not db.isConnected():
        db.connectDB("../db/gamelog.db")
    pmt = 'Game to play (Phase10/Phase10Master/Remigio/Ratuki/Carcassone): '
    game = readInput(pmt, str, lambda x: x in ['Phase10',
                                               'Phase10Master',
                                               'Remigio',
                                               'Ratuki',
                                               'Carcassone'])
    re = ResumeEngine(game)
    candidates = re.getCandidates()
    if not len(candidates):
        print("No {} matches to restore found".format(game))
        exit()
    else:
        print("Matches to restore:")
        for idMatch, match in candidates.items():