team picking things

This commit is contained in:
Sem van der Hoeven
2020-06-07 14:42:39 +02:00
parent 0af0ca02b6
commit 79a0348a84

View File

@@ -355,15 +355,26 @@ public class MainGame extends Game implements ClientCallback {
public void onDataReceived(Data data) { public void onDataReceived(Data data) {
System.out.println("[MAINGAME CALLBACK] Got data: " + data.toString()); System.out.println("[MAINGAME CALLBACK] Got data: " + data.toString());
if (data instanceof NameData) { if (data instanceof NameData) {
System.out.println("[MAINGAME CALLBACK] got name data: " + data);
this.username = ((NameData) data).getName(); this.username = ((NameData) data).getName();
System.out.println("[MAINGAME CALLBACK] username is: " + username); System.out.println("[MAINGAME CALLBACK] username is: " + username);
} else if (data instanceof TeamData) { } else if (data instanceof TeamData) {
// check if it is not our own message
if (!((TeamData) data).getUsername().equals(this.username)) {
// if we have already chosen a faction, so we were first
if (this.chosenFaction != null) { if (this.chosenFaction != null) {
TeamData teamData = (TeamData) data;
if (this.chosenFaction != teamData.getFaction()) {
// other player chose other faction
initCharacters();
setGamestate(GAMESTATE.PLAYING);
} else {
// other player chose same faction, send back that that one
// was already taken
}
} else { } else {
} }
}
} }