Esempio n. 1
0
def chooseWord(index):
    currGame = games[rooms[request.sid]]
    if (request.sid != currGame['order'][currGame['currDrawer']]
            or currGame['currWord'] != ''):
        return
    Game.chooseWord(currGame, index)
    currGame['timerTime'] = currGame['maxTime']  #Start drawing
    emit('startDrawing')
    send('<b>You have chosen ' + currGame['currWord'] + '</b>')
    currGame['currLines'] = []
    emit('clearBoard', None, broadcast=True, room=rooms[request.sid])
    emit('untint', broadcast=True, room=rooms[request.sid])
Esempio n. 2
0
def countdown():
    global continueTimer, timerTime
    if continueTimer:
        threading.Timer(1, countdown).start()
        gamesCopy = list(
            games
        )  #Used because gamesCopy will not be modified as the for loop is executed
        #Execute the following tasks every second
        for roomID in gamesCopy:
            try:
                currGame = games[roomID]
                # print(currGame['order'], currGame['currDrawer'], currGame['players'])
                currGame['timerTime'] -= 1
                if currGame['timerTime'] <= -1:
                    # print(currGame['gameState'])
                    if currGame[
                            'gameState'] == Game.DRAWING:  #Executed when time runs out as a player is drawing
                        nextTurn(currGame, roomID)
                    elif currGame[
                            'gameState'] == Game.CHOOSING:  #Executed when time runs out as a player is choosing a word
                        Game.chooseWord(currGame, None)
                        currGame['guessedCorrectly'] = set()
                        currGame['timerTime'] = currGame[
                            'maxTime']  #Start drawing
                        socketio.send(
                            '<b>You have chosen ' + currGame['currWord'] +
                            '</b>',
                            room=currGame['order'][currGame['currDrawer']])
                        socketio.emit(
                            'startDrawing',
                            room=currGame['order'][currGame['currDrawer']])
                        currGame['currLines'] = []
                        socketio.emit('clearBoard', None, room=roomID)
                        socketio.emit('untint', room=roomID)
                # print(games[roomID]['timerTime'])
                socketio.emit('updateTimer',
                              currGame['timerTime'],
                              room=roomID)
            except:
                continue