Android Open Source - hackfmi-ragdoll-physics Client Strategy






From Project

Back to project page hackfmi-ragdoll-physics.

License

The source code is released under:

GNU General Public License

If you think the Android project hackfmi-ragdoll-physics listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.midtownmadness.bubblecombat.multiplay;
//  ww w.  ja v a2 s  . c om
import static com.midtownmadness.bubblecombat.Settings.HOST_ID;

import java.io.IOException;
import java.net.ConnectException;

import com.midtownmadness.bubblecombat.Settings;
import com.midtownmadness.bubblecombat.multiplay.commobjects.GoMessageObject;

import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.content.Context;

public class ClientStrategy extends BaseStrategy {

  private BluetoothDevice device;

  private Callback<BluetoothSocket> callback;

  public ClientStrategy(Context context, BluetoothDevice device,
      Callback<BluetoothSocket> callback, MultiplayManager manager) {
    super(context, manager);
    this.device = device;
    this.callback = callback;

  }

  @Override
  public void handshakeAndLoad() {
    getHandler().post(new Runnable() {

      @Override
      public void run() {
        try {
          otherPlayer = device
              .createInsecureRfcommSocketToServiceRecord(MultiplayManager.UUID);
          toast("Host socket found " + otherPlayer.toString());

        } catch (IOException e) {
          e.printStackTrace();
        } finally {
          callback.call(otherPlayer);
        }
      }
    });
  }

  @Override
  public void onLooperReady() {
    handshakeAndLoad();
  }

  @Override
  public void close() {
    toast("close");
    try {
      if (otherPlayer != null) {
        otherPlayer.getInputStream().close();
        otherPlayer.getOutputStream().close();
        otherPlayer.close();
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
  }

  @Override
  public void commenceGame() {
    getHandler().post(new Runnable() {

      @Override
      public void run() {
        try {
          otherPlayer.connect();
        } catch (IOException e) {
          toast("Network error");
          e.printStackTrace();
        }
        onPlayerConnected(HOST_ID, otherPlayer);

        sendEmptyMessage(MessageType.JOIN_GAME, getConnectedPlayers()
            .get(Settings.HOST_ID));

        final BluetoothMessage response = obtainMessage(otherPlayer);
        if (response.messageType == MessageType.GO) {
          final GoMessageObject meta = (GoMessageObject) response.payload;
          manager.onGameCommenced(meta.timestamp);
        }
      }
    });
  }
}




Java Source Code List

com.midtownmadness.bubblecombar.listeners.GameRoomListener.java
com.midtownmadness.bubblecombar.model.GameModel.java
com.midtownmadness.bubblecombar.model.GamesAdapter.java
com.midtownmadness.bubblecombar.model.MockAdapter.java
com.midtownmadness.bubblecombat.BaseActivity.java
com.midtownmadness.bubblecombat.BluetoothGamesAdapter.java
com.midtownmadness.bubblecombat.GameActivity.java
com.midtownmadness.bubblecombat.GameView.java
com.midtownmadness.bubblecombat.GlobalContext.java
com.midtownmadness.bubblecombat.MenuActivity.java
com.midtownmadness.bubblecombat.MockMultiplayerGame.java
com.midtownmadness.bubblecombat.Settings.java
com.midtownmadness.bubblecombat.game.DrawThread.java
com.midtownmadness.bubblecombat.game.GameObject.java
com.midtownmadness.bubblecombat.game.GameWallObject.java
com.midtownmadness.bubblecombat.game.LevelObject.java
com.midtownmadness.bubblecombat.game.PlayerObject.java
com.midtownmadness.bubblecombat.multiplay.BaseStrategy.java
com.midtownmadness.bubblecombat.multiplay.BluetoothConnectException.java
com.midtownmadness.bubblecombat.multiplay.BluetoothMessage.java
com.midtownmadness.bubblecombat.multiplay.Callback.java
com.midtownmadness.bubblecombat.multiplay.ClientStrategy.java
com.midtownmadness.bubblecombat.multiplay.HostStrategy.java
com.midtownmadness.bubblecombat.multiplay.LoggingListener.java
com.midtownmadness.bubblecombat.multiplay.LooperThread.java
com.midtownmadness.bubblecombat.multiplay.MessageType.java
com.midtownmadness.bubblecombat.multiplay.MultiplayEventListener.java
com.midtownmadness.bubblecombat.multiplay.MultiplayEvent.java
com.midtownmadness.bubblecombat.multiplay.MultiplayManager.java
com.midtownmadness.bubblecombat.multiplay.MultiplayStrategy.java
com.midtownmadness.bubblecombat.multiplay.MultiplayUtil.java
com.midtownmadness.bubblecombat.multiplay.MultiplayerGame.java
com.midtownmadness.bubblecombat.multiplay.commobjects.GoMessageObject.java
com.midtownmadness.bubblecombat.physics.BodyCreationRequest.java
com.midtownmadness.bubblecombat.physics.BodyUserData.java
com.midtownmadness.bubblecombat.physics.CentralHurdle.java
com.midtownmadness.bubblecombat.physics.CollisionListener.java
com.midtownmadness.bubblecombat.physics.DefaultLevelBuilder.java
com.midtownmadness.bubblecombat.physics.LevelBuilder.java
com.midtownmadness.bubblecombat.physics.MovementRequest.java
com.midtownmadness.bubblecombat.physics.MovementStateRequest.java
com.midtownmadness.bubblecombat.physics.PhysicsRequest.java
com.midtownmadness.bubblecombat.physics.PhysicsService.java
com.midtownmadness.bubblecombat.views.MenuGameView.java
com.midtownmadness.bubblecombat.views.MenuView.java