fixed bugs so the programm would start and added some Todo where code is missing or was fraudulent

This commit is contained in:
Hanno Fleischer
2024-11-27 09:19:57 +01:00
parent 20c9000d56
commit c9362a7a95
7 changed files with 31 additions and 15 deletions

View File

@@ -2,6 +2,7 @@
import pp.mdga.client.view.GameView; import pp.mdga.client.view.GameView;
import pp.mdga.client.view.LobbyView; import pp.mdga.client.view.LobbyView;
import pp.mdga.notification.*;
import java.util.ArrayList; import java.util.ArrayList;

View File

@@ -5,7 +5,7 @@
import pp.mdga.game.Game; import pp.mdga.game.Game;
import pp.mdga.game.Player; import pp.mdga.game.Player;
import pp.mdga.message.client.*; import pp.mdga.message.client.*;
import pp.mdga.message.server.ServerMessage; import pp.mdga.message.server.*;
import pp.mdga.server.ServerGameLogic; import pp.mdga.server.ServerGameLogic;
import pp.mdga.server.ServerSender; import pp.mdga.server.ServerSender;
@@ -108,7 +108,7 @@ private void initializeSerializables() {
Serializer.registerClass(AnyPiece.class); Serializer.registerClass(AnyPiece.class);
Serializer.registerClass(Briefing.class); Serializer.registerClass(Briefing.class);
Serializer.registerClass(CeremonyMessage.class); Serializer.registerClass(CeremonyMessage.class);
Serializer.registerClass(Dice.class); Serializer.registerClass(Die.class);
Serializer.registerClass(DiceAgain.class); Serializer.registerClass(DiceAgain.class);
Serializer.registerClass(DiceNow.class); Serializer.registerClass(DiceNow.class);
Serializer.registerClass(EndOfTurn.class); Serializer.registerClass(EndOfTurn.class);
@@ -138,7 +138,7 @@ private void registerListeners() {
myServer.addMessageListener(this, ClientStartGame.class); myServer.addMessageListener(this, ClientStartGame.class);
myServer.addMessageListener(this, DeselectTSK.class); myServer.addMessageListener(this, DeselectTSK.class);
myServer.addMessageListener(this, ForceContinueGame.class); myServer.addMessageListener(this, ForceContinueGame.class);
myServer.addMessageListener(this, ForceStartGame.class); myServer.addMessageListener(this, StartGame.class);
myServer.addMessageListener(this, JoinServer.class); myServer.addMessageListener(this, JoinServer.class);
myServer.addMessageListener(this, LeaveGame.class); myServer.addMessageListener(this, LeaveGame.class);
myServer.addMessageListener(this, LobbyNotReady.class); myServer.addMessageListener(this, LobbyNotReady.class);
@@ -223,7 +223,12 @@ public void send(int id, ServerMessage message) {
*/ */
public void broadcast(ServerMessage message) { public void broadcast(ServerMessage message) {
for (Map.Entry<Integer, Player> entry: this.logic.getGame().getPlayers().entrySet()) { for (Map.Entry<Integer, Player> entry: this.logic.getGame().getPlayers().entrySet()) {
this.send(entry.getValue().getId(), message); this.send(entry.getKey(), message);
} }
} }
@Override
public void messageReceived(HostedConnection source, Message m) {
}
} }

View File

@@ -182,6 +182,11 @@ public void received(WaitPiece msg) {
state.received(msg); state.received(msg);
} }
@Override
public void received(Spectator msg) {
state.received(msg);
}
public void selectPiece(UUID pieceId){ public void selectPiece(UUID pieceId){
state.selectPiece(pieceId); state.selectPiece(pieceId);
} }

View File

@@ -163,6 +163,11 @@ public void received(UpdateTSK msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg); LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg);
} }
@Override
public void received(Spectator msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg);
}
@Override @Override
public void received(WaitPiece msg) { public void received(WaitPiece msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg); LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg);

View File

@@ -139,7 +139,7 @@ public int getNumberOfActivePlayers() {
*/ */
public void notifyObservers() { public void notifyObservers() {
for (Observer observer : new ArrayList<>(observers)) { for (Observer observer : new ArrayList<>(observers)) {
observer.update(); //observer.update();
} }
} }

View File

@@ -11,7 +11,7 @@ public class UpdateReady extends ServerMessage {
/** /**
* The color associated with the update. * The color associated with the update.
*/ */
private final Color color; private final int playerId;
/** /**
* Indicates whether the player is ready. * Indicates whether the player is ready.
@@ -21,12 +21,12 @@ public class UpdateReady extends ServerMessage {
/** /**
* Constructs a new UpdateReady instance with the specified color and readiness status. * Constructs a new UpdateReady instance with the specified color and readiness status.
* *
* @param color the color associated with the update * @param playerId the playerId associated with the update
* @param ready the readiness status * @param ready the readiness status
*/ */
public UpdateReady(Color color, boolean ready) { public UpdateReady(int playerId, boolean ready) {
super(); super();
this.color = color; this.playerId = playerId;
this.ready = ready; this.ready = ready;
} }
@@ -35,17 +35,17 @@ public UpdateReady(Color color, boolean ready) {
*/ */
private UpdateReady() { private UpdateReady() {
super(); super();
this.color = null; this.playerId = 0;
this.ready = false; this.ready = false;
} }
/** /**
* Gets the color associated with the update. * Gets the playerId associated with the update.
* *
* @return the color * @return the playerId
*/ */
public Color getColor() { public int getPlayerId() {
return color; return playerId;
} }
/** /**

View File

@@ -81,7 +81,7 @@ public void received(LobbyNotReady msg, int from) {
* @param from as the client id of the player as an Integer. * @param from as the client id of the player as an Integer.
*/ */
@Override @Override
public void received(ForceStartGame msg, int from) { public void received(StartGame msg, int from) {
this.logic.getServerSender().broadcast(new ServerStartGame()); this.logic.getServerSender().broadcast(new ServerStartGame());
this.logic.setCurrentState(this.logic.getGameState()); this.logic.setCurrentState(this.logic.getGameState());
} }