This commit is contained in:
Johannes Schmelz 2024-12-06 16:21:12 +01:00
parent b50b5e64d1
commit aca92cd7f1
31 changed files with 21 additions and 361 deletions

View File

@ -8,14 +8,13 @@
package pp.monopoly.client;
import java.lang.System.Logger;
import java.util.List;
import java.lang.System.Logger.Level;
import com.jme3.input.controls.ActionListener;
import com.jme3.scene.Node;
import com.jme3.system.AppSettings;
import pp.monopoly.client.gui.TestWorld;
import pp.monopoly.game.server.Player;
/**
* Represents the state responsible for managing the battle interface within the Battleship game.
@ -24,8 +23,6 @@ import pp.monopoly.game.server.Player;
*/
public class GameAppState extends MonopolyAppState {
private static final Logger LOGGER = System.getLogger(MonopolyAppState.class.getName());
private static final float DEPTH = 0f;
private static final float GAP = 20f;
/**
* A listener for handling click events in the battle interface.
@ -49,9 +46,9 @@ public class GameAppState extends MonopolyAppState {
*/
@Override
protected void enableState() {
LOGGER.log(Level.DEBUG, "Enabling game state");
battleNode.detachAllChildren();
initializeGuiComponents();
layoutGuiComponents();
addGuiComponents();
getApp().getGuiNode().attachChild(battleNode);
}
@ -85,16 +82,6 @@ public class GameAppState extends MonopolyAppState {
private void addGuiComponents() {
}
/**
* Lays out the GUI components within the window, positioning them appropriately.
* The opponent's map view is positioned based on the window's dimensions and a specified gap.
*/
private void layoutGuiComponents() {
final AppSettings s = getApp().getContext().getSettings();
final float windowWidth = s.getWidth();
final float windowHeight = s.getHeight();
}
/**
* Handles click events in the battle interface. If the event indicates a click (not a release),
* it translates the cursor position to the model's coordinate system and triggers the game logic
@ -107,7 +94,6 @@ public class GameAppState extends MonopolyAppState {
@Override
public void update(float tpf) {
// testWorld.update(tpf);
super.update(tpf);
}
}

View File

@ -37,7 +37,6 @@ class GameBoardSynchronizer extends BoardSynchronizer {
private static final String FIGURE = "figure"; //NON-NLS
private final MonopolyApp app;
private final ParticleEffectFactory particleFactory;
/**
* Constructs a {@code GameBoardSynchronizer} object with the specified application, root node, and ship map.
@ -49,7 +48,6 @@ class GameBoardSynchronizer extends BoardSynchronizer {
public GameBoardSynchronizer(MonopolyApp app, Node root, Board board) {
super(board, root);
this.app = app;
this.particleFactory = new ParticleEffectFactory(app);
addExisting();
}

View File

@ -1,22 +0,0 @@
package pp.monopoly.client.gui;
import com.jme3.effect.ParticleMesh.Type;
import pp.monopoly.client.MonopolyApp;
/**
* Factory class responsible for creating particle effects used in the game.
* This centralizes the creation of various types of particle emitters.
*/
public class ParticleEffectFactory {
private static final int COUNT_FACTOR = 1;
private static final float COUNT_FACTOR_F = 1f;
private static final boolean POINT_SPRITE = true;
private static final Type EMITTER_TYPE = POINT_SPRITE ? Type.Point : Type.Triangle;
private final MonopolyApp app;
ParticleEffectFactory(MonopolyApp app) {
this.app = app;
}
}

View File

@ -19,7 +19,6 @@ import pp.monopoly.model.fields.GateField;
import pp.monopoly.model.fields.PropertyField;
import pp.monopoly.notification.Sound;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

View File

@ -96,16 +96,12 @@ public class Toolbar extends Dialog implements GameEventListener {
*/
private Button endTurnButton;
/**
* Flag indicating if dice animation is ongoing.
*/
private volatile boolean animatingDice = false;
/**
* Stores the most recent dice roll event.
*/
private volatile DiceRollEvent latestDiceRollEvent = null;
private DiceRollEvent latestDiceRollEvent = null;
/**Indicates if the bankrupt PopUp has already been shown */
private boolean bankruptPopUp = false;
/**
@ -305,18 +301,12 @@ public class Toolbar extends Dialog implements GameEventListener {
return endTurnButton;
}
private QuadBackgroundComponent createBackground() {
return new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f));
}
private void startDiceAnimation() {
animatingDice = true;
long startTime = System.currentTimeMillis();
new Thread(() -> {
try {
animateDice(startTime);
animatingDice = false;
if (latestDiceRollEvent != null) {
showFinalDiceResult(latestDiceRollEvent);
}

View File

@ -1,168 +0,0 @@
package pp.monopoly.client.gui;
import java.util.Random;
import com.jme3.font.BitmapText;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.simsilica.lemur.Axis;
import com.simsilica.lemur.Button;
import com.simsilica.lemur.Container;
import com.simsilica.lemur.component.SpringGridLayout;
import pp.monopoly.client.MonopolyApp;
/**
* Toolbar Klasse, die am unteren Rand der Szene angezeigt wird.
* Die Buttons bewegen den Würfel auf dem Spielfeld.
*/
public class Toolbar2 {
private final MonopolyApp app;
private final Container toolbarContainer;
private final Geometry cube; // Referenz auf den Würfel
private final BitmapText positionText; // Anzeige für die aktuelle Position
private final float boardLimit = 0.95f; // Grenzen des Bretts
private final float stepSize = 0.18f; // Schrittgröße pro Bewegung
private int currentPosition = 0; // Aktuelle Position auf dem Spielfeld
private final int positionsPerSide = 10; // Anzahl der Positionen pro Seite
private final Random random = new Random(); // Zufallsgenerator für den Würfelwurf
/**
* Konstruktor für die Toolbar.
*
* @param app Die Hauptanwendung (MonopolyApp)
* @param cube Der Würfel, der bewegt werden soll
*/
public Toolbar2(MonopolyApp app, Geometry cube) {
this.app = app;
this.cube = cube;
// Erstelle die Toolbar
toolbarContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y));
// Setze die Position am unteren Rand und die Breite
toolbarContainer.setLocalTranslation(
0, // Links bündig
100, // Höhe über dem unteren Rand
0 // Z-Ebene
);
toolbarContainer.setPreferredSize(new Vector3f(app.getCamera().getWidth(), 100, 0)); // Volle Breite
// Füge Buttons zur Toolbar hinzu
initializeButtons();
// Füge die Toolbar zur GUI hinzu
app.getGuiNode().attachChild(toolbarContainer);
// Erstelle die Position-Anzeige
positionText = createPositionDisplay();
updatePositionDisplay(); // Initialisiere die Anzeige mit der Startposition
}
/**
* Initialisiert die Buttons in der Toolbar.
*/
private void initializeButtons() {
addButton("Vorwärts", 1); // Bewegung nach vorne
addButton("Rückwärts", -1); // Bewegung nach hinten
addDiceRollButton(); // Würfel-Button
}
/**
* Fügt einen Button mit einer Bewegung hinzu.
*
* @param label Der Text des Buttons
* @param step Schrittweite (+1 für vorwärts, -1 für rückwärts)
*/
private void addButton(String label, int step) {
Button button = new Button(label);
button.setPreferredSize(new Vector3f(150, 50, 0)); // Größe der Buttons
button.addClickCommands(source -> moveCube(step));
toolbarContainer.addChild(button);
}
/**
* Fügt den Würfel-Button hinzu, der die Figur entsprechend der gewürfelten Zahl bewegt.
*/
private void addDiceRollButton() {
Button diceButton = new Button("Würfeln");
diceButton.setPreferredSize(new Vector3f(150, 50, 0)); // Größe des Buttons
diceButton.addClickCommands(source -> rollDice());
toolbarContainer.addChild(diceButton);
}
/**
* Simuliert einen Würfelwurf und bewegt die Figur entsprechend.
*/
private void rollDice() {
int diceRoll = random.nextInt(6) + 1; // Zahl zwischen 1 und 6
System.out.println("Gewürfelt: " + diceRoll);
moveCube(diceRoll); // Bewege die Figur um die gewürfelte Zahl
}
/**
* Bewegt den Würfel basierend auf der aktuellen Position auf dem Brett.
*
* @param step Schrittweite (+1 für vorwärts, -1 für rückwärts oder andere Werte)
*/
private void moveCube(int step) {
currentPosition = (currentPosition + step + 4 * positionsPerSide) % (4 * positionsPerSide);
Vector3f newPosition = calculatePosition(currentPosition);
cube.setLocalTranslation(newPosition);
updatePositionDisplay(); // Aktualisiere die Positionsanzeige
System.out.println("Würfelposition: " + newPosition + " (Feld-ID: " + currentPosition + ")");
}
/**
* Berechnet die neue Position des Würfels basierend auf der aktuellen Brettseite und Position.
*
* @param position Aktuelle Position auf dem Spielfeld
* @return Die berechnete Position als Vector3f
*/
private Vector3f calculatePosition(int position) {
int side = position / positionsPerSide; // Seite des Bretts (0 = unten, 1 = rechts, 2 = oben, 3 = links)
int offset = position % positionsPerSide; // Position auf der aktuellen Seite
switch (side) {
case 0: // Unten (positive x-Achse)
return new Vector3f(-boardLimit + offset * stepSize, 0.1f, -boardLimit + 0.05f);
case 1: // Rechts (positive z-Achse)
return new Vector3f(boardLimit - 0.05f, 0.1f, -boardLimit + offset * stepSize);
case 2: // Oben (negative x-Achse)
return new Vector3f(boardLimit - offset * stepSize, 0.1f, boardLimit - 0.05f);
case 3: // Links (negative z-Achse)
return new Vector3f(-boardLimit + 0.05f, 0.1f, boardLimit - offset * stepSize);
default:
throw new IllegalArgumentException("Ungültige Position: " + position);
}
}
/**
* Erstellt die Anzeige für die aktuelle Position.
*
* @return Das BitmapText-Objekt für die Anzeige
*/
private BitmapText createPositionDisplay() {
BitmapText text = new BitmapText(app.getAssetManager().loadFont("Interface/Fonts/Default.fnt"), false);
text.setSize(20); // Schriftgröße
text.setLocalTranslation(10, app.getCamera().getHeight() - 10, 0); // Oben links
app.getGuiNode().attachChild(text);
return text;
}
/**
* Aktualisiert die Anzeige für die aktuelle Position.
*/
private void updatePositionDisplay() {
positionText.setText("Feld-ID: " + currentPosition);
}
/**
* Entfernt die Toolbar.
*/
public void remove() {
app.getGuiNode().detachChild(toolbarContainer);
app.getGuiNode().detachChild(positionText);
}
}

View File

@ -12,7 +12,6 @@ import com.simsilica.lemur.component.SpringGridLayout;
import com.simsilica.lemur.core.VersionedList;
import com.simsilica.lemur.core.VersionedReference;
import com.simsilica.lemur.style.ElementId;
import com.simsilica.lemur.text.DocumentModel;
import pp.dialog.Dialog;
import pp.monopoly.client.MonopolyApp;
@ -55,7 +54,6 @@ public class TradeMenu extends Dialog {
private TextField leftCurrencyInput, rightCurrencyInput;
private VersionedReference<Set<Integer>> leftBuildingRef, rightBuildingRef;
private VersionedReference<DocumentModel> leftCurrencyRef, rightCurrencyRef;
private VersionedReference<Set<Integer>> leftCardRef, rightCardRef;
private Set<String> rightselBuildings = new HashSet<>();
@ -339,11 +337,9 @@ public class TradeMenu extends Dialog {
private void initializeReferences() {
leftBuildingRef = leftBuildingSelector.getSelectionModel().createReference();
leftCardRef = leftSpecialCardSelector.getSelectionModel().createReference();
leftCurrencyRef = leftCurrencyInput.getDocumentModel().createReference();
rightBuildingRef = rightBuildingSelector.getSelectionModel().createReference();
rightCardRef = rightSpecialCardSelector.getSelectionModel().createReference();
rightCurrencyRef = rightCurrencyInput.getDocumentModel().createReference();
}
/**

View File

@ -11,7 +11,6 @@ import pp.monopoly.client.MonopolyApp;
import pp.monopoly.client.gui.SettingsMenu;
import pp.monopoly.client.gui.TradeMenu;
import pp.monopoly.message.client.TradeResponse;
import pp.monopoly.message.server.TradeReply;
import pp.monopoly.model.TradeHandler;
import pp.monopoly.model.fields.PropertyField;
import pp.monopoly.notification.Sound;

View File

@ -31,8 +31,6 @@ public class EventCardPopup extends Dialog {
/** Background container providing a border for the popup. */
private final Container backgroundContainer;
/** The description of the event card. */
private final String description;
/**
* Constructs the EventCardPopup to display the details of a triggered event card.
@ -43,7 +41,6 @@ public class EventCardPopup extends Dialog {
public EventCardPopup(MonopolyApp app, String description) {
super(app.getDialogManager());
this.app = app;
this.description = description;
// Halbtransparentes Overlay hinzufügen
overlayBackground = createOverlayBackground();

View File

@ -1,10 +1,6 @@
package pp.monopoly.client.gui.popups;
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.shape.Quad;
import com.simsilica.lemur.Button;
import com.simsilica.lemur.Container;
import com.simsilica.lemur.Label;
@ -109,22 +105,6 @@ public class GateFieldCard extends Dialog {
app.getGuiNode().attachChild(gateFieldContainer);
}
/**
* Creates a semi-transparent background overlay for the popup.
*
* @return the geometry of the overlay
*/
private Geometry createOverlayBackground() {
Quad quad = new Quad(app.getCamera().getWidth(), app.getCamera().getHeight());
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;
}
/**
* Closes the popup and removes its associated GUI elements.
*/

View File

@ -1,17 +1,13 @@
package pp.monopoly.client.gui.popups;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f;
import com.simsilica.lemur.Axis;
import com.simsilica.lemur.Button;
import com.simsilica.lemur.Checkbox;
import com.simsilica.lemur.Container;
import com.simsilica.lemur.Label;
import com.simsilica.lemur.ListBox;
import com.simsilica.lemur.Selector;
import com.simsilica.lemur.TextField;
import com.simsilica.lemur.component.IconComponent;
import com.simsilica.lemur.component.QuadBackgroundComponent;
import com.simsilica.lemur.component.SpringGridLayout;
import com.simsilica.lemur.core.VersionedList;

View File

@ -21,7 +21,6 @@ import pp.monopoly.message.client.AlterProperty;
import pp.monopoly.model.fields.BoardManager;
import pp.monopoly.model.fields.BuildingProperty;
import pp.monopoly.model.fields.PropertyField;
import pp.monopoly.model.fields.PropertyField;
import pp.monopoly.notification.Sound;
import java.util.HashSet;

View File

@ -14,7 +14,6 @@ import com.simsilica.lemur.style.ElementId;
import pp.dialog.Dialog;
import pp.monopoly.client.MonopolyApp;
import pp.monopoly.notification.Sound;
import static pp.monopoly.Resources.lookup;
/**
* TimeOut is a warning popup triggered when the connection to the server is interrupted.

View File

@ -246,7 +246,7 @@ public class Player implements FieldVisitor<Void>{
*/
public void sellProperty(PropertyField property) {
if (property.getOwner() == this) {
properties.remove(property);
properties.remove(property.getId());
property.setOwner(null);
}
}

View File

@ -4,9 +4,7 @@ import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.util.HashSet;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import pp.monopoly.MonopolyConfig;
@ -212,7 +210,6 @@ public class ServerGameLogic implements ClientInterpreter {
String truc = name.length() > 10 ? name.substring(0, 15) : name;
player.setName(truc);
player.setFigure(new Figure(1, -10, -10, Rotation.LEFT, msg.getFigure()));
//TODO add figure to the map
playerHandler.setPlayerReady(player, true);
LOGGER.log(Level.DEBUG, "Player {0} is ready", player.getName());
}
@ -427,15 +424,14 @@ public class ServerGameLogic implements ClientInterpreter {
@Override
public void received(NotificationAnswer msg, int from) {
if(msg.getA().equals("UseJailCard")) {
if(msg.getKeyword().equals("UseJailCard")) {
playerHandler.getPlayerById(from).useJailCard();
} else if (msg.getA().equals("PayJail")) {
} else if (msg.getKeyword().equals("PayJail")) {
playerHandler.getPlayerById(from).payBail();
} else if(msg.getA().equals("hack")) {
// for (BuildingProperty bp : boardManager.getPropertyFields( List.of(1,3)).stream().filter(p -> p instanceof BuildingProperty).map(p -> (BuildingProperty) p).collect(Collectors.toList())) {
// bp.setOwner(playerHandler.getPlayerById(0));
// playerHandler.getPlayerById(0).addProperty(bp.getId());
// }
} else if(msg.getKeyword().equals("hack")) {
for (BuildingProperty bp : boardManager.getPropertyFields( List.of(1,3)).stream().filter(p -> p instanceof BuildingProperty).map(p -> (BuildingProperty) p).collect(Collectors.toList())) {
bp.build();
}
for(PropertyField field : boardManager.getBoard().stream().filter(p -> p instanceof PropertyField).map(p -> (PropertyField) p).collect(Collectors.toList())) {
field.setOwner(playerHandler.getPlayerById(0));
playerHandler.getPlayerById(0).addProperty(field.getId());

View File

@ -5,16 +5,16 @@ import com.jme3.network.serializing.Serializable;
@Serializable
public class NotificationAnswer extends ClientMessage{
private String A;
private String keyword;
private NotificationAnswer() {}
public NotificationAnswer(String A) {
this.A = A;
public NotificationAnswer(String keyword) {
this.keyword = keyword;
}
public String getA() {
return A;
public String getKeyword() {
return keyword;
}
@Override

View File

@ -11,11 +11,4 @@ public class BuyPropertyRequest extends ServerMessage{
public void accept(ServerInterpreter interpreter) {
interpreter.received(this);
}
@Override
public String getInfoTextKey() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getInfoTextKey'");
}
}

View File

@ -32,12 +32,6 @@ public class DiceResult extends ServerMessage{
interpreter.received(this);
}
@Override
public String getInfoTextKey() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getInfoTextKey'");
}
public boolean isDoublets() {
return a == b;
}

View File

@ -20,12 +20,6 @@ public class EventDrawCard extends ServerMessage{
interpreter.received(this);
}
@Override
public String getInfoTextKey() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getInfoTextKey'");
}
public String getCardDescription() {
return cardDescription;
}

View File

@ -24,10 +24,4 @@ public class GameOver extends ServerMessage{
interpreter.received(this);
}
@Override
public String getInfoTextKey() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getInfoTextKey'");
}
}

View File

@ -27,10 +27,4 @@ public class GameStart extends ServerMessage{
interpreter.received(this);
}
@Override
public String getInfoTextKey() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getInfoTextKey'");
}
}

View File

@ -25,10 +25,4 @@ public class JailEvent extends ServerMessage{
interpreter.received(this);
}
@Override
public String getInfoTextKey() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getInfoTextKey'");
}
}

View File

@ -15,10 +15,5 @@ public class NextPlayerTurn extends ServerMessage{
public void accept(ServerInterpreter interpreter) {
interpreter.received(this);
}
@Override
public String getInfoTextKey() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getInfoTextKey'");
}
}

View File

@ -41,10 +41,4 @@ public class NotificationMessage extends ServerMessage{
interpreter.received(this);
}
@Override
public String getInfoTextKey() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getInfoTextKey'");
}
}

