mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2025-04-17 02:30:58 +02:00
Compare commits
3 Commits
dcf10e0819
...
1b2a7d73b5
Author | SHA1 | Date | |
---|---|---|---|
|
1b2a7d73b5 | ||
|
55778dbcea | ||
|
422faec281 |
@ -302,7 +302,7 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
|
|||||||
*
|
*
|
||||||
* @param isPressed Indicates whether the Escape key is pressed.
|
* @param isPressed Indicates whether the Escape key is pressed.
|
||||||
*/
|
*/
|
||||||
private void escape(boolean isPressed) {
|
public void escape(boolean isPressed) {
|
||||||
if (!isPressed) return;
|
if (!isPressed) return;
|
||||||
if (dialogManager.showsDialog())
|
if (dialogManager.showsDialog())
|
||||||
dialogManager.escape();
|
dialogManager.escape();
|
||||||
|
@ -26,13 +26,12 @@ import pp.monopoly.client.NetworkSupport;
|
|||||||
import pp.monopoly.server.MonopolyServer;
|
import pp.monopoly.server.MonopolyServer;
|
||||||
import pp.dialog.Dialog;
|
import pp.dialog.Dialog;
|
||||||
import pp.dialog.DialogBuilder;
|
import pp.dialog.DialogBuilder;
|
||||||
import pp.dialog.SimpleDialog;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a dialog for setting up a network connection in the Battleship game.
|
* 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.
|
* 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 Logger LOGGER = System.getLogger(CreateGameMenu.class.getName());
|
||||||
private static final String LOCALHOST = "localhost"; //NON-NLS
|
private static final String LOCALHOST = "localhost"; //NON-NLS
|
||||||
private static final String DEFAULT_PORT = "42069"; //NON-NLS
|
private static final String DEFAULT_PORT = "42069"; //NON-NLS
|
||||||
@ -69,7 +68,7 @@ public class CreateGameMenu extends SimpleDialog {
|
|||||||
addChild(input);
|
addChild(input);
|
||||||
// "Abbrechen"-Button
|
// "Abbrechen"-Button
|
||||||
cancelButton.setPreferredSize(new Vector3f(120, 40, 0));
|
cancelButton.setPreferredSize(new Vector3f(120, 40, 0));
|
||||||
cancelButton.addClickCommands(source -> new StartMenu(app).open());
|
cancelButton.addClickCommands(source -> close());
|
||||||
addChild(cancelButton);
|
addChild(cancelButton);
|
||||||
cancelButton.addClickCommands(s -> new StartMenu(app));
|
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
|
* This method is called by {@linkplain pp.dialog.DialogManager#update(float)} for periodically
|
||||||
* updating this dialog. T
|
* updating this dialog. T
|
||||||
|
@ -40,14 +40,12 @@ public class LobbyMenu extends Dialog {
|
|||||||
|
|
||||||
private TextField playerInputField = new TextField("Spieler 1");
|
private TextField playerInputField = new TextField("Spieler 1");
|
||||||
private TextField startingCapital = new TextField("15000");
|
private TextField startingCapital = new TextField("15000");
|
||||||
|
private String figure;
|
||||||
|
|
||||||
public LobbyMenu(MonopolyApp app) {
|
public LobbyMenu(MonopolyApp app) {
|
||||||
super(app.getDialogManager());
|
super(app.getDialogManager());
|
||||||
this.app = app;
|
this.app = app;
|
||||||
|
|
||||||
// Entfernt das CreateGameMenu (inklusive Hintergrund)
|
|
||||||
app.getGuiNode().detachAllChildren();
|
|
||||||
|
|
||||||
// Hintergrundbild laden und hinzufügen
|
// Hintergrundbild laden und hinzufügen
|
||||||
addBackgroundImage();
|
addBackgroundImage();
|
||||||
|
|
||||||
@ -207,11 +205,11 @@ public class LobbyMenu extends Dialog {
|
|||||||
* Schaltet den "Bereit"-Status um.
|
* Schaltet den "Bereit"-Status um.
|
||||||
*/
|
*/
|
||||||
private void toggleReady(Label playersLabel) {
|
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
|
@Override
|
||||||
public void close() {
|
public void escape() {
|
||||||
super.close();
|
super.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,19 +256,25 @@ public class LobbyMenu extends Dialog {
|
|||||||
System.out.println("Selected: " + selected);
|
System.out.println("Selected: " + selected);
|
||||||
switch (selected) {
|
switch (selected) {
|
||||||
case "[0]":
|
case "[0]":
|
||||||
System.out.println("Alpha selected");
|
figure = "Laptop";
|
||||||
break;
|
break;
|
||||||
case "[1]":
|
case "[1]":
|
||||||
System.out.println("Beta selected");
|
figure = "Flugzeug";
|
||||||
break;
|
break;
|
||||||
case "[2]":
|
case "[2]":
|
||||||
System.out.println("Gamma selected");
|
figure = "Jägermeister";
|
||||||
break;
|
break;
|
||||||
case "[3]":
|
case "[3]":
|
||||||
close();
|
figure = "Katze";
|
||||||
|
break;
|
||||||
|
case "[4]":
|
||||||
|
figure = "OOP";
|
||||||
|
break;
|
||||||
|
case "[5]":
|
||||||
|
figure = "Handyholster";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
System.out.println("Unknown selection");
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,27 +63,6 @@ public class StartMenu extends Dialog {
|
|||||||
0));
|
0));
|
||||||
app.getGuiNode().attachChild(centerMenu);
|
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
|
// Load the Monopoly logo as a texture
|
||||||
Texture logoTexture = app.getAssetManager().loadTexture("Pictures/logo-monopoly.png");
|
Texture logoTexture = app.getAssetManager().loadTexture("Pictures/logo-monopoly.png");
|
||||||
|
|
||||||
|
@ -144,6 +144,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
|||||||
LOGGER.log(Level.ERROR, "trying to send {0} with sender==null", msg); //NON-NLS
|
LOGGER.log(Level.ERROR, "trying to send {0} with sender==null", msg); //NON-NLS
|
||||||
} else {
|
} else {
|
||||||
clientSender.send(msg);
|
clientSender.send(msg);
|
||||||
|
System.out.println("Message gesendet");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,19 @@
|
|||||||
package pp.monopoly.message.client;
|
package pp.monopoly.message.client;
|
||||||
|
|
||||||
|
import com.jme3.network.serializing.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a request from a player to buy a property.
|
* Represents a request from a player to buy a property.
|
||||||
*/
|
*/
|
||||||
|
@Serializable
|
||||||
public class BuyPropertyRequest extends ClientMessage{
|
public class BuyPropertyRequest extends ClientMessage{
|
||||||
private int propertyId;
|
private int propertyId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor for serialization purposes.
|
||||||
|
*/
|
||||||
|
private BuyPropertyRequest() { /* empty */ }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a BuyPropertyRequest with the specified property ID.
|
* Constructs a BuyPropertyRequest with the specified property ID.
|
||||||
*
|
*
|
||||||
|
@ -1,9 +1,18 @@
|
|||||||
package pp.monopoly.message.client;
|
package pp.monopoly.message.client;
|
||||||
|
|
||||||
|
import com.jme3.network.serializing.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a message indicating the player wants to end their turn.
|
* Represents a message indicating the player wants to end their turn.
|
||||||
*/
|
*/
|
||||||
|
@Serializable
|
||||||
public class EndTurn extends ClientMessage{
|
public class EndTurn extends ClientMessage{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor for serialization purposes.
|
||||||
|
*/
|
||||||
|
public EndTurn() { /* empty */ }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void accept(ClientInterpreter interpreter, int from) {
|
public void accept(ClientInterpreter interpreter, int from) {
|
||||||
interpreter.received(this, from);
|
interpreter.received(this, from);
|
||||||
|
@ -1,13 +1,21 @@
|
|||||||
package pp.monopoly.message.client;
|
package pp.monopoly.message.client;
|
||||||
|
|
||||||
|
import com.jme3.network.serializing.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a message indicating the player is ready to play.
|
* Represents a message indicating the player is ready to play.
|
||||||
*/
|
*/
|
||||||
|
@Serializable
|
||||||
public class PlayerReady extends ClientMessage {
|
public class PlayerReady extends ClientMessage {
|
||||||
private final boolean isReady;
|
private boolean isReady;
|
||||||
private final String name;
|
private String name;
|
||||||
private final String figure;
|
private String figure;
|
||||||
private final int startMoney;
|
private int startMoney;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor for serialization purposes.
|
||||||
|
*/
|
||||||
|
private PlayerReady() { /* empty */ }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a PlayerReady message.
|
* Constructs a PlayerReady message.
|
||||||
|
@ -1,9 +1,18 @@
|
|||||||
package pp.monopoly.message.client;
|
package pp.monopoly.message.client;
|
||||||
|
|
||||||
|
import com.jme3.network.serializing.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a message requesting to roll the dice.
|
* Represents a message requesting to roll the dice.
|
||||||
*/
|
*/
|
||||||
|
@Serializable
|
||||||
public class RollDice extends ClientMessage{
|
public class RollDice extends ClientMessage{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor for serialization purposes.
|
||||||
|
*/
|
||||||
|
private RollDice() { /* empty */ }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void accept(ClientInterpreter interpreter, int from) {
|
public void accept(ClientInterpreter interpreter, int from) {
|
||||||
interpreter.received(this, from);
|
interpreter.received(this, from);
|
||||||
|
@ -1,14 +1,21 @@
|
|||||||
package pp.monopoly.message.client;
|
package pp.monopoly.message.client;
|
||||||
|
|
||||||
|
import com.jme3.network.serializing.Serializable;
|
||||||
|
|
||||||
import pp.monopoly.model.TradeHandler;
|
import pp.monopoly.model.TradeHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a trade Request message from one player to another.
|
* Represents a trade Request message from one player to another.
|
||||||
*/
|
*/
|
||||||
|
@Serializable
|
||||||
public class TradeOffer extends ClientMessage{
|
public class TradeOffer extends ClientMessage{
|
||||||
private int receiverId;
|
private int receiverId;
|
||||||
private TradeHandler tradehandler;
|
private TradeHandler tradehandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor for serialization purposes.
|
||||||
|
*/
|
||||||
|
private TradeOffer() { /* empty */ }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a TradeOffer with the specified details.
|
* Constructs a TradeOffer with the specified details.
|
||||||
|
@ -1,14 +1,22 @@
|
|||||||
package pp.monopoly.message.client;
|
package pp.monopoly.message.client;
|
||||||
|
|
||||||
|
import com.jme3.network.serializing.Serializable;
|
||||||
|
|
||||||
import pp.monopoly.model.TradeHandler;
|
import pp.monopoly.model.TradeHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a response to a trade offer.
|
* Represents a response to a trade offer.
|
||||||
*/
|
*/
|
||||||
|
@Serializable
|
||||||
public class TradeResponse extends ClientMessage{
|
public class TradeResponse extends ClientMessage{
|
||||||
private int initiatorId;
|
private int initiatorId;
|
||||||
private TradeHandler tradeHandler;
|
private TradeHandler tradeHandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor for serialization purposes.
|
||||||
|
*/
|
||||||
|
private TradeResponse() { /* empty */ }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a TradeResponse with the specified response details.
|
* Constructs a TradeResponse with the specified response details.
|
||||||
*
|
*
|
||||||
|
@ -1,13 +1,21 @@
|
|||||||
package pp.monopoly.message.client;
|
package pp.monopoly.message.client;
|
||||||
|
|
||||||
|
import com.jme3.network.serializing.Serializable;
|
||||||
|
|
||||||
import pp.monopoly.game.server.Player;
|
import pp.monopoly.game.server.Player;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a request from a player to view their assets.
|
* Represents a request from a player to view their assets.
|
||||||
*/
|
*/
|
||||||
|
@Serializable
|
||||||
public class ViewAssetsRequest extends ClientMessage{
|
public class ViewAssetsRequest extends ClientMessage{
|
||||||
|
|
||||||
private final Player player;
|
private Player player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor for serialization purposes.
|
||||||
|
*/
|
||||||
|
private ViewAssetsRequest() { /* empty */ }
|
||||||
|
|
||||||
public ViewAssetsRequest(Player player) {
|
public ViewAssetsRequest(Player player) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
|
@ -28,7 +28,14 @@ import pp.monopoly.MonopolyConfig;
|
|||||||
import pp.monopoly.game.server.Player;
|
import pp.monopoly.game.server.Player;
|
||||||
import pp.monopoly.game.server.ServerGameLogic;
|
import pp.monopoly.game.server.ServerGameLogic;
|
||||||
import pp.monopoly.game.server.ServerSender;
|
import pp.monopoly.game.server.ServerSender;
|
||||||
|
import pp.monopoly.message.client.BuyPropertyRequest;
|
||||||
import pp.monopoly.message.client.ClientMessage;
|
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.message.server.ServerMessage;
|
||||||
import pp.monopoly.model.IntPoint;
|
import pp.monopoly.model.IntPoint;
|
||||||
|
|
||||||
@ -105,6 +112,13 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
|
|||||||
|
|
||||||
private void initializeSerializables() {
|
private void initializeSerializables() {
|
||||||
Serializer.registerClass(IntPoint.class);
|
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() {
|
private void registerListeners() {
|
||||||
@ -113,6 +127,7 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void messageReceived(HostedConnection source, Message message) {
|
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
|
LOGGER.log(Level.INFO, "message received from {0}: {1}", source.getId(), message); //NON-NLS
|
||||||
if (message instanceof ClientMessage clientMessage)
|
if (message instanceof ClientMessage clientMessage)
|
||||||
pendingMessages.add(new ReceivedMessage(clientMessage, source.getId()));
|
pendingMessages.add(new ReceivedMessage(clientMessage, source.getId()));
|
||||||
|
Loading…
Reference in New Issue
Block a user