Beispiel #1
0
def check_game_reqst_response(message):
    game_object = sf.get_game(message['user']['username'])
    return_obj = {
                  'type': 'check_game_reqst_resp',
                  'id'  : message['id'],
                  'game' : game_object
                 }
    return return_obj
Beispiel #2
0
def start_game_resp_response(message):
    game_object = None
    username = message['user']['username'].encode("utf8")
    game = sf.get_game(username)
    if game != None and message['response'] is True:
        sf.update_game_attribute(game['user1'], game['user2'], 'responded', True)
        sf.update_game_attribute(game['user1'], game['user2'], 'response', True)
        game_object = sf.get_game(username)
        sf.update_user_attribute(username, 'in_game', True)
    elif game != None:
        sf.update_game_attribute(game['user1'], game['user2'], 'responded', True)
        sf.update_game_attribute(game['user1'], game['user2'], 'response', False)
        game_object = sf.get_game(username)
        sf.remove_game(game_object['user1'], game_object['user2'])
        sf.update_user_attribute(game_object['user1'], 'in_game', False)
        sf.update_user_attribute(game_object['user2'], 'in_game', False)
    return_obj = {
                  'type': 'start_game_resp_resp',
                  'id'  : message['id'],
                  'game' : game_object
                 }
    return return_obj
Beispiel #3
0
def game_move_response(message):
    player_move = 'pos'+str(message['move'])
    game_object = sf.get_game(message['user']['username'])
    game_object['game_board'][player_move] = 1 if game_object['turn'] == game_object['user1'] else 2
    is_win = sf.is_win(game_object)
    if is_win is None:
        game_object['winner'] = None
        game_object['game_over'] = True
    if is_win is True:
        game_object['winner'] = game_object['turn']
        game_object['game_over'] = True
    game_object['turn'] = game_object['user2'] if game_object['turn'] == game_object['user1'] else game_object['user1'];

    sf.update_game(game_object['user1'], game_object['user2'], game_object)
    #update board, update turn, update win state
    return_obj = {
                  'type': 'game_move_resp',
                  'id'  : message['id'],
                  'game' : game_object
                 }
    return return_obj
Beispiel #4
0
def game_object_reqst_response(message):
    game_object = sf.get_game(message['user']['username'])
    if game_object != None and game_object['game_over'] is True:
        username1 = game_object['user1']
        username2 = game_object['user2']
        winner = game_object['winner']
        if winner == username1:
            sf.update_user_attribute(username1, 'win_value', sf.get_user(username1)['win_value']+1)
            sf.update_user_attribute(username2, 'lose_value', sf.get_user(username2)['lose_value']+1)
        elif winner == username2:
            sf.update_user_attribute(username1, 'lose_value', sf.get_user(username1)['lose_value']+1)
            sf.update_user_attribute(username2, 'win_value', sf.get_user(username2)['win_value']+1)
        else:
            sf.update_user_attribute(username1, 'draw_value', sf.get_user(username1)['draw_value']+1)
            sf.update_user_attribute(username2, 'draw_value', sf.get_user(username2)['draw_value']+1)
        sf.update_user_attribute(username1, 'in_game', False)
        sf.update_user_attribute(username2, 'in_game', False)
        sf.remove_game(game_object['user1'], game_object['user2'])
    return_obj = {
                  'type': 'game_object_reqst_resp',
                  'id'  : message['id'],
                  'game' : game_object
                 }
    return return_obj