示例#1
0
def add_game():
    game = request.get_json()
    newGame = Games(gameId=game["gameId"],
                    startTime=game["startTime"],
                    endTime=game["endTime"],
                    numOfPlayer=game["numOfPlayer"],
                    isCurrent=game["isCurrent"])
    newGame.save()
    return jsonify(newGame)
示例#2
0
def get_games():
    games = Games.objects
    isCurrent = request.args.get('isCurrent')

    if isCurrent == 'true':
        isCurrent = True
        return jsonify(Games.objects(isCurrent=isCurrent))
    elif isCurrent == 'false':
        isCurrent = False
        return jsonify(Games.objects(isCurrent=isCurrent))
    else:
        return jsonify(games)
示例#3
0
def receive_new_game_from_instructor(data):
    # Set all games to passed
    Games.objects.update(isCurrent=False)
    
    # Post only gameId here to current
    Games.objects(gameId=data).update(isCurrent=True)
    Users.objects(userType="Instructor").update(gamePlayed=data)

    # Remove all student users
    Users.objects(userType="Student").delete()

    send_broadcast_message_game_room(data)
示例#4
0
def delete_game():
    game = request.get_json()
    deletedGame = Games.objects(gameId=game["gameId"]).first()
    if not deletedGame:
        return jsonify({'error': 'data not found'})
    else:
        deletedGame.delete()
    return jsonify(deletedGame)
示例#5
0
def get_running_game():
    currentSession = request.sid
    gameData = Games.objects(isCurrent=True).only('gameId')
    currentGameIds = []
    
    for g in gameData:
        currentGameIds.append(g.gameId)

    emit('notification_game_room', format(currentGameIds), room = currentSession)
示例#6
0
def update_game():
    game = request.get_json()
    updateGame = Games.objects(gameId=game["gameId"]).first()

    if not updateGame:
        return jsonify({'error': 'data not found'})
    else:
        updateGame.update(startTime=game["startTime"],
                          endTime=game["endTime"],
                          numOfPlayer=game["numOfPlayer"],
                          isCurrent=game["isCurrent"])

    return jsonify(updateGame)
示例#7
0
def end_game(data):
    gameData = Games.objects(gameId=data,isCurrent=True)
    for g in gameData:
        g.update(isCurrent=False)
    emit('notification_endGame', data, broadcast=True)
示例#8
0
def get_game(id):
    game = Games.objects(gameId=id).first()
    return jsonify(game)