diff --git a/Projekte/battleship/client/src/main/java/pp/battleship/client/BackgroundMusic.java b/Projekte/battleship/client/src/main/java/pp/battleship/client/BackgroundMusic.java index a1000ec0..e84d46a5 100644 --- a/Projekte/battleship/client/src/main/java/pp/battleship/client/BackgroundMusic.java +++ b/Projekte/battleship/client/src/main/java/pp/battleship/client/BackgroundMusic.java @@ -14,7 +14,7 @@ public class BackgroundMusic implements GameEventListener { private static final String VOLUME_PREF = "volume"; private static final String MUSIC_ENABLED_PREF = "musicEnabled"; - private static final Preferences prefs = Preferences.userNodeForPackage(BackgroundMusic.class); + private static final Preferences PREFS = Preferences.userNodeForPackage(BackgroundMusic.class); static final Logger LOGGER = System.getLogger(BackgroundMusic.class.getName()); @@ -40,8 +40,8 @@ public class BackgroundMusic implements GameEventListener { * @param app The main Application */ public BackgroundMusic(BattleshipApp app) { - this.volume = prefs.getFloat(VOLUME_PREF, 1.0f); - this.musicEnabled = prefs.getBoolean(MUSIC_ENABLED_PREF, true); + this.volume = PREFS.getFloat(VOLUME_PREF, 1.0f); + this.musicEnabled = PREFS.getBoolean(MUSIC_ENABLED_PREF, true); this.app = app; menuMusic = createAudioNode(MENU_MUSIC); @@ -135,14 +135,14 @@ public void toggleMusic() { pause(gameOverMusicV); } - prefs.putBoolean(MUSIC_ENABLED_PREF, musicEnabled); + PREFS.putBoolean(MUSIC_ENABLED_PREF, musicEnabled); } /** * this method is used when the main volume changes */ public void setVolume(){ - setVolume(prefs.getFloat(VOLUME_PREF, 1.0f)); + setVolume(PREFS.getFloat(VOLUME_PREF, 1.0f)); } /** @@ -158,7 +158,7 @@ public void setVolume(float volume) { gameOverMusicL.setVolume(volume * mainVolume); gameOverMusicV.setVolume(volume * mainVolume); - prefs.putFloat(VOLUME_PREF, volume); + PREFS.putFloat(VOLUME_PREF, volume); } /** diff --git a/Projekte/battleship/client/src/main/java/pp/battleship/client/GameSound.java b/Projekte/battleship/client/src/main/java/pp/battleship/client/GameSound.java index a6d2f3c0..2dee904b 100644 --- a/Projekte/battleship/client/src/main/java/pp/battleship/client/GameSound.java +++ b/Projekte/battleship/client/src/main/java/pp/battleship/client/GameSound.java @@ -14,6 +14,7 @@ import com.jme3.asset.AssetNotFoundException; import com.jme3.audio.AudioData; import com.jme3.audio.AudioNode; +import com.jme3.audio.AudioSource; import pp.battleship.notification.GameEventListener; import pp.battleship.notification.SoundEvent; @@ -81,9 +82,9 @@ public void setEnabled(boolean enabled) { public void initialize(AppStateManager stateManager, Application app) { super.initialize(stateManager, app); this.app = (BattleshipApp) app; - shipDestroyedSound = loadSound(app, "Sound/Effects/sunken.wav"); //NON-NLS - splashSound = loadSound(app, "Sound/Effects/splash.wav"); //NON-NLS - explosionSound = loadSound(app, "Sound/Effects/explosion.wav"); //NON-NLS + shipDestroyedSound = loadSound(app, "Sound/Effects/sunken.wav", 1); //NON-NLS + splashSound = loadSound(app, "Sound/Effects/splash.wav", 2); //NON-NLS + explosionSound = loadSound(app, "Sound/Effects/explosion.wav",3); //NON-NLS volume = PREFERENCES.getFloat(SOUND_VOLUME_PREF, 1.0f); } @@ -94,11 +95,12 @@ public void initialize(AppStateManager stateManager, Application app) { * @param name The name of the sound file. * @return The loaded AudioNode. */ - private AudioNode loadSound(Application app, String name) { + private AudioNode loadSound(Application app, String name, int channel) { try { final AudioNode sound = new AudioNode(app.getAssetManager(), name, AudioData.DataType.Buffer); sound.setLooping(false); sound.setPositional(false); + sound.setChannel(channel); return sound; } catch (AssetLoadException | AssetNotFoundException ex) { @@ -138,9 +140,10 @@ public void shipDestroyed() { */ public void setSoundVolume(float volume) { float mainVolume = app.getMainVolumeControl().getMainVolume(); - shipDestroyedSound.setVolume(volume); - splashSound.setVolume(volume); - explosionSound.setVolume(volume); + float calculatedVolume = volume * mainVolume; + shipDestroyedSound.setVolume(calculatedVolume); + splashSound.setVolume(calculatedVolume); + explosionSound.setVolume(calculatedVolume); this.volume = volume; PREFERENCES.putFloat(SOUND_VOLUME_PREF, volume); } @@ -168,9 +171,15 @@ public float getVolume(){ @Override public void receivedEvent(SoundEvent event) { switch (event.sound()) { - case EXPLOSION -> explosion(); - case SPLASH -> splash(); - case DESTROYED_SHIP -> shipDestroyed(); + case EXPLOSION : + explosion(); + break; + case SPLASH : + splash(); + break; + case DESTROYED_SHIP: + shipDestroyed(); + break; } } } diff --git a/Projekte/battleship/client/src/main/java/pp/battleship/client/MainVolume.java b/Projekte/battleship/client/src/main/java/pp/battleship/client/MainVolume.java index 53ad1fa1..d9b9574c 100644 --- a/Projekte/battleship/client/src/main/java/pp/battleship/client/MainVolume.java +++ b/Projekte/battleship/client/src/main/java/pp/battleship/client/MainVolume.java @@ -5,7 +5,7 @@ import java.util.prefs.Preferences; public class MainVolume { - private static final Preferences prefs = Preferences.userNodeForPackage(MainVolume.class); + private static final Preferences PREFS = Preferences.userNodeForPackage(MainVolume.class); private static final String MAIN_VOLUME_PREFS = "MainVolume"; static final Logger LOGGER = System.getLogger(MainVolume.class.getName()); @@ -14,7 +14,7 @@ public class MainVolume { private BattleshipApp app; public MainVolume(BattleshipApp app) { - this.mainVolume = prefs.getFloat(MAIN_VOLUME_PREFS, 1.0f); + this.mainVolume = PREFS.getFloat(MAIN_VOLUME_PREFS, 1.0f); this.app = app; } @@ -23,7 +23,7 @@ public void setMainVolume(float mainVolume) { app.getBackgroundMusic().setVolume(); app.getStateManager().getState(GameSound.class).setSoundVolume(); this.mainVolume = mainVolume; - prefs.putFloat(MAIN_VOLUME_PREFS, mainVolume); + PREFS.putFloat(MAIN_VOLUME_PREFS, mainVolume); } public float getMainVolume() { diff --git a/Projekte/battleship/client/src/main/java/pp/battleship/client/gui/ShellMapControl.java b/Projekte/battleship/client/src/main/java/pp/battleship/client/gui/ShellMapControl.java index 2307ac1f..0ec30d90 100644 --- a/Projekte/battleship/client/src/main/java/pp/battleship/client/gui/ShellMapControl.java +++ b/Projekte/battleship/client/src/main/java/pp/battleship/client/gui/ShellMapControl.java @@ -15,7 +15,7 @@ public class ShellMapControl extends AbstractControl { private final Position position; private final IntPoint pos; - private static final Vector3f vector = new Vector3f(); + private static final Vector3f VECTOR = new Vector3f(); private final BattleshipApp app; /** @@ -30,7 +30,7 @@ public ShellMapControl(Position position, BattleshipApp app, IntPoint pos) { this.position = position; this.pos = pos; this.app = app; - vector.set(new Vector3f(position.getX(), position.getY(), 0)); + VECTOR.set(new Vector3f(position.getX(), position.getY(), 0)); } /** @@ -41,7 +41,7 @@ public ShellMapControl(Position position, BattleshipApp app, IntPoint pos) { */ @Override protected void controlUpdate(float tpf) { - spatial.move(vector.mult(tpf)); + spatial.move(VECTOR.mult(tpf)); if (spatial.getLocalTranslation().getX() >= position.getX() && spatial.getLocalTranslation().getY() >= position.getY()) { spatial.getParent().detachChild(spatial); app.getGameLogic().send(new AnimationEndMessage(pos)); diff --git a/Projekte/battleship/client/src/main/resources/Sound/Effects/rocket.wav b/Projekte/battleship/client/src/main/resources/Sound/Effects/rocket.wav new file mode 100644 index 00000000..6a0b59ef Binary files /dev/null and b/Projekte/battleship/client/src/main/resources/Sound/Effects/rocket.wav differ 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 351e482e..ad27b656 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 @@ -213,25 +213,26 @@ public void received(ShootMessage msg, int from) { */ @Override public void received(AnimationEndMessage msg, int from){ - if(state != ServerState.ANIMATION_WAIT) + if(state != ServerState.ANIMATION_WAIT) { LOGGER.log(Level.ERROR, "animation not allowed in {0}", state); - else - if(getPlayerById(from) == players.get(0)){ - LOGGER.log(Level.DEBUG, "{0} set to true", getPlayerById(from)); - player1AnimationReady = true; - shoot(getPlayerById(from), msg.getPosition()); - } else if (getPlayerById(from) == players.get(1)){ - LOGGER.log(Level.DEBUG, "{0} set to true {1}", getPlayerById(from), getPlayerById(from).toString()); - player2AnimationReady = true; - shoot(getPlayerById(from), msg.getPosition()); - } - if(player1AnimationReady && player2AnimationReady){ - setState(ServerState.BATTLE); - for (Player player : players) - send(player, new SwitchBattleState(player == activePlayer)); - player1AnimationReady = false; - player2AnimationReady = false; - } + return; + } + if(getPlayerById(from) == players.get(0)){ + LOGGER.log(Level.DEBUG, "{0} set to true", getPlayerById(from)); + player1AnimationReady = true; + shoot(getPlayerById(from), msg.getPosition()); + } else if (getPlayerById(from) == players.get(1)){ + LOGGER.log(Level.DEBUG, "{0} set to true {1}", getPlayerById(from), getPlayerById(from).toString()); + player2AnimationReady = true; + shoot(getPlayerById(from), msg.getPosition()); + } + if(player1AnimationReady && player2AnimationReady){ + setState(ServerState.BATTLE); + for (Player player : players) + send(player, new SwitchBattleState(player == activePlayer)); + player1AnimationReady = false; + player2AnimationReady = false; + } } /** diff --git a/Projekte/battleship/model/src/main/java/pp/battleship/game/singlemode/InterpreterProxy.java b/Projekte/battleship/model/src/main/java/pp/battleship/game/singlemode/InterpreterProxy.java index a5f3f131..c7a46715 100644 --- a/Projekte/battleship/model/src/main/java/pp/battleship/game/singlemode/InterpreterProxy.java +++ b/Projekte/battleship/model/src/main/java/pp/battleship/game/singlemode/InterpreterProxy.java @@ -26,6 +26,7 @@ class InterpreterProxy implements ServerInterpreter { * * @param playerClient the client to which the server messages are forwarded */ + InterpreterProxy(BattleshipClient playerClient) { this.playerClient = playerClient; }