mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2025-08-03 16:17:09 +02:00
Compare commits
6 Commits
c87406f60e
...
acc797f2ff
Author | SHA1 | Date | |
---|---|---|---|
|
acc797f2ff | ||
|
853c32a5b8 | ||
|
72bef7143a | ||
|
b1ed571950 | ||
|
1a75d6d6a8 | ||
|
c990e7b562 |
@@ -434,4 +434,8 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
|
||||
.build()
|
||||
.open();
|
||||
}
|
||||
|
||||
public void disconnect() {
|
||||
serverConnection.disconnect();
|
||||
}
|
||||
}
|
||||
|
@@ -12,7 +12,11 @@ import java.lang.System.Logger.Level;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import com.jme3.material.Material;
|
||||
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.Button;
|
||||
import com.simsilica.lemur.Container;
|
||||
import com.simsilica.lemur.Label;
|
||||
@@ -23,6 +27,7 @@ import static pp.monopoly.Resources.lookup;
|
||||
|
||||
import pp.monopoly.client.MonopolyApp;
|
||||
import pp.monopoly.client.NetworkSupport;
|
||||
import pp.monopoly.notification.Sound;
|
||||
import pp.monopoly.server.MonopolyServer;
|
||||
import pp.dialog.Dialog;
|
||||
import pp.dialog.DialogBuilder;
|
||||
@@ -59,6 +64,21 @@ public class CreateGameMenu extends Dialog {
|
||||
port.setSingleLine(true);
|
||||
|
||||
final MonopolyApp app = network.getApp();
|
||||
|
||||
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", backgroundImage);
|
||||
background.setMaterial(backgroundMaterial);
|
||||
background.setLocalTranslation(0, 0, -1); // Ensure it is behind other GUI elements
|
||||
app.getGuiNode().attachChild(background);
|
||||
|
||||
|
||||
final Container input = new Container(new SpringGridLayout());
|
||||
input.addChild(new Label(lookup("host.name") + ": "));
|
||||
input.addChild(host, 1);
|
||||
@@ -70,15 +90,25 @@ public class CreateGameMenu extends Dialog {
|
||||
cancelButton.setPreferredSize(new Vector3f(120, 40, 0));
|
||||
cancelButton.addClickCommands(source -> close());
|
||||
addChild(cancelButton);
|
||||
cancelButton.addClickCommands(s -> new StartMenu(app));
|
||||
cancelButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||
this.close();
|
||||
new StartMenu(app);
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
}));
|
||||
|
||||
// "Selber hosten"-Button
|
||||
addChild(serverButton).addClickCommands(s -> startServerInThread());
|
||||
addChild(serverButton).addClickCommands(s -> ifTopDialog(() -> {
|
||||
startServerInThread();
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
}));
|
||||
|
||||
// "Beitreten"-Button
|
||||
joinButton.setPreferredSize(new Vector3f(120, 40, 0));
|
||||
addChild(joinButton);
|
||||
joinButton.addClickCommands(s -> connect());
|
||||
joinButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||
connect();
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -26,6 +26,7 @@ import com.simsilica.lemur.style.ElementId;
|
||||
import pp.dialog.Dialog;
|
||||
import pp.monopoly.client.MonopolyApp;
|
||||
import pp.monopoly.message.client.PlayerReady;
|
||||
import pp.monopoly.notification.Sound;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@@ -133,7 +134,10 @@ public class LobbyMenu extends Dialog {
|
||||
Button cancelButton = new Button("Abbrechen");
|
||||
cancelButton.setPreferredSize(new Vector3f(200, 60, 0)); // Set size to match the appearance in the image
|
||||
cancelButton.setFontSize(18); // Adjust font size
|
||||
cancelButton.addClickCommands(source -> close()); // Add functionality
|
||||
cancelButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||
this.close();
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
}));
|
||||
lowerLeftMenu.addChild(cancelButton);
|
||||
|
||||
// Position the container near the bottom-left corner
|
||||
@@ -146,7 +150,10 @@ public class LobbyMenu extends Dialog {
|
||||
readyButton.setPreferredSize(new Vector3f(200, 60, 0)); // Set size to match the appearance in the image
|
||||
readyButton.setFontSize(18); // Adjust font size
|
||||
readyButton.setBackground(new QuadBackgroundComponent(ColorRGBA.Green)); // Add color to match the style
|
||||
readyButton.addClickCommands(source -> toggleReady()); // Add functionality
|
||||
readyButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||
toggleReady();
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
}));
|
||||
lowerRightMenu.addChild(readyButton);
|
||||
|
||||
// Position the container near the bottom-right corner
|
||||
@@ -254,6 +261,7 @@ public class LobbyMenu extends Dialog {
|
||||
*/
|
||||
private void onDropdownSelectionChanged(String selected) {
|
||||
System.out.println("Selected: " + selected);
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
switch (selected) {
|
||||
case "[0]":
|
||||
figure = "Laptop";
|
||||
|
@@ -20,6 +20,8 @@ import pp.monopoly.client.GameSound;
|
||||
import pp.monopoly.client.MonopolyApp;
|
||||
import pp.dialog.Dialog;
|
||||
import pp.dialog.StateCheckboxModel;
|
||||
import pp.monopoly.notification.Sound;
|
||||
|
||||
import static pp.util.PreferencesUtils.getPreferences;
|
||||
|
||||
/**
|
||||
@@ -56,9 +58,14 @@ public class SettingsMenu extends Dialog {
|
||||
|
||||
addChild(musicSlider);
|
||||
|
||||
addChild(new Button("Zurück zum Spiel", new ElementId("button"))).addClickCommands(s -> ifTopDialog(this::close));
|
||||
addChild(new Button("Beenden", new ElementId("button"))).addClickCommands(s -> ifTopDialog(app::closeApp));
|
||||
|
||||
addChild(new Button("Zurück zum Spiel", new ElementId("button"))).addClickCommands(s -> ifTopDialog(() -> {
|
||||
this.close(); // Close the StartMenu dialog
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
}));
|
||||
addChild(new Button("Beenden", new ElementId("button"))).addClickCommands(s -> ifTopDialog(() -> {
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
app.closeApp();
|
||||
}));
|
||||
update();
|
||||
}
|
||||
|
||||
|
@@ -117,7 +117,7 @@ public class StartMenu extends Dialog {
|
||||
|
||||
@Override
|
||||
public void escape() {
|
||||
super.close();
|
||||
new SettingsMenu(app).open();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -14,6 +14,7 @@ import com.simsilica.lemur.component.SpringGridLayout;
|
||||
import com.simsilica.lemur.style.ElementId;
|
||||
import pp.dialog.Dialog;
|
||||
import pp.monopoly.client.MonopolyApp;
|
||||
import pp.monopoly.notification.Sound;
|
||||
|
||||
/**
|
||||
* Toolbar Klasse, die am unteren Rand der Szene angezeigt wird.
|
||||
@@ -135,7 +136,10 @@ public class Toolbar extends Dialog {
|
||||
private Button addDiceRollButton() {
|
||||
Button diceButton = new Button("Würfeln");
|
||||
diceButton.setPreferredSize(new Vector3f(50, 20, 0));
|
||||
diceButton.addClickCommands(source -> rollDice());
|
||||
diceButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||
rollDice();
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
}));
|
||||
toolbarContainer.addChild(diceButton);
|
||||
return diceButton;
|
||||
}
|
||||
@@ -143,21 +147,30 @@ public class Toolbar extends Dialog {
|
||||
private void addTradeMenuButton() {
|
||||
Button diceButton = new Button("Handeln");
|
||||
diceButton.setPreferredSize(new Vector3f(150, 50, 0)); // Größe des Buttons
|
||||
diceButton.addClickCommands(source -> rollDice());
|
||||
diceButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||
rollDice();
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
}));
|
||||
toolbarContainer.addChild(diceButton);
|
||||
}
|
||||
|
||||
private void addEndTurnButton() {
|
||||
Button diceButton = new Button("Grundstücke");
|
||||
diceButton.setPreferredSize(new Vector3f(150, 50, 0)); // Größe des Buttons
|
||||
diceButton.addClickCommands(source -> rollDice());
|
||||
diceButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||
rollDice();
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
}));
|
||||
toolbarContainer.addChild(diceButton);
|
||||
}
|
||||
|
||||
private void addPropertyMenuButton() {
|
||||
Button diceButton = new Button("Zug beenden");
|
||||
diceButton.setPreferredSize(new Vector3f(150, 50, 0)); // Größe des Buttons
|
||||
diceButton.addClickCommands(source -> rollDice());
|
||||
diceButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||
rollDice();
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
}));
|
||||
toolbarContainer.addChild(diceButton);
|
||||
}
|
||||
|
||||
|
@@ -1,12 +1,20 @@
|
||||
package pp.monopoly.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
/**
|
||||
* Represents the server's response to a player's request to buy a property.
|
||||
*/
|
||||
@Serializable
|
||||
public class BuyPropertyResponse extends ServerMessage{
|
||||
private final boolean successful;
|
||||
private final String propertyName;
|
||||
private final String reason; // Reason for failure, if any
|
||||
private boolean successful;
|
||||
private String propertyName;
|
||||
private String reason; // Reason for failure, if any
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
*/
|
||||
private BuyPropertyResponse() { /* empty */ }
|
||||
|
||||
public BuyPropertyResponse(boolean successful, String propertyName, String reason) {
|
||||
this.successful = successful;
|
||||
|
@@ -2,10 +2,18 @@ package pp.monopoly.message.server;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
@Serializable
|
||||
public class DiceResult extends ServerMessage{
|
||||
|
||||
private List<Integer> rollResult;
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
*/
|
||||
private DiceResult() { /* empty */ }
|
||||
|
||||
public DiceResult(List<Integer> rollResult) {
|
||||
this.rollResult = rollResult;
|
||||
}
|
||||
|
@@ -1,7 +1,15 @@
|
||||
package pp.monopoly.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
@Serializable
|
||||
public class EventDrawCard extends ServerMessage{
|
||||
private final String cardDescription;
|
||||
private String cardDescription;
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
*/
|
||||
private EventDrawCard() { /* empty */ }
|
||||
|
||||
public EventDrawCard(String cardDescription) {
|
||||
this.cardDescription = cardDescription;
|
||||
|
@@ -1,7 +1,15 @@
|
||||
package pp.monopoly.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
@Serializable
|
||||
public class GameOver extends ServerMessage{
|
||||
private final boolean isWinner;
|
||||
private boolean isWinner;
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
*/
|
||||
private GameOver() { /* empty */ }
|
||||
|
||||
public GameOver(boolean isWinner) {
|
||||
this.isWinner = isWinner;
|
||||
|
@@ -1,10 +1,18 @@
|
||||
package pp.monopoly.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import pp.monopoly.game.server.PlayerHandler;
|
||||
|
||||
@Serializable
|
||||
public class GameStart extends ServerMessage{
|
||||
|
||||
private final PlayerHandler ph;
|
||||
private PlayerHandler ph;
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
*/
|
||||
private GameStart() { /* empty */ }
|
||||
|
||||
public GameStart(PlayerHandler ph) {
|
||||
this.ph = ph;
|
||||
|
@@ -1,8 +1,16 @@
|
||||
package pp.monopoly.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
@Serializable
|
||||
public class JailEvent extends ServerMessage{
|
||||
|
||||
private final boolean goingToJail;
|
||||
private boolean goingToJail;
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
*/
|
||||
private JailEvent() { /* empty */ }
|
||||
|
||||
public JailEvent(boolean goingToJail) {
|
||||
this.goingToJail = goingToJail;
|
||||
|
@@ -1,10 +1,18 @@
|
||||
package pp.monopoly.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import pp.monopoly.game.server.Player;
|
||||
|
||||
@Serializable
|
||||
public class NextPlayerTurn extends ServerMessage{
|
||||
|
||||
private final Player player;
|
||||
private Player player;
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
*/
|
||||
private NextPlayerTurn() { /* empty */ }
|
||||
|
||||
public NextPlayerTurn(Player player) {
|
||||
this.player = player;
|
||||
|
@@ -1,12 +1,20 @@
|
||||
package pp.monopoly.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import pp.monopoly.game.server.PlayerColor;
|
||||
|
||||
@Serializable
|
||||
public class PlayerStatusUpdate extends ServerMessage{
|
||||
|
||||
private final String playerName;
|
||||
private final String status;
|
||||
private final PlayerColor color;
|
||||
private String playerName;
|
||||
private String status;
|
||||
private PlayerColor color;
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
*/
|
||||
private PlayerStatusUpdate() { /* empty */ }
|
||||
|
||||
public PlayerStatusUpdate(String playerName, String status, PlayerColor color) {
|
||||
this.playerName = playerName;
|
||||
|
@@ -1,8 +1,16 @@
|
||||
package pp.monopoly.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
@Serializable
|
||||
public class TimeOutWarning extends ServerMessage{
|
||||
|
||||
private final int remainingTime;
|
||||
private int remainingTime;
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
*/
|
||||
private TimeOutWarning() { /* empty */ }
|
||||
|
||||
public TimeOutWarning(int remainingTime) {
|
||||
this.remainingTime = remainingTime;
|
||||
|
@@ -1,14 +1,22 @@
|
||||
package pp.monopoly.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import pp.monopoly.model.TradeHandler;
|
||||
|
||||
/**
|
||||
* Represents a response to a trade offer.
|
||||
*/
|
||||
@Serializable
|
||||
public class TradeReply extends ServerMessage{
|
||||
private int initiatorId;
|
||||
private TradeHandler tradeHandler;
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
*/
|
||||
private TradeReply() { /* empty */ }
|
||||
|
||||
/**
|
||||
* Constructs a TradeResponse with the specified response details.
|
||||
*
|
||||
|
@@ -1,15 +1,23 @@
|
||||
package pp.monopoly.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import pp.monopoly.model.TradeHandler;
|
||||
|
||||
/**
|
||||
* Represents a trade Request message from one player to another.
|
||||
*/
|
||||
@Serializable
|
||||
public class TradeRequest extends ServerMessage{
|
||||
private int receiverId;
|
||||
private TradeHandler tradehandler;
|
||||
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
*/
|
||||
private TradeRequest() { /* empty */ }
|
||||
|
||||
/**
|
||||
* Constructs a TradeRequest with the specified details.
|
||||
*
|
||||
|
@@ -2,18 +2,26 @@ package pp.monopoly.message.server;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import pp.monopoly.model.fields.BoardManager;
|
||||
import pp.monopoly.model.fields.PropertyField;
|
||||
|
||||
/**
|
||||
* Represents a response containing the player's assets.
|
||||
*/
|
||||
@Serializable
|
||||
public class ViewAssetsResponse extends ServerMessage{
|
||||
|
||||
private final List<PropertyField> properties;
|
||||
private final BoardManager board;
|
||||
private final int accountBalance;
|
||||
private final int jailCards;
|
||||
private List<PropertyField> properties;
|
||||
private BoardManager board;
|
||||
private int accountBalance;
|
||||
private int jailCards;
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
*/
|
||||
private ViewAssetsResponse() { /* empty */ }
|
||||
|
||||
/**
|
||||
* Constructs a ViewAssetsResponse with the specified properties and account balance.
|
||||
|
@@ -122,6 +122,13 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
|
||||
}
|
||||
|
||||
private void registerListeners() {
|
||||
myServer.addMessageListener(this, BuyPropertyRequest.class);
|
||||
myServer.addMessageListener(this, EndTurn.class);
|
||||
myServer.addMessageListener(this, PlayerReady.class);
|
||||
myServer.addMessageListener(this, RollDice.class);
|
||||
myServer.addMessageListener(this, TradeOffer.class);
|
||||
myServer.addMessageListener(this, TradeResponse.class);
|
||||
myServer.addMessageListener(this, ViewAssetsRequest.class);
|
||||
myServer.addConnectionListener(this);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user