mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2024-11-25 02:19:45 +01:00
Compare commits
No commits in common. "bb9727d54a7151c0171512d5f268c301b4e419db" and "b6968df45143f06152afd26e8acc93456995a7c1" have entirely different histories.
bb9727d54a
...
b6968df451
@ -20,13 +20,15 @@ import pp.monopoly.client.MonopolyApp;
|
||||
import pp.monopoly.client.StartMenu;
|
||||
import pp.monopoly.server.MonopolyServer;
|
||||
|
||||
/**
|
||||
* CreateGameMenu class represents the menu for creating a new game.
|
||||
*/
|
||||
public class CreateGameMenu {
|
||||
|
||||
private final MonopolyApp app;
|
||||
private final Container menuContainer;
|
||||
private Geometry background;
|
||||
private TextField serverAddressField;
|
||||
private TextField portField;
|
||||
private Label serverStatusLabel;
|
||||
|
||||
public CreateGameMenu(MonopolyApp app) {
|
||||
this.app = app;
|
||||
@ -48,12 +50,12 @@ public class CreateGameMenu {
|
||||
inputContainer.setLocalTranslation(20, 0, 0); // Abstand vom Rand
|
||||
|
||||
inputContainer.addChild(new Label("Server-Adresse:"));
|
||||
serverAddressField = inputContainer.addChild(new TextField("localhost"));
|
||||
serverAddressField.setPreferredWidth(400); // Breite des Textfelds
|
||||
TextField playerNameField = inputContainer.addChild(new TextField("localhost"));
|
||||
playerNameField.setPreferredWidth(400); // Breite des Textfelds
|
||||
|
||||
inputContainer.addChild(new Label("Port:"));
|
||||
portField = inputContainer.addChild(new TextField("42069"));
|
||||
portField.setPreferredWidth(400); // Breite des Textfelds
|
||||
TextField serverAddressField = inputContainer.addChild(new TextField("42069"));
|
||||
serverAddressField.setPreferredWidth(400); // Breite des Textfelds
|
||||
|
||||
// Button-Container
|
||||
Container buttonContainer = menuContainer.addChild(new Container(new SpringGridLayout(Axis.X, Axis.Y)));
|
||||
@ -68,15 +70,14 @@ public class CreateGameMenu {
|
||||
// "Selber hosten"-Button
|
||||
Button hostButton = buttonContainer.addChild(new Button("Selber hosten"));
|
||||
hostButton.setPreferredSize(new Vector3f(120, 40, 0));
|
||||
hostButton.addClickCommands(source -> startServerAndJoin());
|
||||
hostButton.addClickCommands(source -> startServer());
|
||||
|
||||
// "Beitreten"-Button (vorerst funktionslos)
|
||||
Button joinButton = buttonContainer.addChild(new Button("Beitreten"));
|
||||
joinButton.setPreferredSize(new Vector3f(120, 40, 0));
|
||||
joinButton.addClickCommands(source -> joinServer());
|
||||
|
||||
// Serverstatus-Label
|
||||
Label serverStatusLabel = menuContainer.addChild(new Label("Serverstatus: Noch nicht gestartet"));
|
||||
serverStatusLabel = menuContainer.addChild(new Label("Serverstatus: Noch nicht gestartet"));
|
||||
serverStatusLabel.setFontSize(24);
|
||||
|
||||
// Zentrierung des Containers
|
||||
@ -85,6 +86,7 @@ public class CreateGameMenu {
|
||||
(app.getCamera().getHeight() + menuContainer.getPreferredSize().y) / 2,
|
||||
1 // Höhere Z-Ebene für den Vordergrund
|
||||
);
|
||||
|
||||
app.getInputManager().addMapping("OpenTestWorld", new com.jme3.input.controls.KeyTrigger(com.jme3.input.KeyInput.KEY_T));
|
||||
app.getInputManager().addListener(new com.jme3.input.controls.ActionListener() {
|
||||
@Override
|
||||
@ -122,38 +124,9 @@ public class CreateGameMenu {
|
||||
StartMenu.createStartMenu(app);
|
||||
}
|
||||
|
||||
/**
|
||||
* Startet den Server und tritt nach 2 Sekunden der Lobby bei.
|
||||
*/
|
||||
private void startServerAndJoin() {
|
||||
new Thread(() -> {
|
||||
app.start();
|
||||
MonopolyServer server = new MonopolyServer();
|
||||
server.run();
|
||||
|
||||
// Warte 2 Sekunden
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
|
||||
// Verbinde mit dem Server
|
||||
app.enqueue(() -> joinServer());
|
||||
}).start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tritt dem Server basierend auf den Eingaben bei.
|
||||
*/
|
||||
private void joinServer() {
|
||||
String serverAddress = serverAddressField.getText();
|
||||
int port = Integer.parseInt(portField.getText());
|
||||
app.getServerConnection().connect(serverAddress, port);
|
||||
|
||||
// Öffnet die Lobby
|
||||
app.getGuiNode().detachChild(menuContainer);
|
||||
app.getGuiNode().detachChild(background); // Entfernt das Hintergrundbild
|
||||
new LobbyMenu(app);
|
||||
private void startServer() {
|
||||
app.start();
|
||||
app.getServerConnection().connect();
|
||||
JOptionPane.showMessageDialog(null, "Server Started");
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,51 @@
|
||||
package pp.monopoly.client.gui;
|
||||
|
||||
|
||||
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;
|
||||
|
||||
public class GameMenu extends Dialog {
|
||||
private final MonopolyApp app;
|
||||
|
||||
/**
|
||||
* Constructs the SettingsMenu dialog for the Monopoly application.
|
||||
*
|
||||
* @param app the MonopolyApp instance
|
||||
*/
|
||||
public GameMenu(MonopolyApp app) {
|
||||
super(app.getDialogManager());
|
||||
this.app = app;
|
||||
|
||||
// Add a title label for Settings
|
||||
Label settingsTitle = new Label("Einstellungen", new ElementId("settings-title"));
|
||||
settingsTitle.setFontSize(48); // Set font size for the title
|
||||
settingsTitle.setColor(ColorRGBA.White);
|
||||
|
||||
// Add any settings-related components here, such as volume control, toggles, etc.
|
||||
|
||||
// Add a back button to return to StartMenu
|
||||
Button backButton = new Button("Zurück", new ElementId("menu-button"));
|
||||
backButton.setColor(ColorRGBA.White);
|
||||
backButton.setFontSize(24);
|
||||
backButton.addClickCommands(source -> returnToStartMenu());
|
||||
|
||||
// Add components to this dialog
|
||||
addChild(settingsTitle);
|
||||
addChild(backButton);
|
||||
|
||||
// You can add more settings components here, like checkboxes or sliders.
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns to the StartMenu when the back button is clicked.
|
||||
*/
|
||||
private void returnToStartMenu() {
|
||||
app.getDialogManager().close(this); // Close the current settings dialog
|
||||
//TODO return zum Ausgangsmenü
|
||||
}
|
||||
}
|
@ -1,99 +0,0 @@
|
||||
package pp.monopoly.client.gui;
|
||||
|
||||
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.Axis;
|
||||
import com.simsilica.lemur.Button;
|
||||
import com.simsilica.lemur.Container;
|
||||
import com.simsilica.lemur.Label;
|
||||
import com.simsilica.lemur.component.SpringGridLayout;
|
||||
|
||||
import pp.monopoly.client.MonopolyApp;
|
||||
|
||||
public class LobbyMenu {
|
||||
|
||||
private final MonopolyApp app;
|
||||
private final Container menuContainer;
|
||||
private Geometry background;
|
||||
|
||||
public LobbyMenu(MonopolyApp app) {
|
||||
this.app = app;
|
||||
|
||||
// Entfernt das CreateGameMenu (inklusive Hintergrund)
|
||||
app.getGuiNode().detachAllChildren();
|
||||
|
||||
// Hintergrundbild laden und hinzufügen
|
||||
addBackgroundImage();
|
||||
|
||||
// Hauptcontainer für das Menü
|
||||
menuContainer = new Container(new SpringGridLayout(Axis.Y, Axis.X));
|
||||
menuContainer.setPreferredSize(new Vector3f(600, 400, 0)); // Feste Größe des Containers
|
||||
|
||||
// Titel
|
||||
Label title = menuContainer.addChild(new Label("Lobby"));
|
||||
title.setFontSize(48);
|
||||
|
||||
// Spielerstatus anzeigen
|
||||
Container playerListContainer = menuContainer.addChild(new Container(new SpringGridLayout(Axis.Y, Axis.X)));
|
||||
playerListContainer.addChild(new Label("Spieler in der Lobby:"));
|
||||
Label playersLabel = playerListContainer.addChild(new Label("Noch keine Spieler verbunden.")); // Beispieltext
|
||||
|
||||
// Buttons
|
||||
Container buttonContainer = menuContainer.addChild(new Container(new SpringGridLayout(Axis.X, Axis.Y)));
|
||||
buttonContainer.setPreferredSize(new Vector3f(400, 50, 0));
|
||||
|
||||
// "Bereit"-Button
|
||||
Button readyButton = buttonContainer.addChild(new Button("Bereit"));
|
||||
readyButton.setPreferredSize(new Vector3f(120, 40, 0));
|
||||
readyButton.addClickCommands(source -> toggleReady(playersLabel));
|
||||
|
||||
// "Zurück"-Button
|
||||
Button backButton = buttonContainer.addChild(new Button("Zurück"));
|
||||
backButton.setPreferredSize(new Vector3f(120, 40, 0));
|
||||
backButton.addClickCommands(source -> goBackToCreateGame());
|
||||
|
||||
// Zentrierung des Containers
|
||||
menuContainer.setLocalTranslation(
|
||||
(app.getCamera().getWidth() - menuContainer.getPreferredSize().x) / 2,
|
||||
(app.getCamera().getHeight() + menuContainer.getPreferredSize().y) / 2,
|
||||
1 // Höhere Z-Ebene für den Vordergrund
|
||||
);
|
||||
|
||||
app.getGuiNode().attachChild(menuContainer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lädt das Hintergrundbild und fügt es als geometrische Ebene hinzu.
|
||||
*/
|
||||
private void addBackgroundImage() {
|
||||
Texture backgroundImage = app.getAssetManager().loadTexture("Pictures/unibw-Bib2.png");
|
||||
Quad quad = new Quad(app.getCamera().getWidth(), app.getCamera().getHeight());
|
||||
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); // Hintergrundebene
|
||||
|
||||
app.getGuiNode().attachChild(background);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schaltet den "Bereit"-Status um.
|
||||
*/
|
||||
private void toggleReady(Label playersLabel) {
|
||||
// Beispiel-Logik für das Umschalten des Status
|
||||
playersLabel.setText("Spielerstatus aktualisiert."); // Beispieltext
|
||||
}
|
||||
|
||||
/**
|
||||
* Geht zurück zum CreateGameMenu.
|
||||
*/
|
||||
private void goBackToCreateGame() {
|
||||
app.getGuiNode().detachChild(menuContainer);
|
||||
app.getGuiNode().detachChild(background); // Entfernt das Hintergrundbild
|
||||
new CreateGameMenu(app);
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
package pp.monopoly.client.gui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
public class ServerScreen {
|
||||
private JFrame frame;
|
||||
private JTextField inputField;
|
||||
private JLabel label;
|
||||
private JButton startButton;
|
||||
private JButton stopButton;
|
||||
|
||||
public ServerScreen() {
|
||||
initialize();
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
// Erstelle das Hauptfenster
|
||||
frame = new JFrame("Server Placeholder"); // Setze den Titel
|
||||
frame.setSize(400, 200);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setLayout(new BorderLayout());
|
||||
|
||||
// Eingabefeld und Label im oberen Bereich
|
||||
JPanel topPanel = new JPanel();
|
||||
topPanel.setLayout(new FlowLayout());
|
||||
|
||||
label = new JLabel("Server-Port:");
|
||||
inputField = new JTextField("42069", 10);
|
||||
topPanel.add(label);
|
||||
topPanel.add(inputField);
|
||||
|
||||
// Buttons im unteren Bereich
|
||||
JPanel bottomPanel = new JPanel();
|
||||
bottomPanel.setLayout(new FlowLayout());
|
||||
|
||||
startButton = new JButton("Start Server");
|
||||
stopButton = new JButton("Stop Server");
|
||||
stopButton.setEnabled(false); // Stop-Button ist anfangs deaktiviert
|
||||
|
||||
bottomPanel.add(startButton);
|
||||
bottomPanel.add(stopButton);
|
||||
|
||||
// Füge die Panels zum Hauptfenster hinzu
|
||||
frame.add(topPanel, BorderLayout.NORTH);
|
||||
frame.add(bottomPanel, BorderLayout.SOUTH);
|
||||
|
||||
// Aktion für Start-Button
|
||||
startButton.addActionListener(e -> startServer());
|
||||
|
||||
// Aktion für Stop-Button
|
||||
stopButton.addActionListener(e -> stopServer());
|
||||
|
||||
// Zeige das Fenster
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
private void startServer() {
|
||||
String port = inputField.getText();
|
||||
try {
|
||||
int portNumber = Integer.parseInt(port);
|
||||
// Server-Startlogik hier einfügen
|
||||
JOptionPane.showMessageDialog(frame, "Server gestartet auf Port " + portNumber);
|
||||
startButton.setEnabled(false); // Deaktiviere den Start-Button
|
||||
stopButton.setEnabled(true); // Aktiviere den Stop-Button
|
||||
} catch (NumberFormatException e) {
|
||||
JOptionPane.showMessageDialog(frame, "Ungültiger Port: " + port, "Fehler", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
private void stopServer() {
|
||||
// Server-Stoplogik hier einfügen
|
||||
JOptionPane.showMessageDialog(frame, "Server gestoppt.");
|
||||
startButton.setEnabled(true); // Aktiviere den Start-Button
|
||||
stopButton.setEnabled(false); // Deaktiviere den Stop-Button
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SwingUtilities.invokeLater(ServerScreen::new);
|
||||
}
|
||||
}
|
@ -1,38 +1,50 @@
|
||||
package pp.monopoly.message.client;
|
||||
|
||||
import pp.monopoly.game.server.PlayerColor;
|
||||
|
||||
/**
|
||||
* Represents a message indicating the player is ready to play.
|
||||
*/
|
||||
public class PlayerReady extends ClientMessage {
|
||||
public class PlayerReady extends ClientMessage{
|
||||
private boolean isReady;
|
||||
private String name;
|
||||
private String figure;
|
||||
private PlayerColor color;
|
||||
|
||||
/**
|
||||
* Constructs a PlayerReady message.
|
||||
*
|
||||
* @param isReady true if the player is ready, false otherwise
|
||||
* @param name the name of the player
|
||||
* @param color the color of the player (can be null)
|
||||
*/
|
||||
public PlayerReady(boolean isReady, String name, String figure) {
|
||||
public PlayerReady(boolean isReady) {
|
||||
this.isReady = isReady;
|
||||
this.name = name;
|
||||
this.figure = figure;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the Name
|
||||
* @return the Name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getFigure() {
|
||||
return figure;
|
||||
/**
|
||||
* Getter for the Playercolor
|
||||
* @return the Playercolor
|
||||
*/
|
||||
public PlayerColor getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the player is ready.
|
||||
*
|
||||
* @return true if ready, false otherwise
|
||||
*/
|
||||
public boolean isReady() {
|
||||
return isReady;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void accept(ClientInterpreter interpreter, int from) {
|
||||
interpreter.received(this, from);
|
||||
|
Loading…
Reference in New Issue
Block a user