From b37a5095f02c18bcb1155b0664e82160ddd3cc49 Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Mon, 18 Nov 2024 03:20:39 +0100 Subject: [PATCH 01/21] client recieve message logic --- .../monopoly/game/client/ClientGameLogic.java | 88 +++++++++---------- .../message/server/BuyPropertyResponse.java | 28 +++++- .../message/server/EventDrawCard.java | 9 ++ .../pp/monopoly/message/server/GameOver.java | 9 ++ .../pp/monopoly/message/server/JailEvent.java | 10 +++ .../message/server/PlayerStatusUpdate.java | 24 +++++ .../message/server/ServerInterpreter.java | 7 -- .../message/server/TimeOutWarning.java | 10 +++ .../message/server/UpdatePlayerAssets.java | 16 ---- .../message/server/ViewAssetsResponse.java | 6 +- .../java/pp/monopoly/notification/Sound.java | 55 +++++++++++- 11 files changed, 186 insertions(+), 76 deletions(-) delete mode 100644 Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/UpdatePlayerAssets.java diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ClientGameLogic.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ClientGameLogic.java index 67e291c..1f440c0 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ClientGameLogic.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ClientGameLogic.java @@ -19,7 +19,6 @@ import pp.monopoly.message.server.ServerInterpreter; import pp.monopoly.message.server.TimeOutWarning; import pp.monopoly.message.server.TradeReply; import pp.monopoly.message.server.TradeRequest; -import pp.monopoly.message.server.UpdatePlayerAssets; import pp.monopoly.message.server.ViewAssetsResponse; import pp.monopoly.model.IntPoint; import pp.monopoly.model.Board; @@ -38,8 +37,6 @@ import java.lang.System.Logger.Level; import java.util.ArrayList; import java.util.List; -import static java.lang.Math.max; - /** * Controls the client-side game logic for Monopoly. * Manages the player's placement, interactions with the map, and response to server messages. @@ -48,9 +45,8 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker { static final Logger LOGGER = System.getLogger(ClientGameLogic.class.getName()); private final ClientSender clientSender; private final List listeners = new ArrayList<>(); - private Board ownMap; - private Board harbor; - private Board opponentMap; + private Board board; + private ClientState state = new ClientState(this) { }; @@ -88,8 +84,8 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker { * * @return the player's own map */ - public Board getMap() { - return ownMap; + public Board getBoard() { + return board; } /** @@ -185,73 +181,73 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker { @Override public void received(BuyPropertyResponse msg) { - // TODO Auto-generated method stub - throw new UnsupportedOperationException("Unimplemented method 'received'"); + if (msg.isSuccessful()) { + setInfoText("You successfully bought " + msg.getPropertyName() + "!"); + playSound(Sound.MONEY_LOST); + } else { + setInfoText("Unable to buy " + msg.getPropertyName() + ". Reason: " + msg.getReason()); + } } - + @Override public void received(DiceResult msg) { - // TODO Auto-generated method stub - throw new UnsupportedOperationException("Unimplemented method 'received'"); + setInfoText("You rolled a " + msg.calcTotal() + "!"); + playSound(Sound.DICE_ROLL); } - + @Override public void received(EventDrawCard msg) { - // TODO Auto-generated method stub - throw new UnsupportedOperationException("Unimplemented method 'received'"); + setInfoText("Event card drawn: " + msg.getCardDescription()); + playSound(Sound.EVENT_CARD); } - + @Override public void received(GameOver msg) { - // TODO Auto-generated method stub - throw new UnsupportedOperationException("Unimplemented method 'received'"); + if (msg.isWinner()) { + setInfoText("Congratulations! You have won the game!"); + playSound(Sound.WINNER); + } else { + setInfoText("Game over. Better luck next time!"); + playSound(Sound.LOSER); + } } - + @Override public void received(GameStart msg) { - // TODO Auto-generated method stub - throw new UnsupportedOperationException("Unimplemented method 'received'"); + setInfoText("The game has started! Good luck!"); } - + @Override public void received(JailEvent msg) { - // TODO Auto-generated method stub - throw new UnsupportedOperationException("Unimplemented method 'received'"); + if (msg.isGoingToJail()) { + setInfoText("You are sent to jail!"); + playSound(Sound.GULAG); + } else { + setInfoText("You are out of jail!"); + } } - + @Override public void received(PlayerStatusUpdate msg) { - // TODO Auto-generated method stub - throw new UnsupportedOperationException("Unimplemented method 'received'"); + setInfoText("Player " + msg.getPlayerName() + " status updated: " + msg.getStatus()); } - + @Override public void received(TimeOutWarning msg) { - // TODO Auto-generated method stub - throw new UnsupportedOperationException("Unimplemented method 'received'"); + setInfoText("Warning! Time is running out. You have " + msg.getRemainingTime() + " seconds left."); } - - @Override - public void received(UpdatePlayerAssets msg) { - // TODO Auto-generated method stub - throw new UnsupportedOperationException("Unimplemented method 'received'"); - } - + @Override public void received(ViewAssetsResponse msg) { - // TODO Auto-generated method stub - throw new UnsupportedOperationException("Unimplemented method 'received'"); + setInfoText("Your current assets are being displayed."); } - + @Override public void received(TradeReply msg) { - // TODO Auto-generated method stub - throw new UnsupportedOperationException("Unimplemented method 'received'"); } - + @Override public void received(TradeRequest msg) { - // TODO Auto-generated method stub - throw new UnsupportedOperationException("Unimplemented method 'received'"); } + } diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/BuyPropertyResponse.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/BuyPropertyResponse.java index cd2b906..e926317 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/BuyPropertyResponse.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/BuyPropertyResponse.java @@ -1,11 +1,34 @@ package pp.monopoly.message.server; +/** + * Represents the server's response to a player's request to buy a property. + */ public class BuyPropertyResponse extends ServerMessage{ + private final boolean successful; + private final String propertyName; + private final String reason; // Reason for failure, if any + + public BuyPropertyResponse(boolean successful, String propertyName, String reason) { + this.successful = successful; + this.propertyName = propertyName; + this.reason = reason; + } + + public boolean isSuccessful() { + return successful; + } + + public String getPropertyName() { + return propertyName; + } + + public String getReason() { + return reason; + } @Override public void accept(ServerInterpreter interpreter) { - // TODO Auto-generated method stub - throw new UnsupportedOperationException("Unimplemented method 'accept'"); + interpreter.received(this); } @Override @@ -13,5 +36,4 @@ public class BuyPropertyResponse extends ServerMessage{ // TODO Auto-generated method stub throw new UnsupportedOperationException("Unimplemented method 'getInfoTextKey'"); } - } diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/EventDrawCard.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/EventDrawCard.java index 7ed4938..968f2bb 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/EventDrawCard.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/EventDrawCard.java @@ -1,6 +1,11 @@ package pp.monopoly.message.server; public class EventDrawCard extends ServerMessage{ + private final String cardDescription; + + public EventDrawCard(String cardDescription) { + this.cardDescription = cardDescription; + } @Override public void accept(ServerInterpreter interpreter) { @@ -13,4 +18,8 @@ public class EventDrawCard extends ServerMessage{ throw new UnsupportedOperationException("Unimplemented method 'getInfoTextKey'"); } + public String getCardDescription() { + return cardDescription; + } + } diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/GameOver.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/GameOver.java index 9b2cff3..e91041e 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/GameOver.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/GameOver.java @@ -1,6 +1,15 @@ package pp.monopoly.message.server; public class GameOver extends ServerMessage{ + private final boolean isWinner; + + public GameOver(boolean isWinner) { + this.isWinner = isWinner; + } + + public boolean isWinner() { + return isWinner; + } @Override public void accept(ServerInterpreter interpreter) { diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/JailEvent.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/JailEvent.java index a802398..485a7fd 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/JailEvent.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/JailEvent.java @@ -2,6 +2,16 @@ package pp.monopoly.message.server; public class JailEvent extends ServerMessage{ + private final boolean goingToJail; + + public JailEvent(boolean goingToJail) { + this.goingToJail = goingToJail; + } + + public boolean isGoingToJail() { + return goingToJail; + } + @Override public void accept(ServerInterpreter interpreter) { interpreter.received(this); diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/PlayerStatusUpdate.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/PlayerStatusUpdate.java index 8b51066..c876108 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/PlayerStatusUpdate.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/PlayerStatusUpdate.java @@ -1,7 +1,31 @@ package pp.monopoly.message.server; +import pp.monopoly.game.server.PlayerColor; + public class PlayerStatusUpdate extends ServerMessage{ + private final String playerName; + private final String status; + private final PlayerColor color; + + public PlayerStatusUpdate(String playerName, String status, PlayerColor color) { + this.playerName = playerName; + this.status = status; + this.color = color; + } + + public String getPlayerName() { + return playerName; + } + + public String getStatus() { + return status; + } + + public PlayerColor getColor() { + return color; + } + @Override public void accept(ServerInterpreter interpreter) { interpreter.received(this); diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/ServerInterpreter.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/ServerInterpreter.java index 3480d20..1f78ba7 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/ServerInterpreter.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/ServerInterpreter.java @@ -69,13 +69,6 @@ public interface ServerInterpreter { */ void received(TimeOutWarning msg); - /** - * Handles a UpdatePlayerAssets message received from the server. - * - * @param msg the UpdatePlayerAssets message received - */ - void received(UpdatePlayerAssets msg); - /** * Handles a ViewAssetsResponse message received from the server. * diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/TimeOutWarning.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/TimeOutWarning.java index f9510a7..b862170 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/TimeOutWarning.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/TimeOutWarning.java @@ -2,6 +2,16 @@ package pp.monopoly.message.server; public class TimeOutWarning extends ServerMessage{ + private final int remainingTime; + + public TimeOutWarning(int remainingTime) { + this.remainingTime = remainingTime; + } + + public int getRemainingTime() { + return remainingTime; + } + @Override public void accept(ServerInterpreter interpreter) { interpreter.received(this); diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/UpdatePlayerAssets.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/UpdatePlayerAssets.java deleted file mode 100644 index e37c78c..0000000 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/UpdatePlayerAssets.java +++ /dev/null @@ -1,16 +0,0 @@ -package pp.monopoly.message.server; - -public class UpdatePlayerAssets extends ServerMessage{ - - @Override - public void accept(ServerInterpreter interpreter) { - interpreter.received(this); - } - - @Override - public String getInfoTextKey() { - // TODO Auto-generated method stub - throw new UnsupportedOperationException("Unimplemented method 'getInfoTextKey'"); - } - -} diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/ViewAssetsResponse.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/ViewAssetsResponse.java index 116366e..9a00833 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/ViewAssetsResponse.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/ViewAssetsResponse.java @@ -8,9 +8,9 @@ import pp.monopoly.model.fields.PropertyField; */ public class ViewAssetsResponse extends ServerMessage{ - private List properties; - private int accountBalance; - private int jailCards; + private final List properties; + private final int accountBalance; + private final int jailCards; /** * Constructs a ViewAssetsResponse with the specified properties and account balance. diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/notification/Sound.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/notification/Sound.java index 280ad4f..36c12d6 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/notification/Sound.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/notification/Sound.java @@ -1,8 +1,61 @@ package pp.monopoly.notification; /** - * Enumeration representing different types of sounds used in the game. + * Enum representing various sound effects in the game. */ public enum Sound { + /** + * UC-sound-01: Sound effect for passing the start/Los field. + */ + PASS_START, + /** + * UC-sound-02: Sound effect for drawing an event card. + */ + EVENT_CARD, + + /** + * UC-sound-03: Sound effect for entering the Gulag. + */ + GULAG, + + /** + * UC-sound-04: Sound effect for rolling the dice. + */ + DICE_ROLL, + + /** + * UC-sound-05: Sound effect for collecting money. + */ + MONEY_COLLECTED, + + /** + * UC-sound-06: Sound effect for losing money. + */ + MONEY_LOST, + + /** + * UC-sound-07: Sound effect for accepting a trade offer. + */ + TRADE_ACCEPTED, + + /** + * UC-sound-08: Sound effect for rejecting a trade offer. + */ + TRADE_REJECTED, + + /** + * UC-sound-09: Sound effect for winning the game. + */ + WINNER, + + /** + * UC-sound-10: Sound effect for losing the game. + */ + LOSER, + + /** + * UC-sound-11: Sound effect for button click. + */ + BUTTON; } From af4b4243ea5b70d505d4c44fb111d72bfe67e97d Mon Sep 17 00:00:00 2001 From: Luca Puderbach Date: Mon, 18 Nov 2024 04:42:30 +0100 Subject: [PATCH 02/21] Resolve merge conflicts --- .../java/pp/monopoly/client/MonopolyApp.java | 51 +----- .../pp/monopoly/client/MonopolyAppConfig.java | 9 +- .../pp/monopoly/client/MonopolyAppState.java | 2 +- .../pp/monopoly/client/NetworkDialog.java | 3 +- .../pp/monopoly/client/NetworkSupport.java | 2 +- .../java/pp/monopoly/client/StartMenu.java | 162 +++++++++--------- .../monopoly/client/gui/CreateGameMenu.java | 2 +- .../java/pp/monopoly/client/gui/GameMenu.java | 1 + .../pp/monopoly/client/gui/SettingsMenu.java | 122 +++++-------- .../monopoly/game/client/ClientGameLogic.java | 26 +-- 10 files changed, 139 insertions(+), 241 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 68c73d9..422a1f9 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 @@ -55,55 +55,6 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga setSettings(makeSettings()); } - /** - * Creates and configures application settings from the client configuration. - * - * @return A configured {@link AppSettings} object. - */ - private AppSettings makeSettings() { - final AppSettings settings = new AppSettings(true); - settings.setTitle(lookup("monopoly.name")); - settings.setResolution(config.getResolutionWidth(), config.getResolutionHeight()); - settings.setFullscreen(config.fullScreen()); - settings.setUseRetinaFrameBuffer(config.useRetinaFrameBuffer()); - settings.setGammaCorrection(config.useGammaCorrection()); - return settings; - } - - /** - * Factory method for creating a server connection based on the current - * client configuration. - * - * @return A {@link ServerConnection} instance, which could be a real or mock server. - */ - private ServerConnection makeServerConnection() { - return new NetworkSupport(this); - } - - /** - * Returns the dialog manager responsible for managing in-game dialogs. - * - * @return The {@link DialogManager} instance. - */ - public DialogManager getDialogManager() { - return dialogManager; - } - - /** - * Returns the game logic handler for the client. - * - * @return The {@link ClientGameLogic} instance. - */ - @Override - public ClientGameLogic getGameLogic() { - return logic; - } - - /** - * Returns the current configuration settings for the Monopoly client. - * - * @return The {@link MonopolyClientConfig} instance. - */ @Override public MonopolyAppConfig getConfig() { return config; @@ -243,4 +194,4 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga } -} +} \ No newline at end of file diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/MonopolyAppConfig.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/MonopolyAppConfig.java index e126f75..15a69f1 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/MonopolyAppConfig.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/MonopolyAppConfig.java @@ -1,10 +1,3 @@ -//////////////////////////////////////// -// Programming project code -// UniBw M, 2022, 2023, 2024 -// www.unibw.de/inf2 -// (c) Mark Minas (mark.minas@unibw.de) -//////////////////////////////////////// - package pp.monopoly.client; import com.jme3.math.ColorRGBA; @@ -194,4 +187,4 @@ public class MonopolyAppConfig extends MonopolyClientConfig { public ColorRGBA getTopColor() { return topColor; } -} +} \ No newline at end of file diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/MonopolyAppState.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/MonopolyAppState.java index 76b002e..ec11aa4 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/MonopolyAppState.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/MonopolyAppState.java @@ -81,4 +81,4 @@ public abstract class MonopolyAppState extends AbstractAppState { * Called when the state is disabled. Override to define specific behavior. */ protected abstract void disableState(); -} +} \ No newline at end of file diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/NetworkDialog.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/NetworkDialog.java index 6671b7b..d399636 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/NetworkDialog.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/NetworkDialog.java @@ -142,4 +142,5 @@ class NetworkDialog extends SimpleDialog { network.getApp().errorDialog("Verbindung zum Server fehlgeschlagen."); network.getApp().setInfoText(e.getLocalizedMessage()); } -} + +} \ No newline at end of file diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/NetworkSupport.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/NetworkSupport.java index 065bcf6..3ea11b0 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/NetworkSupport.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/NetworkSupport.java @@ -141,4 +141,4 @@ class NetworkSupport implements MessageListener, ClientStateListener, Se client.send(message); } } -} +} \ No newline at end of file diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/StartMenu.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/StartMenu.java index 75c37a2..9ebbc14 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/StartMenu.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/StartMenu.java @@ -1,117 +1,123 @@ package pp.monopoly.client; -import com.jme3.asset.TextureKey; import com.jme3.material.Material; +import com.jme3.math.ColorRGBA; import com.jme3.math.Vector3f; import com.jme3.scene.Geometry; import com.jme3.scene.shape.Quad; import com.jme3.texture.Texture; +import com.simsilica.lemur.Axis; import com.simsilica.lemur.Button; -import com.simsilica.lemur.Insets3f; -import com.simsilica.lemur.Label; -import com.simsilica.lemur.Panel; -import com.simsilica.lemur.style.ElementId; +import com.simsilica.lemur.Container; +import com.simsilica.lemur.HAlignment; import com.simsilica.lemur.component.QuadBackgroundComponent; -import com.jme3.math.ColorRGBA; +import com.simsilica.lemur.component.SpringGridLayout; + import pp.dialog.Dialog; +import pp.monopoly.client.gui.CreateGameMenu; +import pp.monopoly.client.gui.SettingsMenu; + +/** + * Constructs the startup menu dialog for the Monopoly application. import pp.monopoly.client.gui.GameMenu; -import pp.dialog.DialogManager; - -import java.util.prefs.Preferences; - -import static pp.monopoly.Resources.lookup; -import static pp.util.PreferencesUtils.getPreferences; - + */ public class StartMenu extends Dialog { - private static final Preferences PREFERENCES = getPreferences(StartMenu.class); private final MonopolyApp app; - // Buttons for the menu - private final Button playButton = new Button(lookup("button.play")); - private final Button quitButton = new Button(lookup("menu.quit")); - private final Button settingsButton = new Button("Einstellungen", new ElementId("menu-button")); - /** - * Constructs the StartMenu dialog for the Monopoly application. + * Constructs the Startup Menu dialog for the Monopoly application. * * @param app the MonopolyApp instance */ public StartMenu(MonopolyApp app) { super(app.getDialogManager()); this.app = app; + } - // Load and display the background image - TextureKey backgroundKey = new TextureKey("unibw-bib", false); - Texture backgroundTexture = app.getAssetManager().loadTexture(backgroundKey); + /** + * Creates and displays the Start Menu with buttons for starting the game, + * opening settings, and quitting the application. + */ + public static void createStartMenu(MonopolyApp app) { + int screenWidth = app.getContext().getSettings().getWidth(); + int screenHeight = app.getContext().getSettings().getHeight(); + + // Set up the background image + Texture backgroundImage = app.getAssetManager().loadTexture("Pictures/unibw-Bib2.png"); + Quad quad = new Quad(screenWidth, screenHeight); + Geometry background = new Geometry("Background", quad); Material backgroundMaterial = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); - backgroundMaterial.setTexture("ColorMap", backgroundTexture); - - // Create a large Quad for the background - Quad backgroundQuad = new Quad(16, 9); // Adjust size as necessary to fill the screen - Geometry background = new Geometry("Background", backgroundQuad); + backgroundMaterial.setTexture("ColorMap", backgroundImage); background.setMaterial(backgroundMaterial); - background.setLocalTranslation(new Vector3f(-8, -4.5f, -1)); // Position it behind the UI components - - // Attach the background as the first element + background.setLocalTranslation(0, 0, -1); // Ensure it is behind other GUI elements app.getGuiNode().attachChild(background); - // Load and display the Monopoly logo - TextureKey monopolyLogoKey = new TextureKey("log-Monopoly", false); - Texture monopolyLogoTexture = app.getAssetManager().loadTexture(monopolyLogoKey); - Material monopolyLogoMaterial = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); - monopolyLogoMaterial.setTexture("ColorMap", monopolyLogoTexture); + // Center container for title and play button + Container centerMenu = new Container(new SpringGridLayout(Axis.Y, Axis.X)); - Quad monopolyQuad = new Quad(5, 1.5f); // Adjust dimensions as necessary - Geometry monopolyLogo = new Geometry("MonopolyLogo", monopolyQuad); - monopolyLogo.setMaterial(monopolyLogoMaterial); - monopolyLogo.setLocalTranslation(new Vector3f(0, 5, 0)); // Position Monopoly logo at the top + 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 - Panel monopolyLogoPanel = new Panel(); - addChild(monopolyLogoPanel); + // Set a custom border and background color + ColorRGBA borderColor = ColorRGBA.Orange; // Example: White border + ColorRGBA backgroundColor = ColorRGBA.LightGray; // Example: light gray background + QuadBackgroundComponent backgroundColorSp = new QuadBackgroundComponent(backgroundColor); + backgroundColorSp.setMargin(2, 2); // Optional: Adjust margin for the border + backgroundColorSp.setColor(borderColor); // Set border color + startButton.setBackground(backgroundColorSp); - // Load and display the university logo - TextureKey universityLogoKey = new TextureKey("unibw-logo.png", false); - Texture universityLogoTexture = app.getAssetManager().loadTexture(universityLogoKey); - Material universityLogoMaterial = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); - universityLogoMaterial.setTexture("ColorMap", universityLogoTexture); + startButton.addClickCommands(source -> startGame(app)); + centerMenu.addChild(startButton); - Quad universityQuad = new Quad(4, 1); // Adjust dimensions to fit below Monopoly logo - Geometry universityLogo = new Geometry("UniversityLogo", universityQuad); - universityLogo.setMaterial(universityLogoMaterial); - universityLogo.setLocalTranslation(new Vector3f(0, 3, 0)); // Position below the Monopoly logo + // 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)); + app.getGuiNode().attachChild(centerMenu); - Panel universityLogoPanel = new Panel(); - addChild(universityLogoPanel); + // Lower-left container for "Spiel beenden" button + Container lowerLeftMenu = new Container(); + lowerLeftMenu.setLocalTranslation(new Vector3f(100, 90, 0)); + Button quitButton = new Button("Spiel beenden"); + quitButton.setPreferredSize(new Vector3f(130, 40, 0)); // Increase button size slightly (width, height) + quitButton.setFontSize(20); + quitButton.addClickCommands(source -> quitGame()); + lowerLeftMenu.addChild(quitButton); + app.getGuiNode().attachChild(lowerLeftMenu); - - - // Button actions - playButton.addClickCommands(source -> startGame()); - quitButton.addClickCommands(source -> app.closeApp()); - settingsButton.addClickCommands(source -> openSettings()); - - addChild(monopolyLogoPanel); - addChild(universityLogoPanel); - addChild(playButton); - addChild(quitButton); - addChild(settingsButton); + // Lower-right container for "Einstellungen" button + Container lowerRightMenu = new Container(); + lowerRightMenu.setLocalTranslation(new Vector3f(screenWidth - 200, 90, 0)); + Button settingsButton = new Button("Einstellungen"); + settingsButton.setPreferredSize(new Vector3f(130, 40, 0)); // Increase button size slightly (width, height) + settingsButton.setFontSize(20); // Increase the font size for the text + settingsButton.addClickCommands(source -> openSettings(app)); + lowerRightMenu.addChild(settingsButton); + app.getGuiNode().attachChild(lowerRightMenu); } - private void startGame() { - System.out.println("Starting game..."); + /** + * Starts the game by transitioning to the CreateGameMenu. + */ + private static void startGame(MonopolyApp app) { + app.getGuiNode().detachAllChildren(); + new CreateGameMenu(app); } - private void openSettings() { - app.getDialogManager().close(this); - app.getDialogManager().open(new GameMenu(app)); + /** + * Opens the settings menu. + */ + private static void openSettings(MonopolyApp app) { + app.getGuiNode().detachAllChildren(); + new SettingsMenu(app); } - @Override - public void update() { + /** + * Quits the game application. + */ + private static void quitGame() { + System.exit(0); } - - @Override - public void escape() { - close(); - } -} +} \ No newline at end of file diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/CreateGameMenu.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/CreateGameMenu.java index 6b88b62..c6ae9bc 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/CreateGameMenu.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/CreateGameMenu.java @@ -126,4 +126,4 @@ public class CreateGameMenu { } -} +} \ No newline at end of file diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/GameMenu.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/GameMenu.java index ef5dd78..da390c8 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/GameMenu.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/GameMenu.java @@ -5,6 +5,7 @@ import com.jme3.math.ColorRGBA; import com.simsilica.lemur.Button; import com.simsilica.lemur.Label; import com.simsilica.lemur.style.ElementId; + import pp.dialog.Dialog; import pp.monopoly.client.MonopolyApp; 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 eb882da..1424bd4 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 @@ -1,10 +1,10 @@ package pp.monopoly.client.gui; +import com.jme3.material.Material; +import com.jme3.material.RenderState.BlendMode; import com.jme3.math.ColorRGBA; import com.jme3.scene.Geometry; -import com.jme3.scene.Node; import com.jme3.scene.shape.Quad; -import com.jme3.texture.Texture; import com.simsilica.lemur.Button; import com.simsilica.lemur.Checkbox; import com.simsilica.lemur.Container; @@ -16,122 +16,80 @@ import com.simsilica.lemur.style.ElementId; import pp.dialog.Dialog; import pp.monopoly.client.MonopolyApp; +/** + * SettingsMenu ist ein Overlay-Menü, das durch ESC aufgerufen werden kann. + */ public class SettingsMenu extends Dialog { private final MonopolyApp app; + private final Geometry overlayBackground; private final Container settingsContainer; - private Geometry blockLayer; - private final Node savedGuiNodeContent = new Node("SavedGuiNodeContent"); public SettingsMenu(MonopolyApp app) { super(app.getDialogManager()); this.app = app; - // Blockierungsebene hinzufügen - addBlockLayer(); - - // Hintergrundbild - addBackgroundImage(); + // Halbtransparentes Overlay hinzufügen + overlayBackground = createOverlayBackground(); + app.getGuiNode().attachChild(overlayBackground); + // Hauptcontainer für das Menü settingsContainer = new Container(); + settingsContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.1f, 0.1f, 0.1f, 0.9f))); - // Hintergrundfarbe für das Container-Element setzen, um es undurchsichtig zu machen - settingsContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.1f, 0.1f, 0.1f, 0.8f))); // Teiltransparent, falls gewünscht - - // Titel "Einstellungen" + // Titel Label settingsTitle = settingsContainer.addChild(new Label("Einstellungen", new ElementId("settings-title"))); settingsTitle.setFontSize(48); - settingsTitle.setColor(ColorRGBA.White); - // Effekt Sound mit Slider und Checkbox + // Effekt-Sound: Slider und Checkbox Container effectSoundContainer = settingsContainer.addChild(new Container()); - Label effectSoundLabel = effectSoundContainer.addChild(new Label("Effekt Sound", new ElementId("label"))); - effectSoundLabel.setFontSize(24); - effectSoundLabel.setColor(ColorRGBA.White); + effectSoundContainer.addChild(new Label("Effekt Sound", new ElementId("label"))); + effectSoundContainer.addChild(new Slider()); + effectSoundContainer.addChild(new Checkbox("Aktivieren")).setChecked(true); - Slider effectSoundSlider = effectSoundContainer.addChild(new Slider()); - effectSoundSlider.setPreferredSize(new com.jme3.math.Vector3f(300, 30, 0)); - - Checkbox effectSoundCheckbox = effectSoundContainer.addChild(new Checkbox("")); - effectSoundCheckbox.setChecked(true); - - // Hintergrund Musik mit Slider und Checkbox + // Hintergrundmusik: Slider und Checkbox Container backgroundMusicContainer = settingsContainer.addChild(new Container()); - Label backgroundMusicLabel = backgroundMusicContainer.addChild(new Label("Hintergrund Musik", new ElementId("label"))); - backgroundMusicLabel.setFontSize(24); - backgroundMusicLabel.setColor(ColorRGBA.White); + backgroundMusicContainer.addChild(new Label("Hintergrund Musik", new ElementId("label"))); + backgroundMusicContainer.addChild(new Slider()); + backgroundMusicContainer.addChild(new Checkbox("Aktivieren")).setChecked(true); - Slider backgroundMusicSlider = backgroundMusicContainer.addChild(new Slider()); - backgroundMusicSlider.setPreferredSize(new com.jme3.math.Vector3f(300, 30, 0)); - - Checkbox backgroundMusicCheckbox = backgroundMusicContainer.addChild(new Checkbox("")); - backgroundMusicCheckbox.setChecked(true); - - // Beenden Button + // Beenden-Button Button quitButton = settingsContainer.addChild(new Button("Beenden", new ElementId("menu-button"))); quitButton.setFontSize(32); - quitButton.setColor(ColorRGBA.White); quitButton.addClickCommands(source -> app.stop()); - // Zentrieren des Containers + // Zentriere das Menü settingsContainer.setLocalTranslation( (app.getCamera().getWidth() - settingsContainer.getPreferredSize().x) / 2, (app.getCamera().getHeight() + settingsContainer.getPreferredSize().y) / 2, - 1 // Höhere Z-Ebene für den Vordergrund + 1 ); app.getGuiNode().attachChild(settingsContainer); } - private void addBlockLayer() { - // Sichern des aktuellen GUI-Inhalts - for (var child : app.getGuiNode().getChildren()) { - savedGuiNodeContent.attachChild(child); - } - app.getGuiNode().detachAllChildren(); - - // Blockierungsebene erstellen und hinzufügen - blockLayer = new Geometry("BlockLayer", new Quad(app.getCamera().getWidth(), app.getCamera().getHeight())); - blockLayer.setMaterial(createTransparentMaterial()); - blockLayer.setLocalTranslation(0, 0, 0); // Platzierung unterhalb des SettingsMenu - app.getGuiNode().attachChild(blockLayer); - } - - private com.jme3.material.Material createTransparentMaterial() { - com.jme3.material.Material material = new com.jme3.material.Material( - app.getAssetManager(), - "Common/MatDefs/Misc/Unshaded.j3md" - ); - material.setColor("Color", new ColorRGBA(0, 0, 0, 0.5f)); // Halbtransparent - material.getAdditionalRenderState().setBlendMode(com.jme3.material.RenderState.BlendMode.Alpha); - return material; - } - - private void addBackgroundImage() { - Texture backgroundImage = app.getAssetManager().loadTexture("Pictures/unibw-Bib2.png"); + /** + * Erstellt einen halbtransparenten Hintergrund für das Menü. + * + * @return Geometrie des Overlays + */ + private Geometry createOverlayBackground() { Quad quad = new Quad(app.getCamera().getWidth(), app.getCamera().getHeight()); - Geometry background = new Geometry("Background", quad); - com.jme3.material.Material backgroundMaterial = new com.jme3.material.Material( - app.getAssetManager(), - "Common/MatDefs/Misc/Unshaded.j3md" - ); - backgroundMaterial.setTexture("ColorMap", backgroundImage); - background.setMaterial(backgroundMaterial); - background.setLocalTranslation(0, 0, -1); // Platzierung hinter dem SettingsMenu - app.getGuiNode().attachChild(background); + Geometry overlay = new Geometry("Overlay", quad); + Material material = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); + material.setColor("Color", new ColorRGBA(0, 0, 0, 0.5f)); // Halbtransparent + material.getAdditionalRenderState().setBlendMode(BlendMode.Alpha); + overlay.setMaterial(material); + overlay.setLocalTranslation(0, 0, 0); + return overlay; } + /** + * Schließt das Menü und entfernt die GUI-Elemente. + */ @Override public void close() { - // Entfernt das SettingsMenu und die Blockierungsebene app.getGuiNode().detachChild(settingsContainer); - app.getGuiNode().detachChild(blockLayer); - - // Stellt die ursprüngliche GUI wieder her - for (var child : savedGuiNodeContent.getChildren()) { - app.getGuiNode().attachChild(child); - } - savedGuiNodeContent.detachAllChildren(); - + app.getGuiNode().detachChild(overlayBackground); app.setSettingsMenuOpen(false); } } diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ClientGameLogic.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ClientGameLogic.java index e05af47..fa28b52 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ClientGameLogic.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ClientGameLogic.java @@ -7,6 +7,13 @@ package pp.monopoly.game.client; +import java.io.File; +import java.io.IOException; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; +import java.util.ArrayList; +import java.util.List; + import pp.monopoly.message.client.ClientMessage; import pp.monopoly.message.server.BuyPropertyResponse; import pp.monopoly.message.server.DiceResult; @@ -21,25 +28,6 @@ import pp.monopoly.message.server.TradeReply; import pp.monopoly.message.server.TradeRequest; import pp.monopoly.message.server.UpdatePlayerAssets; import pp.monopoly.message.server.ViewAssetsResponse; -import pp.monopoly.model.IntPoint; -import pp.monopoly.model.Board; -import pp.monopoly.notification.ClientStateEvent; -import pp.monopoly.notification.GameEvent; -import pp.monopoly.notification.GameEventBroker; -import pp.monopoly.notification.GameEventListener; -import pp.monopoly.notification.InfoTextEvent; -import pp.monopoly.notification.Sound; -import pp.monopoly.notification.SoundEvent; - -import java.io.File; -import java.io.IOException; -import java.lang.System.Logger; -import java.lang.System.Logger.Level; -import java.util.ArrayList; -import java.util.List; - -import pp.monopoly.message.client.ClientMessage; -import pp.monopoly.message.server.ServerInterpreter; import pp.monopoly.model.Board; import pp.monopoly.model.IntPoint; import pp.monopoly.notification.ClientStateEvent; From cac06dda7d6027088bf6e6fd64dd2a7f53c1d18b Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Mon, 18 Nov 2024 04:01:41 +0000 Subject: [PATCH 03/21] Refactor --- .../monopoly/game/server/PlayerHandler.java | 6 +- .../monopoly/model/fields/BoardManager.java | 80 +++++++++---------- 2 files changed, 44 insertions(+), 42 deletions(-) diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerHandler.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerHandler.java index a5cc850..d7bbe10 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerHandler.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerHandler.java @@ -109,8 +109,10 @@ public class PlayerHandler { * @return the next players who is active */ Player nextPlayer() { - players.addLast(players.removeFirst()); - return players.getFirst(); + Player tmp = players.get(0); + players.remove(0); + players.add(tmp); + return players.get(0); } /** diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/model/fields/BoardManager.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/model/fields/BoardManager.java index cf0b74d..0cb7c0c 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/model/fields/BoardManager.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/model/fields/BoardManager.java @@ -25,46 +25,46 @@ public class BoardManager { private static List createBoard() { ArrayList fields = new ArrayList<>(); - fields.addLast(new GoField()); - fields.addLast(new BuildingProperty("Gym", 1, 600, 20)); - fields.addLast(new EventField("Hausfeier", 2)); - fields.addLast(new BuildingProperty("Sportplatz", 3, 600, 40)); - fields.addLast(new FineField("Diszi", 4, 2000)); - fields.addLast(new GateField("Südtor", 5)); - fields.addLast(new BuildingProperty("Studium+", 6, 1000, 60)); - fields.addLast(new EventField("Üvas", 7)); - fields.addLast(new BuildingProperty("PhysikHörsaal", 8, 1000, 60)); - fields.addLast(new BuildingProperty("Audimax", 9, 1200, 80)); - fields.addLast(new GulagField()); - fields.addLast(new BuildingProperty("99er", 11, 1400, 100)); - fields.addLast(new FoodField("Brandl", 12)); - fields.addLast(new BuildingProperty("12er", 13, 1400, 100)); - fields.addLast(new BuildingProperty("23er", 14, 1600, 120)); - fields.addLast(new GateField("HauptWache", 15)); - fields.addLast(new BuildingProperty("Schwimmhalle", 16, 1800, 140)); - fields.addLast(new BuildingProperty("CISM-Bahn", 17, 1800, 140)); - fields.addLast(new EventField("Marine-Welcome-Party", 18)); - fields.addLast(new BuildingProperty("Kletterturm", 19, 2000, 160)); - fields.addLast(new TestStreckeField()); - fields.addLast(new BuildingProperty("StudFBer C", 21, 2200, 180)); - fields.addLast(new EventField("Üvas", 22)); - fields.addLast(new BuildingProperty("StudFBer B", 23, 2200, 180)); - fields.addLast(new BuildingProperty("StudFBer A", 24, 2400, 200)); - fields.addLast(new GateField("Nordtor", 25)); - fields.addLast(new BuildingProperty("Cascada", 26, 2600, 220)); - fields.addLast(new BuildingProperty("Fakultätsgebäude", 27, 2600, 220)); - fields.addLast(new FoodField("Truppenküche", 28)); - fields.addLast(new BuildingProperty("Prüfungsamt", 29, 2800, 240)); - fields.addLast(new WacheField()); - fields.addLast(new BuildingProperty("Feuerwehr", 31, 3000, 260)); - fields.addLast(new BuildingProperty("SanZ", 32, 300, 260)); - fields.addLast(new EventField("Maibock", 33)); - fields.addLast(new BuildingProperty("Rechenzentrum", 34, 3200, 280)); - fields.addLast(new GateField("Osttor", 35)); - fields.addLast(new EventField("Üvas", 36)); - fields.addLast(new BuildingProperty("2er", 37, 3500, 350)); - fields.addLast(new FineField("EZM", 38, 1000)); - fields.addLast(new BuildingProperty("20er", 39, 4000, 500)); + fields.add(new GoField()); + fields.add(new BuildingProperty("Gym", 1, 600, 20)); + fields.add(new EventField("Hausfeier", 2)); + fields.add(new BuildingProperty("Sportplatz", 3, 600, 40)); + fields.add(new FineField("Diszi", 4, 2000)); + fields.add(new GateField("Südtor", 5)); + fields.add(new BuildingProperty("Studium+", 6, 1000, 60)); + fields.add(new EventField("Üvas", 7)); + fields.add(new BuildingProperty("PhysikHörsaal", 8, 1000, 60)); + fields.add(new BuildingProperty("Audimax", 9, 1200, 80)); + fields.add(new GulagField()); + fields.add(new BuildingProperty("99er", 11, 1400, 100)); + fields.add(new FoodField("Brandl", 12)); + fields.add(new BuildingProperty("12er", 13, 1400, 100)); + fields.add(new BuildingProperty("23er", 14, 1600, 120)); + fields.add(new GateField("HauptWache", 15)); + fields.add(new BuildingProperty("Schwimmhalle", 16, 1800, 140)); + fields.add(new BuildingProperty("CISM-Bahn", 17, 1800, 140)); + fields.add(new EventField("Marine-Welcome-Party", 18)); + fields.add(new BuildingProperty("Kletterturm", 19, 2000, 160)); + fields.add(new TestStreckeField()); + fields.add(new BuildingProperty("StudFBer C", 21, 2200, 180)); + fields.add(new EventField("Üvas", 22)); + fields.add(new BuildingProperty("StudFBer B", 23, 2200, 180)); + fields.add(new BuildingProperty("StudFBer A", 24, 2400, 200)); + fields.add(new GateField("Nordtor", 25)); + fields.add(new BuildingProperty("Cascada", 26, 2600, 220)); + fields.add(new BuildingProperty("Fakultätsgebäude", 27, 2600, 220)); + fields.add(new FoodField("Truppenküche", 28)); + fields.add(new BuildingProperty("Prüfungsamt", 29, 2800, 240)); + fields.add(new WacheField()); + fields.add(new BuildingProperty("Feuerwehr", 31, 3000, 260)); + fields.add(new BuildingProperty("SanZ", 32, 300, 260)); + fields.add(new EventField("Maibock", 33)); + fields.add(new BuildingProperty("Rechenzentrum", 34, 3200, 280)); + fields.add(new GateField("Osttor", 35)); + fields.add(new EventField("Üvas", 36)); + fields.add(new BuildingProperty("2er", 37, 3500, 350)); + fields.add(new FineField("EZM", 38, 1000)); + fields.add(new BuildingProperty("20er", 39, 4000, 500)); return fields; } From a7ea5773da6d591b6e7747bdf231694bcb3ebce1 Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Mon, 18 Nov 2024 05:05:37 +0100 Subject: [PATCH 04/21] resolve merge conflict --- .../pp/monopoly/notification/SoundEvent.java | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/notification/SoundEvent.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/notification/SoundEvent.java index b42ed7d..2eaaefe 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/notification/SoundEvent.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/notification/SoundEvent.java @@ -1,25 +1,26 @@ +//////////////////////////////////////// +// Programming project code +// UniBw M, 2022, 2023, 2024 +// www.unibw.de/inf2 +// (c) Mark Minas (mark.minas@unibw.de) +//////////////////////////////////////// + package pp.monopoly.notification; /** - * Event when a sound needs to be played. + * Event when an item is added to a map. * - * @param soundFileName the sound file to be played + * @param sound the sound to be played */ -public class SoundEvent implements GameEvent { - private final String soundFileName; - - public SoundEvent(Sound sound) { - this.soundFileName = sound.getFileName(); // Angenommen, Sound hat eine Methode getFileName() - } - - public String getSoundFileName() { - return soundFileName; - } +public record SoundEvent(Sound sound) implements GameEvent { + /** + * Notifies the game event listener of this event. + * + * @param listener the game event listener + */ @Override public void notifyListener(GameEventListener listener) { listener.receivedEvent(this); } } - - From 6dcfb92dba09d9c99b94e2cfa09c74e187e1b964 Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Mon, 18 Nov 2024 05:07:41 +0100 Subject: [PATCH 05/21] resolve merge conflict --- .../java/pp/monopoly/client/GameSound.java | 83 +++++++++++++------ 1 file changed, 56 insertions(+), 27 deletions(-) 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 df498f5..ec54da2 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 @@ -1,28 +1,39 @@ +//////////////////////////////////////// +// Programming project code +// UniBw M, 2022, 2023, 2024 +// www.unibw.de/inf2 +// (c) Mark Minas (mark.minas@unibw.de) +//////////////////////////////////////// + package pp.monopoly.client; +import com.jme3.app.Application; +import com.jme3.app.state.AbstractAppState; +import com.jme3.app.state.AppStateManager; +import com.jme3.asset.AssetLoadException; +import com.jme3.asset.AssetNotFoundException; +import com.jme3.audio.AudioData; +import com.jme3.audio.AudioNode; +import pp.monopoly.notification.GameEventListener; +import pp.monopoly.notification.SoundEvent; + 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; -import com.jme3.audio.AudioData; -import com.jme3.audio.AudioNode; - -import pp.monopoly.notification.GameEventListener; -import pp.monopoly.notification.SoundEvent; import static pp.util.PreferencesUtils.getPreferences; /** - * An application state that plays sounds based on game events. + * An application state that plays sounds. */ public class GameSound extends AbstractAppState implements GameEventListener { private static final Logger LOGGER = System.getLogger(GameSound.class.getName()); private static final Preferences PREFERENCES = getPreferences(GameSound.class); - private static final String ENABLED_PREF = "enabled"; + private static final String ENABLED_PREF = "enabled"; //NON-NLS - private Application app; // Feld zum Speichern der Application-Instanz + private AudioNode splashSound; + private AudioNode shipDestroyedSound; + private AudioNode explosionSound; /** * Checks if sound is enabled in the preferences. @@ -42,6 +53,7 @@ public class GameSound extends AbstractAppState implements GameEventListener { /** * Sets the enabled state of this AppState. + * Overrides {@link com.jme3.app.state.AbstractAppState#setEnabled(boolean)} * * @param enabled {@code true} to enable the AppState, {@code false} to disable it. */ @@ -49,52 +61,69 @@ public class GameSound extends AbstractAppState implements GameEventListener { public void setEnabled(boolean enabled) { if (isEnabled() == enabled) return; super.setEnabled(enabled); - LOGGER.log(Level.INFO, "Sound enabled: {0}", enabled); + LOGGER.log(Level.INFO, "Sound enabled: {0}", enabled); //NON-NLS PREFERENCES.putBoolean(ENABLED_PREF, enabled); } /** - * Initializes the sound effects for the game and stores the application reference. + * Initializes the sound effects for the game. + * Overrides {@link AbstractAppState#initialize(AppStateManager, Application)} * * @param stateManager The state manager - * @param app The application instance + * @param app The application */ @Override public void initialize(AppStateManager stateManager, Application app) { super.initialize(stateManager, app); - this.app = app; // Speichert die Application-Instanz } /** * Loads a sound from the specified file. * + * @param app The application * @param name The name of the sound file. * @return The loaded AudioNode. */ - private AudioNode loadSound(String name) { + private AudioNode loadSound(Application app, String name) { try { - AudioNode sound = new AudioNode(app.getAssetManager(), name, AudioData.DataType.Buffer); + final AudioNode sound = new AudioNode(app.getAssetManager(), name, AudioData.DataType.Buffer); sound.setLooping(false); sound.setPositional(false); return sound; - } catch (Exception ex) { + } + catch (AssetLoadException | AssetNotFoundException ex) { LOGGER.log(Level.ERROR, ex.getMessage(), ex); } return null; } /** - * Handles sound-related game events to play specific sounds. - * - * @param event The sound event received. + * Plays the splash sound effect. */ + public void splash() { + if (isEnabled() && splashSound != null) + splashSound.playInstance(); + } + + /** + * Plays the explosion sound effect. + */ + public void explosion() { + if (isEnabled() && explosionSound != null) + explosionSound.playInstance(); + } + + /** + * Plays sound effect when a ship has been destroyed. + */ + public void shipDestroyed() { + if (isEnabled() && shipDestroyedSound != null) + shipDestroyedSound.playInstance(); + } + @Override public void receivedEvent(SoundEvent event) { - if (isEnabled()) { - AudioNode sound = loadSound(event.getSoundFileName()); - if (sound != null) { - sound.play(); - } + switch (event.sound()) { } } -}//heloo +} From 8e3cb432449c774c16f797d784108c31ddafa4c4 Mon Sep 17 00:00:00 2001 From: Yvonne Schmidt Date: Mon, 18 Nov 2024 05:32:33 +0100 Subject: [PATCH 06/21] =?UTF-8?q?eigenes=20GUI=20Styling=20eingef=C3=BChrt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Interface/Lemur/pp-styles.groovy | 185 +++++++++++++----- .../java/pp/monopoly/client/MonopolyApp.java | 16 +- 2 files changed, 154 insertions(+), 47 deletions(-) diff --git a/Projekte/jme-common/src/main/resources/Interface/Lemur/pp-styles.groovy b/Projekte/jme-common/src/main/resources/Interface/Lemur/pp-styles.groovy index 957bc68..ed033be 100644 --- a/Projekte/jme-common/src/main/resources/Interface/Lemur/pp-styles.groovy +++ b/Projekte/jme-common/src/main/resources/Interface/Lemur/pp-styles.groovy @@ -1,76 +1,60 @@ // Styling of Lemur components // For documentation, see: // https://github.com/jMonkeyEngine-Contributions/Lemur/wiki/Styling - import com.simsilica.lemur.* import com.simsilica.lemur.component.QuadBackgroundComponent +import com.simsilica.lemur.Button +import com.simsilica.lemur.Button.ButtonAction +import com.simsilica.lemur.Command +import com.simsilica.lemur.HAlignment +import com.simsilica.lemur.Insets3f +import com.simsilica.lemur.component.QuadBackgroundComponent +import com.simsilica.lemur.component.TbtQuadBackgroundComponent -def bgColor = color(1, 1, 1, 1) +def bgColor = color(0.25, 0.5, 0.5, 1) def buttonEnabledColor = color(0.8, 0.9, 1, 1) def buttonDisabledColor = color(0.8, 0.9, 1, 0.2) -//def buttonBgColor = color(0, 0.75, 0.75, 1) +def buttonBgColor = color(0, 0.75, 0.75, 1) def sliderColor = color(0.6, 0.8, 0.8, 1) def sliderBgColor = color(0.5, 0.75, 0.75, 1) -def gradientColor = color(1, 1, 1, 1) +def gradientColor = color(0.5, 0.75, 0.85, 0.5) def tabbuttonEnabledColor = color(0.4, 0.45, 0.5, 1) -def playButtonBorderColor = color(1, 0.6, 0, 1) // For "Spielen" button -def blackColor = color(0, 0, 0, 1) // Define black color for border - -def playButtonBorderColor = color(1, 0.6, 0, 1) // Orange border for "Spielen" button -def playButtonTextColor = color(0, 0, 0, 1) // Black text color for "Spielen" button -def buttonBgColor = color(1, 1, 1, 1) // White background for "Spiel beenden" and "Einstellungen" buttons -def buttonTextColor = color(0, 0, 0, 1) // Black text color for "Spiel beenden" and "Einstellungen" buttons -def borderColor = color(0, 0, 0, 1) // Black border for "Spiel beenden" and "Einstellungen" def gradient = TbtQuadBackgroundComponent.create( - texture(name: "/com/simsilica/lemur/icons/bordered-gradient.png", generateMips: false), - 1, 1, 1, 126, 126, 1f, false) + texture(name: "/com/simsilica/lemur/icons/bordered-gradient.png", + generateMips: false), + 1, 1, 1, 126, 126, + 1f, false) def doubleGradient = new QuadBackgroundComponent(gradientColor) -doubleGradient.texture = texture(name: "/com/simsilica/lemur/icons/double-gradient-128.png", generateMips: false) +doubleGradient.texture = texture(name: "/com/simsilica/lemur/icons/double-gradient-128.png", + generateMips: false) -// Hauptstil für die Schriftart selector("pp") { font = font("Interface/Fonts/Metropolis/Metropolis-Regular-32.fnt") } -// Titel für "Einstellungen" -selector("settings-title", "pp") { - color = color(1, 1, 1, 1) - fontSize = 48 - textHAlignment = HAlignment.Center - insets = new Insets3f(5, 5, 5, 5) +selector("label", "pp") { + insets = new Insets3f(2, 2, 2, 2) + color = buttonEnabledColor +} + +selector("header", "pp") { + font = font("Interface/Fonts/Metropolis/Metropolis-Bold-42.fnt") + insets = new Insets3f(2, 2, 2, 2) + color = color(1, 0.5, 0, 1) + textHAlignment = HAlignment.Center } -// Container Stil selector("container", "pp") { background = gradient.clone() background.setColor(bgColor) } -// Slider Stil selector("slider", "pp") { - insets = new Insets3f(5, 10, 5, 10) // Abstand - background = new QuadBackgroundComponent(sliderBgColor) -} - -selector("play-button", "pp") { - color = playButtonTextColor // Black text color - background = new QuadBackgroundComponent(playButtonBorderColor) // Orange border background - insets = new Insets3f(15, 25, 15, 25) // Padding for larger button size - background.setMargin(5, 5) // Thin border effect around the background color - fontSize = 36 // Larger font size for prominence -} - -selector("menu-button", "pp") { - color = buttonTextColor // Black text color - background = new QuadBackgroundComponent(buttonBgColor) // White background - insets = new Insets3f(10, 20, 10, 20) // Padding - background.setMargin(1, 1) // Thin black border - background.setColor(borderColor) // Set black border color - - fontSize = 24 // Standard font size + background = gradient.clone() + background.setColor(bgColor) } def pressedCommand = new Command