Android multiplayer bluetooth

a 夏天 提交于 2020-01-02 21:50:08

问题


I'm trying to develop a simple multiplayer game using bluetooth with Eclipse
The game is already working in single player mode (using AndEngine), but now I need to send information between devices.
The part that concerns establishing connection between devices,and link them
is already working, and I can send messages between devices, but now I need to
start the game on "the other" device, so I think that the solution is sending an Intent
using Bluetooth, but I'm not sure if this is possible or not.
So, how can I start the game in both devices at the same time? (I don't want the game in real time, I just want to compare the number of coins that each player gets).

Thank you very much!


回答1:


If you see the "Uno" game, you'll get some idea. There, they aren't using Bluetooth, but WiFi. From that I learned, and some other bluetooth games that you wait for Connection successful.

If you're using BluetoothChat application as the reference, then use your Handler as your event generator to start your game.

    // The Handler that gets information back from the BluetoothChatService
private final Handler mHandler = new Handler() {
    @Override
    public void handleMessage(Message msg) {
        switch (msg.what) {
        case MESSAGE_STATE_CHANGE:
            if(D) Log.i(TAG, "MESSAGE_STATE_CHANGE: " + msg.arg1);
            switch (msg.arg1) {
            case BluetoothChatService.STATE_CONNECTED:
                setStatus(getString(R.string.title_connected_to, mConnectedDeviceName));
                mConversationArrayAdapter.clear();

                // DO YOUR ACTIVITY HERE .. .. 
                // May Be like ...  Intent intent = new Intent( ... )


                break;


来源:https://stackoverflow.com/questions/16500502/android-multiplayer-bluetooth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!