Compare commits

...

3 Commits

Author SHA1 Message Date
Johannes Schmelz
1b2a7d73b5 extend dialog 2024-11-24 22:41:53 +01:00
Johannes Schmelz
55778dbcea removed the buttons on start 2024-11-24 22:29:19 +01:00
Johannes Schmelz
422faec281 send player ready 2024-11-24 22:06:19 +01:00
13 changed files with 100 additions and 40 deletions

View File

@ -302,7 +302,7 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
*
* @param isPressed Indicates whether the Escape key is pressed.
*/
private void escape(boolean isPressed) {
public void escape(boolean isPressed) {
if (!isPressed) return;
if (dialogManager.showsDialog())
dialogManager.escape();

View File

@ -26,13 +26,12 @@ import pp.monopoly.client.NetworkSupport;
import pp.monopoly.server.MonopolyServer;
import pp.dialog.Dialog;
import pp.dialog.DialogBuilder;
import pp.dialog.SimpleDialog;
/**
* Represents a dialog for setting up a network connection in the Battleship game.
* Allows users to specify the host and port for connecting to a game server.
*/
public class CreateGameMenu extends SimpleDialog {
public class CreateGameMenu extends Dialog {
private static final Logger LOGGER = System.getLogger(CreateGameMenu.class.getName());
private static final String LOCALHOST = "localhost"; //NON-NLS
private static final String DEFAULT_PORT = "42069"; //NON-NLS
@ -69,7 +68,7 @@ public class CreateGameMenu extends SimpleDialog {
addChild(input);
// "Abbrechen"-Button
cancelButton.setPreferredSize(new Vector3f(120, 40, 0));
cancelButton.addClickCommands(source -> new StartMenu(app).open());
cancelButton.addClickCommands(source -> close());
addChild(cancelButton);
cancelButton.addClickCommands(s -> new StartMenu(app));
@ -124,6 +123,11 @@ public class CreateGameMenu extends SimpleDialog {
}
}
@Override
public void escape() {
close();
}
/**
* This method is called by {@linkplain pp.dialog.DialogManager#update(float)} for periodically
* updating this dialog. T

View File

@ -40,14 +40,12 @@ public class LobbyMenu extends Dialog {
private TextField playerInputField = new TextField("Spieler 1");
private TextField startingCapital = new TextField("15000");
private String figure;
public LobbyMenu(MonopolyApp app) {
super(app.getDialogManager());
this.app = app;
// Entfernt das CreateGameMenu (inklusive Hintergrund)
app.getGuiNode().detachAllChildren();
// Hintergrundbild laden und hinzufügen
addBackgroundImage();
@ -207,11 +205,11 @@ public class LobbyMenu extends Dialog {
* Schaltet den "Bereit"-Status um.
*/
private void toggleReady(Label playersLabel) {
app.getGameLogic().send(new PlayerReady(true, "Test", "flugzeug", 15000));;
app.getGameLogic().send(new PlayerReady(true, playerInputField.getText(), figure, Integer.parseInt(startingCapital.getText())));
}
@Override
public void close() {
public void escape() {
super.close();
}
@ -258,19 +256,25 @@ public class LobbyMenu extends Dialog {
System.out.println("Selected: " + selected);
switch (selected) {
case "[0]":
System.out.println("Alpha selected");
figure = "Laptop";
break;
case "[1]":
System.out.println("Beta selected");
figure = "Flugzeug";
break;
case "[2]":
System.out.println("Gamma selected");
figure = "Jägermeister";
break;
case "[3]":
close();
figure = "Katze";
break;
case "[4]":
figure = "OOP";
break;
case "[5]":
figure = "Handyholster";
break;
default:
System.out.println("Unknown selection");
break;
}
}

View File

@ -63,27 +63,6 @@ public class StartMenu extends Dialog {
0));
app.getGuiNode().attachChild(centerMenu);
// 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(18);
quitButton.addClickCommands(source -> ifTopDialog(app::closeApp));
lowerLeftMenu.addChild(quitButton);
app.getGuiNode().attachChild(lowerLeftMenu);
// 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(18); // Increase the font size for the text
settingsButton.addClickCommands(source -> new SettingsMenu(app).open());
lowerRightMenu.addChild(settingsButton);
app.getGuiNode().attachChild(lowerRightMenu);
// Load the Monopoly logo as a texture
Texture logoTexture = app.getAssetManager().loadTexture("Pictures/logo-monopoly.png");

View File

@ -144,6 +144,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
LOGGER.log(Level.ERROR, "trying to send {0} with sender==null", msg); //NON-NLS
} else {
clientSender.send(msg);
System.out.println("Message gesendet");
}
}

View File

@ -1,11 +1,19 @@
package pp.monopoly.message.client;
import com.jme3.network.serializing.Serializable;
/**
* Represents a request from a player to buy a property.
*/
@Serializable
public class BuyPropertyRequest extends ClientMessage{
private int propertyId;
/**
* Default constructor for serialization purposes.
*/
private BuyPropertyRequest() { /* empty */ }
/**
* Constructs a BuyPropertyRequest with the specified property ID.
*

View File

@ -1,9 +1,18 @@
package pp.monopoly.message.client;
import com.jme3.network.serializing.Serializable;
/**
* Represents a message indicating the player wants to end their turn.
*/
@Serializable
public class EndTurn extends ClientMessage{
/**
* Default constructor for serialization purposes.
*/
public EndTurn() { /* empty */ }
@Override
public void accept(ClientInterpreter interpreter, int from) {
interpreter.received(this, from);

View File

@ -1,13 +1,21 @@
package pp.monopoly.message.client;
import com.jme3.network.serializing.Serializable;
/**
* Represents a message indicating the player is ready to play.
*/
@Serializable
public class PlayerReady extends ClientMessage {
private final boolean isReady;
private final String name;
private final String figure;
private final int startMoney;
private boolean isReady;
private String name;
private String figure;
private int startMoney;
/**
* Default constructor for serialization purposes.
*/
private PlayerReady() { /* empty */ }
/**
* Constructs a PlayerReady message.

View File

@ -1,9 +1,18 @@
package pp.monopoly.message.client;
import com.jme3.network.serializing.Serializable;
/**
* Represents a message requesting to roll the dice.
*/
@Serializable
public class RollDice extends ClientMessage{
/**
* Default constructor for serialization purposes.
*/
private RollDice() { /* empty */ }
@Override
public void accept(ClientInterpreter interpreter, int from) {
interpreter.received(this, from);

View File

@ -1,14 +1,21 @@
package pp.monopoly.message.client;
import com.jme3.network.serializing.Serializable;
import pp.monopoly.model.TradeHandler;
/**
* Represents a trade Request message from one player to another.
*/
@Serializable
public class TradeOffer extends ClientMessage{
private int receiverId;
private TradeHandler tradehandler;
/**
* Default constructor for serialization purposes.
*/
private TradeOffer() { /* empty */ }
/**
* Constructs a TradeOffer with the specified details.

View File

@ -1,14 +1,22 @@
package pp.monopoly.message.client;
import com.jme3.network.serializing.Serializable;
import pp.monopoly.model.TradeHandler;
/**
* Represents a response to a trade offer.
*/
@Serializable
public class TradeResponse extends ClientMessage{
private int initiatorId;
private TradeHandler tradeHandler;
/**
* Default constructor for serialization purposes.
*/
private TradeResponse() { /* empty */ }
/**
* Constructs a TradeResponse with the specified response details.
*

View File

@ -1,13 +1,21 @@
package pp.monopoly.message.client;
import com.jme3.network.serializing.Serializable;
import pp.monopoly.game.server.Player;
/**
* Represents a request from a player to view their assets.
*/
@Serializable
public class ViewAssetsRequest extends ClientMessage{
private final Player player;
private Player player;
/**
* Default constructor for serialization purposes.
*/
private ViewAssetsRequest() { /* empty */ }
public ViewAssetsRequest(Player player) {
this.player = player;

View File

@ -28,7 +28,14 @@ import pp.monopoly.MonopolyConfig;
import pp.monopoly.game.server.Player;
import pp.monopoly.game.server.ServerGameLogic;
import pp.monopoly.game.server.ServerSender;
import pp.monopoly.message.client.BuyPropertyRequest;
import pp.monopoly.message.client.ClientMessage;
import pp.monopoly.message.client.EndTurn;
import pp.monopoly.message.client.PlayerReady;
import pp.monopoly.message.client.RollDice;
import pp.monopoly.message.client.TradeOffer;
import pp.monopoly.message.client.TradeResponse;
import pp.monopoly.message.client.ViewAssetsRequest;
import pp.monopoly.message.server.ServerMessage;
import pp.monopoly.model.IntPoint;
@ -105,6 +112,13 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
private void initializeSerializables() {
Serializer.registerClass(IntPoint.class);
Serializer.registerClass(BuyPropertyRequest.class);
Serializer.registerClass(EndTurn.class);
Serializer.registerClass(PlayerReady.class);
Serializer.registerClass(RollDice.class);
Serializer.registerClass(TradeOffer.class);
Serializer.registerClass(TradeResponse.class);
Serializer.registerClass(ViewAssetsRequest.class);
}
private void registerListeners() {
@ -113,6 +127,7 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
@Override
public void messageReceived(HostedConnection source, Message message) {
System.out.println("Message recieved");
LOGGER.log(Level.INFO, "message received from {0}: {1}", source.getId(), message); //NON-NLS
if (message instanceof ClientMessage clientMessage)
pendingMessages.add(new ReceivedMessage(clientMessage, source.getId()));