예제 #1
0
def nextRound(g_id):
    print("********** attempting to move to next round...")
    #get game
    cGame = dbManager.getGameById(g_id)
    nextSeqNum = cGame.current_question_sequence_number + 1
    print("********** nextSeqNum is {}".format(str(nextSeqNum)))
    #getPlayersByGameId
    players = dbManager.getPlayersByGameId(g_id)

    #check if there are more questions
    if nextSeqNum < cGame.number_of_questions:
        print(
            "********** I'm in Next Round and my seq number before updating is {}"
            .format(str(cGame.current_question_sequence_number)))

        # more questions...
        # lets update the Game's... sequence_number_and_question ID automatically ahndled by
        # updateGameToNextQuestion
        dbManager.updateGameToNextQuestion(g_id)

        #Lets update the gamestate and send out next question
        moveToFakeAnswer(g_id)
        return True
    else:
        # build final message
        endGame2(g_id)
        return False
예제 #2
0
def moveToGuessTime(g_id):
    print("Moved To Guess Time")
    #Get Game Info by id
    curr_game = dbManager.getGameById(g_id)

    #Get All Answers from Table
    answers = dbManager.getPlayerAnswers(
        g_id, curr_game.current_question_sequence_number)

    #Build Response message
    str_response = "\r The following answers were given: \r"
    anum = 1

    #Also lets get the real answer
    curr_question = dbManager.getQuestion(curr_game.current_question_id)
    real_answer = curr_question.true_answer

    #first lets actually generate a random number between 1 and total num of answers
    rndNum = random.randint(1, len(answers))

    #lets loop through all the answers to...
    #1. Assign a numerical value to an answer (true and fake)
    #2. Create a response string
    for answer in answers:
        #if our anum variable = the random number, thats where we are going to insert
        #the real answer.
        if rndNum == anum:
            str_response = str_response + "{}. {}\r".format(
                anum, real_answer.lower())
            #lets store off the value that people will have to enter to select the right answer
            dbManager.updateQuestionRealAnswerGuessId(curr_question.id,
                                                      str(anum))
            anum = anum + 1

        str_response = str_response + "{}. {}\r".format(
            anum, answer.fake_answer)
        dbManager.updatePlayerAnswerFakeGuessId(answer.id, str(anum))
        anum = anum + 1

    str_response = str_response + "\r Reply with the answer number you think is correct."
    #K lets get the list of players
    players = dbManager.getPlayersByGameId(g_id)

    #Send Message With Question and Fake Answers
    for player in players:
        messageSender.sendMessage(player.mdn, str_response)

    #Update game state
    dbManager.updateGameState(g_id, "guesstime")
예제 #3
0
def sendResults(g_id):
    #get game
    curr_game = dbManager.getGameById(g_id)

    #get players & scores
    players = dbManager.getPlayersByGameId(g_id)

    str_response = "\r And the scores after the last round are: \r"
    #Build response.
    for player in players:
        str_response = str_response + "{} - {}\r".format(
            player.player_name, str(player.score))
        #str_response = str_response + "{} - {}\r".format(player.mdn, str(player.score))

    #Send Response
    for play in players:
        messageSender.sendMessage(play.mdn, str_response)
예제 #4
0
def startGame(g_id):
    #update game state
    dbManager.updateGameState(g_id, "fakeanswers")

    #get question
    question_1 = dbManager.getQuestionById(
        dbManager.getGameQuestionIdByGameId(g_id))
    instruction = "... \r Supply a fake answer for others to guess."
    #get player
    players = dbManager.getPlayersByGameId(g_id)
    current_q_num = 1 + dbManager.getGameQuestionSequenceNumber(g_id)

    for player in players:
        messageSender.sendMessage(
            player.mdn, "Question {}: \r".format(current_q_num) + question_1 +
            "{}".format(instruction))
        print("********** {}. Sent to {}".format(question_1, player.mdn))
예제 #5
0
def endGame2(g_id):
    #get game
    curr_game = dbManager.getGameById(g_id)

    #get players in order of score desc.
    winning_plr = dbManager.getWinningPlayer(g_id)

    #get players & scores
    players = dbManager.getPlayersByGameId(g_id)
    #Build Response message
    resp_msg = "\r Congratulations to {}, winning with a score of {} points!!!! Thanks for playing!".format(
        winning_plr.mdn, winning_plr.score)

    #Send Final Messsage
    for play in players:
        messageSender.sendMessage(play.mdn, resp_msg)

    #Update Game state
    dbManager.updateGameState(g_id, "complete")

    #removeAllPlayersFromGame
    rmvd_plyers = dbManager.removeAllPlayersFromGame(g_id)