您好,我们正在开发通过蓝牙进行的 Android 多人游戏。这是一款多人 LUDO 游戏,4 名玩家相互连接并玩游戏。
我们被困在第三个和第四个玩家的连接中。
private OnMaxConnectionsReachedListener maxConnectionsListener = new OnMaxConnectionsReachedListener() {
public void OnMaxConnectionsReached() {
}
};
private OnIncomingConnectionListener connectedListener = new OnIncomingConnectionListener() {
public void OnIncomingConnection(String device) {
//rivalDevice = device;
if(index < 1000)
{
clients[index] = device;
index++;
Log.d("Khawar", "Khawar"+device);
if(index == 1)
{
//blue.setText(clients[0]);
mConnection.sendMessage(clients[0], "ConnectionList--Ludofyp309509--"+server+"--Ludofyp309509--"+clients[0]);
}
else if(index == 2)
{
//blue.setText(clients[0]);
//red.setText(clients[1]);
mConnection.sendMessage(clients[0], "ConnectionList--Ludofyp309509--"+server+"--Ludofyp309509--"+clients[0]+"--Ludofyp309509--"+clients[1]);
mConnection.sendMessage(clients[1], "ConnectionList--Ludofyp309509--"+server+"--Ludofyp309509--"+clients[0]+"--Ludofyp309509--"+clients[1]);
}
else if(index==3)
{
//blue.setText(clients[0]);
//red.setText(clients[1]);
//yellow.setText(clients[2]);
mConnection.sendMessage(clients[0], "ConnectionList--Ludofyp309509--"+server+"--Ludofyp309509--"+clients[0]+"--Ludofyp309509--"+clients[1]+"--Ludofyp309509--"+clients[2]);
mConnection.sendMessage(clients[1], "ConnectionList--Ludofyp309509--"+server+"--Ludofyp309509--"+clients[0]+"--Ludofyp309509--"+clients[1]+"--Ludofyp309509--"+clients[2]);
mConnection.sendMessage(clients[2], "ConnectionList--Ludofyp309509--"+server+"--Ludofyp309509--"+clients[0]+"--Ludofyp309509--"+clients[1]+"--Ludofyp309509--"+clients[2]);
}
}
//Toast.makeText(getBaseContext(), …
Run Code Online (Sandbox Code Playgroud) android bluetooth android-emulator android-contentresolver android-layout