您好,我们在uni开设了一个项目,我们在其中开发了井字游戏。与原始版本的区别在于它是通过蓝牙连接的多人游戏,主机可以选择一组要使用的游戏。我已经可以连接两个设备,并且已经设置了游戏代码。但是,我似乎无法将一组游戏的按钮的值发送到其他设备。所选游戏集只能在主机设备上加载。谁能帮帮我吗。非常感谢
GameLobby.java
btnChoice1 = (Button) MyDialog.findViewById(R.id.btnChoice1);
btChoice1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PieceChoice = 1;
Toast.makeText(GameLobby.this, "Game piece chosen. Waiting for connection", Toast.LENGTH_LONG).show();
MyDialog.dismiss();
}
});
GameLobby.java上的处理程序
private final Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what)
{
case MESSAGE_DEVICE_NAME:
mChoice = msg.getData().getInt(FCHOICE);
switch (mChoice)
{
case 1:
loadGameBoard1();
break;
case 2:
loadGameBoard2();
break;
case 3:
loadGameBoard3();
break;
}
BluetoothService.java
Message msg = mHandler.obtainMessage(GameLobby.MESSAGE_DEVICE_NAME);
Bundle bundle = new Bundle();
int pieceChoice = GameLobby.PieceChoice;
bundle.putInt(GameLobby.FCHOICE, pieceChoice);
msg.setData(bundle);
mHandler.sendMessage(msg);