From 7acf448c0cfae13559b76e1e06df476daf226c3d Mon Sep 17 00:00:00 2001 From: Yvonne Schmidt Date: Mon, 2 Dec 2024 03:44:33 +0100 Subject: [PATCH 1/3] added documentation for MonopolyApp --- .../java/pp/monopoly/client/MonopolyApp.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/MonopolyApp.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/MonopolyApp.java index ad5db00..d2616a0 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/MonopolyApp.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/MonopolyApp.java @@ -153,7 +153,7 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga } /** - * Starts the Battleship application. + * Starts the Monopoly application. * * @param args Command-line arguments for launching the application. */ @@ -220,9 +220,9 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga } /** - * Returns the current configuration settings for the Battleship client. + * Returns the current configuration settings for the Monopoly client. * - * @return The {@link BattleshipClientConfig} instance. //TODO Fehler im Kommentar + * @return The {@link pp.monopoly.game.client.MonopolyClientConfig} instance. */ @Override public MonopolyAppConfig getConfig() { @@ -276,7 +276,7 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga } - //logik zum wechselnden erscheinen und verschwinden beim drücken von B //TODO süäter entfernen + //logik zum wechselnden erscheinen und verschwinden beim drücken von B //TODO später entfernen private void handleB(boolean isPressed) { if (isPressed) { Dialog tmp = new GulagInfo(this, 3); @@ -482,10 +482,24 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga .open(); } + /** + * Disconnects the current server connection. + * + * This method delegates the disconnection operation to the `disconnect` method of the + * `serverConnection` object. + * + */ public void disconnect() { serverConnection.disconnect(); } + /** + * Retrieves the unique identifier associated with the server connection. + * + * Checks if a Server is connected and returns {@Code 0} if there is no connection + * + * @return the ID of the connected Server instance. + */ public int getId() { if (serverConnection != null && serverConnection instanceof NetworkSupport) return ((NetworkSupport) serverConnection).getId(); return 0; From 065049f6631d10823fd416a5c25570ab99ca1e77 Mon Sep 17 00:00:00 2001 From: Yvonne Schmidt Date: Mon, 2 Dec 2024 04:08:54 +0100 Subject: [PATCH 2/3] added documentation in client package --- .../java/pp/monopoly/client/GameMusic.java | 2 +- .../java/pp/monopoly/client/GameSound.java | 21 +++++++++++++++++++ .../java/pp/monopoly/client/MonopolyApp.java | 2 +- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/GameMusic.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/GameMusic.java index 1e6f94e..6483174 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/GameMusic.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/GameMusic.java @@ -15,7 +15,7 @@ import com.jme3.audio.AudioData; import com.jme3.audio.AudioNode; /** - * Handles the background music beeing played. Is able to start and stop the music. Set the Volume of the Audio. + * Handles the background music being played. Is able to start and stop the music. Set the Volume of the Audio. */ public class GameMusic extends AbstractAppState{ private static final Logger LOGGER = System.getLogger(GameMusic.class.getName()); diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/GameSound.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/GameSound.java index 2722afa..942dfc2 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/GameSound.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/GameSound.java @@ -27,9 +27,25 @@ import static pp.util.PreferencesUtils.getPreferences; * An application state that plays sounds. */ public class GameSound extends AbstractAppState implements GameEventListener { + + /** + * Logger instance for logging messages related to GameSound. + */ private static final Logger LOGGER = System.getLogger(GameSound.class.getName()); + + /** + * Preferences instance for managing GameSound-related settings. + */ private static final Preferences PREFERENCES = getPreferences(GameSound.class); + + /** + * Preference key for enabling or disabling GameSound. + */ private static final String ENABLED_PREF = "enabled"; //NON-NLS + + /** + * Preference key for storing the volume level of GameSound. + */ private static final String VOLUME_PREF = "volume"; //NON-NLS private AudioNode passStartSound; @@ -223,6 +239,11 @@ public class GameSound extends AbstractAppState implements GameEventListener { PREFERENCES.putFloat(VOLUME_PREF, vol); } + /** + * Overrides {@link SoundEvent#notifyListener(GameEventListener)} + * @param event the received event + */ + @Override public void receivedEvent(SoundEvent event) { switch (event.sound()) { diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/MonopolyApp.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/MonopolyApp.java index d2616a0..facb398 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/MonopolyApp.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/MonopolyApp.java @@ -48,7 +48,7 @@ import pp.monopoly.notification.InfoTextEvent; import pp.monopoly.notification.Sound; /** - * The main class for the Battleship client application. + * The main class for the Monopoly client application. * It manages the initialization, input setup, GUI setup, and game states for the client. */ public class MonopolyApp extends SimpleApplication implements MonopolyClient, GameEventListener { From 0b71c2cb961849c2c793fc6a2cb5ea6d052a0b3b Mon Sep 17 00:00:00 2001 From: Yvonne Schmidt Date: Mon, 2 Dec 2024 05:53:52 +0100 Subject: [PATCH 3/3] added documentation --- .../client/gui/PropertyOverviewMenu.java | 11 +- .../pp/monopoly/client/gui/SettingsMenu.java | 21 +++- .../pp/monopoly/client/gui/SoundSlider.java | 9 +- .../pp/monopoly/client/gui/StartMenu.java | 40 ++++--- .../java/pp/monopoly/client/gui/Toolbar.java | 106 +++++++++++++++++- .../pp/monopoly/client/gui/VolumeSlider.java | 2 +- 6 files changed, 160 insertions(+), 29 deletions(-) diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/PropertyOverviewMenu.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/PropertyOverviewMenu.java index d3a3605..5a8d82a 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/PropertyOverviewMenu.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/PropertyOverviewMenu.java @@ -43,7 +43,6 @@ public class PropertyOverviewMenu extends Dialog { super(app.getDialogManager()); this.app = app; - // Make the menu fullscreen Vector3f screenSize = new Vector3f(app.getCamera().getWidth(), app.getCamera().getHeight(), 0); @@ -231,6 +230,8 @@ public class PropertyOverviewMenu extends Dialog { /** * Custom listener for slider value changes. + * Extends {@link AbstractControl} to respond to updates in the slider's value and refresh + * the visible cards accordingly. */ private class SliderValueChangeListener extends AbstractControl { @Override @@ -240,6 +241,14 @@ public class PropertyOverviewMenu extends Dialog { refreshVisibleCards(sliderValue); } + /** + * Overrides the rendering logic for the control. + *