View File

@ -27,10 +27,4 @@ public class PlayerStatusUpdate extends ServerMessage{
interpreter.received(this);
}
@Override
public String getInfoTextKey() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getInfoTextKey'");
}
}

View File

@ -28,12 +28,4 @@ public abstract class ServerMessage extends AbstractMessage {
* @param interpreter the visitor to be used for processing
*/
public abstract void accept(ServerInterpreter interpreter);
/**
* Gets the bundle key of the informational text to be shown at the client.
* This key is used to retrieve the appropriate localized text for display.
*
* @return the bundle key of the informational text
*/
public abstract String getInfoTextKey();
}

View File

@ -25,10 +25,4 @@ public class TimeOutWarning extends ServerMessage{
interpreter.received(this);
}
@Override
public String getInfoTextKey() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getInfoTextKey'");
}
}

View File

@ -38,10 +38,4 @@ public class TradeReply extends ServerMessage{
interpreter.received(this);
}
@Override
public String getInfoTextKey() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getInfoTextKey'");
}
}

View File

@ -34,10 +34,4 @@ public class TradeRequest extends ServerMessage{
interpreter.received(this);
}
@Override
public String getInfoTextKey() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getInfoTextKey'");
}
}

View File

@ -32,13 +32,8 @@ public class ViewAssetsResponse extends ServerMessage{
interpreter.received(this);
}
@Override
public String getInfoTextKey() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getInfoTextKey'");
}
public BoardManager getboard() {
return board;
}
}

View File

@ -7,11 +7,11 @@
package pp.monopoly.model;
import java.io.Serializable;
/**
* Represents the rotation of a Item and provides functionality related to rotation.
*/
import java.io.Serializable;
public enum Rotation implements Serializable {
/**
* Represents the item facing upwards.