From dffb5b4d63ad1b67841636e72986fde8e09cd916 Mon Sep 17 00:00:00 2001 From: Benjamin Feyer Date: Tue, 8 Oct 2024 23:05:51 +0200 Subject: [PATCH] corrected the server based validation in 'WaitState' and 'ServerGameLogic' and 'battleship.properties' and 'battleship_de.properties' and reformatted 'SeaSynchronizer' corrected the 'ServerGameLogic' so it will send new GameLogic and will be still in EditorState, when presented with an invalid map and added in the properties the keys writen in 'WaitState' and added the 'ReceivedGameLogic', to receive new GameDetails --- .../pp/battleship/client/gui/SeaSynchronizer.java | 9 ++------- .../java/pp/battleship/game/client/WaitState.java | 15 +++++++++++++++ .../battleship/game/server/ServerGameLogic.java | 1 + .../src/main/resources/battleship.properties | 1 + .../src/main/resources/battleship_de.properties | 1 + 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/Projekte/battleship/client/src/main/java/pp/battleship/client/gui/SeaSynchronizer.java b/Projekte/battleship/client/src/main/java/pp/battleship/client/gui/SeaSynchronizer.java index a6304789..4e346bfd 100644 --- a/Projekte/battleship/client/src/main/java/pp/battleship/client/gui/SeaSynchronizer.java +++ b/Projekte/battleship/client/src/main/java/pp/battleship/client/gui/SeaSynchronizer.java @@ -122,12 +122,13 @@ private Spatial handleHit(Shot shot) { /** * this method attach fire to the ship, if it is hit + * * @param shot the shot, that hit the ship * @return the Fire */ private ParticleEmitter createFire(Shot shot) { - ParticleEmitter hitEffect = new ParticleEmitter("HitEffect", Type.Triangle, 5000); + ParticleEmitter hitEffect = new ParticleEmitter("HitEffect", Type.Triangle, 5000); hitEffect.setMaterial(new Material(app.getAssetManager(), PARTICLE)); hitEffect.setImagesX(2); hitEffect.setImagesY(2); @@ -280,12 +281,6 @@ private Spatial createDestroyer(Battleship ship) { model.scale(0.0001f); model.move(0, 0.3f, 0); model.setShadowMode(ShadowMode.CastAndReceive); - //model.setMaterial(app.getAssetManager().loadMaterial("Models/Destroyer/10619_Battleship.mtl")); - //TODO - //Material m = new Material(); - - //m.setTexture("textureDestroyer",app.getAssetManager().loadTexture("Models/Destroyer/10619_Battleship.mtl")); - //model.setMaterial(m); return model; } diff --git a/Projekte/battleship/model/src/main/java/pp/battleship/game/client/WaitState.java b/Projekte/battleship/model/src/main/java/pp/battleship/game/client/WaitState.java index 90cb8176..3dcb1909 100644 --- a/Projekte/battleship/model/src/main/java/pp/battleship/game/client/WaitState.java +++ b/Projekte/battleship/model/src/main/java/pp/battleship/game/client/WaitState.java @@ -7,6 +7,7 @@ package pp.battleship.game.client; +import pp.battleship.message.server.GameDetails; import pp.battleship.message.server.StartBattleMessage; import java.lang.System.Logger.Level; @@ -38,4 +39,18 @@ public void receivedStartBattle(StartBattleMessage msg) { logic.setInfoText(msg.getInfoTextKey()); logic.setState(new BattleState(logic, msg.isMyTurn())); } + + /** + * Handles the GameDetails message received from the server. + * If the map is invalid, the editor state is set. + * + * @param msg the GameDetails message received + */ + @Override + public void receivedGameDetails(GameDetails msg) { + ClientGameLogic.LOGGER.log(Level.WARNING, "Invalid Map"); //NON-NLS + logic.setInfoText("map.invalid"); + logic.setState(new EditorState(logic)); + } + } diff --git a/Projekte/battleship/model/src/main/java/pp/battleship/game/server/ServerGameLogic.java b/Projekte/battleship/model/src/main/java/pp/battleship/game/server/ServerGameLogic.java index 17fab180..a8e48c39 100644 --- a/Projekte/battleship/model/src/main/java/pp/battleship/game/server/ServerGameLogic.java +++ b/Projekte/battleship/model/src/main/java/pp/battleship/game/server/ServerGameLogic.java @@ -145,6 +145,7 @@ public void received(MapMessage msg, int from) { LOGGER.log(Level.ERROR, "playerReady not allowed in {0}", state); //NON-NLS else if (!verifyMap(msg, from)) { LOGGER.log(Level.ERROR, "player submitted invalid map", state); + send(getPlayerById(from), new GameDetails(config)); } else playerReady(getPlayerById(from), msg.getShips()); diff --git a/Projekte/battleship/model/src/main/resources/battleship.properties b/Projekte/battleship/model/src/main/resources/battleship.properties index 8964446a..6584a54d 100644 --- a/Projekte/battleship/model/src/main/resources/battleship.properties +++ b/Projekte/battleship/model/src/main/resources/battleship.properties @@ -41,3 +41,4 @@ background.music.checkbox= Background music on/off background.music.volume= Background volume player.submitted.invalid.map= invalid map submitted local.server= instantiate local server +map.invalid=The map is invalid diff --git a/Projekte/battleship/model/src/main/resources/battleship_de.properties b/Projekte/battleship/model/src/main/resources/battleship_de.properties index c80c2516..2aa07dbe 100644 --- a/Projekte/battleship/model/src/main/resources/battleship_de.properties +++ b/Projekte/battleship/model/src/main/resources/battleship_de.properties @@ -41,4 +41,5 @@ background.music.checkbox= Musik an/aus background.music.volume= Musiklautstärke player.submitted.invalid.map= Invalide karte gegeben local.server=Lokalen Server erstellen +map.invalid=Die Karte ist ungültig