+ * This implementation does not require any rendering operations, so the method is left empty. + * + * @param renderManager the {@link RenderManager} handling the rendering process. + * @param viewPort the {@link ViewPort} associated with the rendering context. + */ @Override protected void controlRender(RenderManager renderManager, ViewPort viewPort) { // No rendering logic needed diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/SettingsMenu.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/SettingsMenu.java index 9d7f710..76369f8 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/SettingsMenu.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/SettingsMenu.java @@ -24,15 +24,30 @@ import pp.monopoly.notification.Sound; import static pp.util.PreferencesUtils.getPreferences; /** - * The Menu class represents the main menu in the Battleship game application. - * It extends the Dialog class and provides functionalities for loading, saving, + * The Menu class represents the main menu in the Monopoly game application. + * It extends the Dialog class and provides functionalities for Volume adjustment, Sound adjustment, * returning to the game, and quitting the application. */ public class SettingsMenu extends Dialog { + + /** + * Preferences instance for storing and retrieving settings specific to the SettingsMenu. + */ private static final Preferences PREFERENCES = getPreferences(SettingsMenu.class); - private static final String LAST_PATH = "last.file.path"; + + /** + * Reference to the main Monopoly application instance. + */ private final MonopolyApp app; + + /** + * Slider control for adjusting the music volume. + */ private final VolumeSlider musicSlider; + + /** + * Slider control for adjusting the sound effects volume. + */ private final SoundSlider soundSlider; /** diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/SoundSlider.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/SoundSlider.java index 31c547e..5a07704 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/SoundSlider.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/SoundSlider.java @@ -5,7 +5,14 @@ import pp.monopoly.client.GameSound; public class SoundSlider extends Slider { + /** + * Manages sound effects for the game. + */ private final pp.monopoly.client.GameSound sound; + + /** + * Volume level for the game sounds. + */ private double vol; /** @@ -20,7 +27,7 @@ public class SoundSlider extends Slider { } /** - * when triggered it updates the volume to the value set with the slider + * When triggered it updates the volume to the value set with the slider */ public void update() { if (vol != getModel().getPercent()) { diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/StartMenu.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/StartMenu.java index f1e1f7d..ed499d4 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/StartMenu.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/StartMenu.java @@ -18,7 +18,6 @@ import pp.monopoly.notification.Sound; /** * Constructs the startup menu dialog for the Monopoly application. -import pp.monopoly.client.gui.GameMenu; */ public class StartMenu extends Dialog { private final MonopolyApp app; @@ -42,25 +41,24 @@ public class StartMenu extends Dialog { Material backgroundMaterial = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); backgroundMaterial.setTexture("ColorMap", backgroundImage); background.setMaterial(backgroundMaterial); - background.setLocalTranslation(0, 0, -1); // Ensure it is behind other GUI elements + background.setLocalTranslation(0, 0, -1); app.getGuiNode().attachChild(background); - // Center container for title and play button Container centerMenu = new Container(new SpringGridLayout(Axis.Y, Axis.X)); Button startButton = new Button("Spielen"); - startButton.setPreferredSize(new Vector3f(190, 60, 0)); // Increase button size (width, height) - startButton.setFontSize(40); // Set the font size for the button text - startButton.setTextHAlignment(HAlignment.Center); // Center the text horizontally + startButton.setPreferredSize(new Vector3f(190, 60, 0)); + startButton.setFontSize(40); + startButton.setTextHAlignment(HAlignment.Center); startButton.addClickCommands(s -> ifTopDialog(() -> { close(); app.getGameLogic().playSound(Sound.BUTTON); - app.connect(); // Perform the connection logic + app.connect(); })); centerMenu.addChild(startButton); - // Position the center container in the middle of the screen + centerMenu.setLocalTranslation(new Vector3f(screenWidth / 2f - centerMenu.getPreferredSize().x / 2f, screenHeight / 2f - 280 + centerMenu.getPreferredSize().y / 2f, 0)); @@ -74,38 +72,32 @@ public class StartMenu extends Dialog { QuadBackgroundComponent logoBackground = new QuadBackgroundComponent(logoTexture); logoContainer.setBackground(logoBackground); - // Set the size of the container to fit the logo - float logoWidth = 512; // Adjust these values based on the logo dimensions - float logoHeight = 128; // Adjust these values based on the logo dimensions + + float logoWidth = 512; + float logoHeight = 128; logoContainer.setPreferredSize(new Vector3f(logoWidth, logoHeight, 0)); - // Position the container at the center of the screen logoContainer.setLocalTranslation(new Vector3f( screenWidth / 2f - logoWidth / 2f, - screenHeight / 2f + 200, // Adjust this value for vertical position + screenHeight / 2f + 200, 0 )); - // Attach the container to the GUI node app.getGuiNode().attachChild(logoContainer); - // Load the Unibw logo as a texture Texture unibwTexture = app.getAssetManager().loadTexture("Pictures/logo-unibw.png"); - // Create a container for the Unibw logo Container unibwContainer = new Container(); QuadBackgroundComponent unibwBackground = new QuadBackgroundComponent(unibwTexture); unibwContainer.setBackground(unibwBackground); - // Set the size of the container to fit the Unibw logo - float unibwWidth = 512; // Adjust these values based on the logo dimensions - float unibwHeight = 128; // Adjust these values based on the logo dimensions + float unibwWidth = 512; + float unibwHeight = 128; unibwContainer.setPreferredSize(new Vector3f(unibwWidth, unibwHeight, 0)); - // Position the container slightly below the Monopoly logo unibwContainer.setLocalTranslation(new Vector3f( screenWidth / 2f - unibwWidth / 2f, - screenHeight / 2f + 100, // Adjust this value for vertical position + screenHeight / 2f + 100, 0 )); @@ -113,11 +105,17 @@ public class StartMenu extends Dialog { app.getGuiNode().attachChild(unibwContainer); } + /** + * Opens the settings menu when the escape key is pressed. + */ @Override public void escape() { new SettingsMenu(app).open(); } + /** + * Closes the startup menu and detaches all GUI elements. + */ @Override public void close() { app.getGuiNode().detachAllChildren(); diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java index e2a4467..f9173dd 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java @@ -25,23 +25,93 @@ import pp.monopoly.notification.GameEventListener; import pp.monopoly.notification.Sound; import pp.monopoly.notification.UpdatePlayerView; +/** + * Represents the toolbar interface in the Monopoly application. + *

+ * This class provides game controls, player information, and event handling + * for actions such as dice rolling, trading, and ending turns. + * Implements {@link GameEventListener} to respond to game events. + *

+ */ public class Toolbar extends Dialog implements GameEventListener { + /** + * Reference to the Monopoly application instance. + */ private final MonopolyApp app; + + /** + * The main container for the toolbar interface. + */ private final Container toolbarContainer; + + /** + * Container for displaying an overview of other players. + */ private Container overviewContainer; + + /** + * Container for displaying account-related information. + */ private Container accountContainer; + + /** + * Handles player-related data and actions. + */ private PlayerHandler playerHandler; + + /** + * Label for the first dice display. + */ private Label imageLabel; + + /** + * Label for the second dice display. + */ private Label imageLabel2; + + + /** + * Button for rolling the dice. + */ private Button diceButton; + + + /** + * Button for initiating trades. + */ private Button tradeButton; + + + /** + * Button for accessing the property menu. + */ private Button propertyMenuButton; + + /** + * Button for ending the player's turn. + */ private Button endTurnButton; + /** + * Flag indicating if dice animation is ongoing. + */ private volatile boolean animatingDice = false; + + /** + * Stores the most recent dice roll event. + */ private volatile DiceRollEvent latestDiceRollEvent = null; + /** + * Constructs the toolbar for the Monopoly application. + *

+ * Initializes the toolbar interface, adds event listeners, and sets up + * the GUI elements such as dice, buttons, and player information displays. + *

+ * + * @param app the Monopoly application instance + */ public Toolbar(MonopolyApp app) { super(app.getDialogManager()); this.app = app; @@ -216,7 +286,10 @@ public class Toolbar extends Dialog implements GameEventListener { } }).start(); } - + + /** + * Animates the dice roll by cycling through dice images. + */ private void animateDice(long startTime) throws InterruptedException { int[] currentFace = {1}; while (System.currentTimeMillis() - startTime < 2000) { // Animation duration @@ -233,7 +306,12 @@ public class Toolbar extends Dialog implements GameEventListener { Thread.sleep(100); // Time between frame updates } } - + + /** + * Displays the final dice result after animation. + * + * @param event the dice roll event containing the result + */ private void showFinalDiceResult(DiceRollEvent event) { app.enqueue(() -> { setDiceIcon(imageLabel, diceToString(event.a())); @@ -260,11 +338,21 @@ public class Toolbar extends Dialog implements GameEventListener { } } + /** + * Handles dice roll events by updating the dice display. + * + * @param event the dice roll event containing dice values + */ @Override public void receivedEvent(DiceRollEvent event) { latestDiceRollEvent = event; } + /** + * Updates the player view with the latest account and overview data. + * + * @param event the update event for the player view + */ @Override public void receivedEvent(UpdatePlayerView event) { playerHandler = app.getGameLogic().getPlayerHandler(); @@ -306,6 +394,11 @@ public class Toolbar extends Dialog implements GameEventListener { overviewContainer.setBackground(null); } + /** + * Updates the enabled status of toolbar buttons based on the event. + * + * @param event the button status event + */ @Override public void receivedEvent(ButtonStatusEvent event) { boolean enabled = event.buttonsEnabled(); @@ -315,17 +408,26 @@ public class Toolbar extends Dialog implements GameEventListener { endTurnButton.setEnabled(enabled); } + /** + * Closes the toolbar and detaches it from the GUI. + */ @Override public void close() { app.getGuiNode().detachChild(toolbarContainer); super.close(); } + /** + * Opens the settings menu when the escape key is pressed. + */ @Override public void escape() { new SettingsMenu(app).open(); } + /** + * Updates the toolbar by refreshing player information. + */ @Override public void update() { receivedEvent(new UpdatePlayerView()); diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/VolumeSlider.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/VolumeSlider.java index c0c8cc2..b2e9410 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/VolumeSlider.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/VolumeSlider.java @@ -25,7 +25,7 @@ public class VolumeSlider extends Slider { } /** - * when triggered it updates the volume to the value set with the slider + * When triggered it updates the volume to the value set with the slider */ public void update() { if (vol != getModel().getPercent()) {