I have a round-based Multiplayer game for Android that has been working over XMPP before, and I want to switch to Google Play Game Services. In the old version, there was an XMPP bot, deciding which player will be player 1 or 2. This is important to know which player should make the first move.
With Google Play Game Services, I found a solution that nearly works:
@Override
public void onRoomConnected(int statusCode, Room room) {
ArrayList<Participant> participants = room.getParticipants();
Participant first = participants.get(0);
if (first.getPlayer() == null || !first.getPlayer().getPlayerId().equals(myPlayerId)) {
LaskaField.HUMAN_PLAYER = 2;
LaskaField.OTHER_PLAYER = 1;
opponent = first.getDisplayName();
} else {
LaskaField.HUMAN_PLAYER = 1;
LaskaField.OTHER_PLAYER = 2;
opponent = participants.get(1).getDisplayName();
}
setPlayerNames();
}
This way works fine when inviting another player. However, it often fails when both players select auto-matching. In this case, both players are on the same position in the participants ArrayList. Therefore, they will both appear as the same player on their currently used device.
What is the right way to select player 1 and 2, with no central instance for deciding this. Is there any useful data in the participants list that I didn't find with the debugger?