コード例 #1
0
ファイル: ViewProxy.java プロジェクト: zspotter/Abalone
    @Override
    public void run() {
      try {
        while (true) {
          // Get next message from client.
          Object msg = _in.readObject();

          // If this client hasn't joined the game yet, only accept
          // join requests.
          if (_viewListener == null) {
            if (msg instanceof RequestJoin) {
              SessionManager.joinGame(ViewProxy.this, ((RequestJoin) msg).getGameId());
            }
            // Skip other message checks.
            continue;
          }

          // Listen for only AbaloneMessage's
          if (!(msg instanceof AbaloneMessage)) continue;

          if (msg instanceof RequestMove) {
            _viewListener.requestMove((RequestMove) msg);
          } else if (msg instanceof RequestLeave) {
            _viewListener.leaveGame();
          }
        }
      } catch (IOException e) {
      } catch (ClassNotFoundException e) {
      } finally {
        if (_viewListener != null) _viewListener.leaveGame();
      }
    }