Пример #1
0
def watch_game(conn, game_id, trans=None):
    user = conn.data['user']
    game = Game.getGameById(game_id)

    # TODO: what if game is not in memory, but in the database?
    
    #if user.getGameById(game_id) is None:
    if game is not None:
        user.enterGame(game)
        response = GameOk.you_can_watch()
    else:
        response = GameError.game_not_found()
    #else:
    #    response = GameOk.you_are_already_in_the_game()
        
    conn.send(response, trans)
Пример #2
0
def resign(conn, game_id, trans=None):
    player = conn.data["user"]
    game = player.getGameById(game_id)

    if game is not None:
        player_name = player.db_tuple.name

        if player_name in [game._config.black, game._config.white]:
            if game.resign(player):
                response = GameOk.ok_resign()
            else:
                response = GameError.error_resign()
        else:
            response = GameError.not_your_game()
    else:
        response = GameError.user_doesnt_know_game_id()

    conn.send(response, trans)
Пример #3
0
 def callback(valid):
     if valid:
         response = GameOk.ok_move()
     else:
         response = GameError.invalid_move()
     conn.send(response, trans)