From c0a3e8b37a9fa50dd40d9588b0a26d304f1ed19a Mon Sep 17 00:00:00 2001 From: Tamino Mueller Date: Sun, 13 Oct 2024 20:34:01 +0200 Subject: [PATCH] task 10 --- .../pp/battleship/client/BattleshipApp.java | 11 ++++++---- .../battleship/client/BattleshipAppState.java | 2 ++ .../java/pp/battleship/client/GameSound.java | 2 +- .../main/java/pp/battleship/client/Menu.java | 16 ++++++++------ .../pp/battleship/game/client/GameMusic.java | 21 +++++++++---------- 5 files changed, 30 insertions(+), 22 deletions(-) diff --git a/Projekte/battleship/client/src/main/java/pp/battleship/client/BattleshipApp.java b/Projekte/battleship/client/src/main/java/pp/battleship/client/BattleshipApp.java index a750963..c39bce1 100644 --- a/Projekte/battleship/client/src/main/java/pp/battleship/client/BattleshipApp.java +++ b/Projekte/battleship/client/src/main/java/pp/battleship/client/BattleshipApp.java @@ -272,12 +272,15 @@ public class BattleshipApp extends SimpleApplication implements BattleshipClient stateManager.attachAll(new EditorAppState(), new BattleAppState(), new SeaAppState()); } - private void attachGameMusic() { - final GameMusic gameMusic = new GameMusic(); - gameMusic.setEnabled(GameMusic.enabledInPreferences()); - stateManager.attach(gameMusic); + private void atttachGameMusic() { + final GameMusic gameSound = new GameMusic(); + gameSound.setEnabled(GameMusic.enabledInPreferences()); + stateManager.attach(gameSound); + } + + /** * Attaches the game sound state and sets its initial enabled state. * diff --git a/Projekte/battleship/client/src/main/java/pp/battleship/client/BattleshipAppState.java b/Projekte/battleship/client/src/main/java/pp/battleship/client/BattleshipAppState.java index 0094516..8664671 100644 --- a/Projekte/battleship/client/src/main/java/pp/battleship/client/BattleshipAppState.java +++ b/Projekte/battleship/client/src/main/java/pp/battleship/client/BattleshipAppState.java @@ -12,6 +12,8 @@ import com.jme3.app.state.AbstractAppState; import com.jme3.app.state.AppStateManager; import pp.battleship.game.client.ClientGameLogic; + + /** * Abstract class representing a state in the Battleship game. * Extends the AbstractAppState from jMonkeyEngine to manage state behavior. 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 0fdcef6..0b3ae6a 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 @@ -87,7 +87,7 @@ public class GameSound extends AbstractAppState implements GameEventListener { * @param name The name of the sound file. * @return The loaded AudioNode. */ - private AudioNode loadSound(Application app, String name) { + public AudioNode loadSound(Application app, String name) { try { final AudioNode sound = new AudioNode(app.getAssetManager(), name, AudioData.DataType.Buffer); sound.setLooping(false); diff --git a/Projekte/battleship/client/src/main/java/pp/battleship/client/Menu.java b/Projekte/battleship/client/src/main/java/pp/battleship/client/Menu.java index 4b64cf2..b69ff48 100644 --- a/Projekte/battleship/client/src/main/java/pp/battleship/client/Menu.java +++ b/Projekte/battleship/client/src/main/java/pp/battleship/client/Menu.java @@ -32,7 +32,7 @@ class Menu extends Dialog { private static final Preferences PREFERENCES = getPreferences(Menu.class); private static final String LAST_PATH = "last.file.path"; - private final VolumeSlider slider; + // private final VolumeSlider slider; private final BattleshipApp app; private final Button loadButton = new Button(lookup("menu.map.load")); private final Button saveButton = new Button(lookup("menu.map.save")); @@ -42,13 +42,14 @@ class Menu extends Dialog { * * @param app the BattleshipApp instance */ + public Menu(BattleshipApp app) { super(app.getDialogManager()); this.app = app; addChild(new Label(lookup("battleship.name"), new ElementId("header"))); //NON-NLS addChild(new Checkbox(lookup("menu.sound-enabled"), new StateCheckboxModel(app, GameSound.class))); - slider = new VolumeSlider(app.getStateManager().getState(GameMusic.class)); + // slider = new VolumeSlider(app.getStateManager().getState(GameMusic.class)); addChild(loadButton) .addClickCommands(s -> ifTopDialog(this::loadDialog)); addChild(saveButton) @@ -61,8 +62,7 @@ class Menu extends Dialog { addChild(new Checkbox(lookup("menu.sound-enabled"), new StateCheckboxModel(app, GameSound.class))); addChild(new Checkbox(lookup("menu.background-sound-enabled"), new StateCheckboxModel(app, GameMusic.class))); - - addChild(slider); + // addChild(slider); } @@ -74,11 +74,15 @@ class Menu extends Dialog { loadButton.setEnabled(app.getGameLogic().mayLoadMap()); saveButton.setEnabled(app.getGameLogic().maySaveMap()); } - @Override - public void update(float delta){ + + /* @Override + public void update(float delta) { slider.update(); } + */ + + /** * As an escape action, this method closes the menu if it is the top dialog. */ diff --git a/Projekte/battleship/model/src/main/java/pp/battleship/game/client/GameMusic.java b/Projekte/battleship/model/src/main/java/pp/battleship/game/client/GameMusic.java index dd89122..46010f8 100644 --- a/Projekte/battleship/model/src/main/java/pp/battleship/game/client/GameMusic.java +++ b/Projekte/battleship/model/src/main/java/pp/battleship/game/client/GameMusic.java @@ -1,12 +1,5 @@ package pp.battleship.game.client; - -import static pp.util.PreferencesUtils.getPreferences; - -import java.lang.System.Logger; -import java.lang.System.Logger.Level; -import java.util.prefs.Preferences; - import com.jme3.app.Application; import com.jme3.app.state.AbstractAppState; import com.jme3.app.state.AppStateManager; @@ -15,6 +8,12 @@ import com.jme3.asset.AssetNotFoundException; import com.jme3.audio.AudioData; import com.jme3.audio.AudioNode; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; +import java.util.prefs.Preferences; + +import static pp.util.PreferencesUtils.getPreferences; + public class GameMusic extends AbstractAppState{ private static final Logger LOGGER = System.getLogger(GameMusic.class.getName()); private static final Preferences PREFERENCES = getPreferences(GameMusic.class); @@ -43,7 +42,7 @@ public class GameMusic extends AbstractAppState{ /** * Initializes the sound effects for the game. - * Overrides {@link AbstractAppState#initialize(AppStateManager, Application)} + * Overrides {@link com.jme3.app.state.AbstractAppState#initialize(com.jme3.app.state.AppStateManager, com.jme3.app.Application)} * * @param stateManager The state manager * @param app The application @@ -51,7 +50,7 @@ public class GameMusic extends AbstractAppState{ @Override public void initialize(AppStateManager stateManager, Application app) { super.initialize(stateManager, app); - music = loadSound(app, "Sound/DasBootMenu.ogg"); + music = loadSoundb(app, "Sound/Music/My_heart_will_go_on.ogg"); setVolume(volumeInPreferences()); music.setLooping(true); if (isEnabled() && music != null) { @@ -66,7 +65,7 @@ public class GameMusic extends AbstractAppState{ * @param name The name of the sound file. * @return The loaded AudioNode. */ -/* private AudioNode loadSound(Application app, String name) { + private AudioNode loadSoundb(Application app, String name) { try{ final AudioNode sound = new AudioNode(app.getAssetManager(), name, AudioData.DataType.Buffer); sound.setLooping(false); @@ -79,7 +78,7 @@ public class GameMusic extends AbstractAppState{ return null; } - */ + /** * Sets the enabled state of this AppState.