# Conflicts:
#	core/src/netwerkprog/game/client/game/map/GameInputProcessor.java
This commit is contained in:
MickWerf
2020-06-07 15:04:53 +02:00
4 changed files with 34 additions and 10 deletions

View File

@@ -227,8 +227,8 @@ public class MainGame extends Game implements ClientCallback {
private void renderTurnText() {
String text = playersTurn ? "Your turn, moves left: " + (3 - this.turn) : "Other player's turn";
layout.setText(font,text);
textRenderer.render(text, (Gdx.graphics.getWidth() / 2f) - layout.width / 2f,Gdx.graphics.getHeight() - 3);
layout.setText(font, text);
textRenderer.render(text, (Gdx.graphics.getWidth() / 2f) - layout.width / 2f, Gdx.graphics.getHeight() - 3);
}
/**
@@ -353,20 +353,31 @@ public class MainGame extends Game implements ClientCallback {
@Override
public void onDataReceived(Data data) {
System.out.println("[MAINGAME CALLBACK] Got data: " + data.toString());
System.out.println("[MAINGAME" + this.username + "] Got data: " + data.toString());
if (data instanceof NameData) {
System.out.println("[MAINGAME CALLBACK] got name data: " + data);
this.username = ((NameData) data).getName();
System.out.println("[MAINGAME CALLBACK] username is: " + username);
System.out.println("[MAINGAME" + this.username + "] username is: " + username);
} else if (data instanceof TeamData) {
if (this.chosenFaction != null) {
} else {
// 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) {
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 {
}
}
}
}
public String getUsername() {

View File

@@ -10,6 +10,7 @@ import com.badlogic.gdx.utils.TimeUtils;
import netwerkprog.game.client.MainGame;
import netwerkprog.game.client.game.GAMESTATE;
import netwerkprog.game.util.data.Data;
import netwerkprog.game.util.data.connection.ReadyData;
import netwerkprog.game.util.data.connection.TeamData;
import netwerkprog.game.util.game.Faction;
import netwerkprog.game.util.game.GameCharacter;
@@ -132,6 +133,7 @@ public class GameInputProcessor implements InputProcessor {
// camera.translate(-400, 0);
// mainGame.setGamestate(GAMESTATE.PLAYING);
}
mainGame.send(new ReadyData());
}
return false;

View File

@@ -87,12 +87,14 @@ public class SessionController extends Controller implements DataCallback {
}
}
System.out.println("[SERVER] got username " + username);
username = "player" + (this.clients.size() + 1);
System.out.println("[SERVER] set username " + username);
ServerClient serverClient = new ServerClient(username, inputStream, outputStream, this);
Thread t = new Thread(serverClient);
t.start();
serverClient.writeData(new NameData(username));
this.clientThreads.put(username,t);
this.clients.add(serverClient);
} catch (IOException | ClassNotFoundException ex) {

View File

@@ -0,0 +1,9 @@
package netwerkprog.game.util.data.connection;
import netwerkprog.game.util.data.Data;
public class ReadyData extends Data {
public ReadyData() {
super("ready");
}
}