mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2025-08-03 20:34:29 +02:00
Compare commits
3 Commits
970a0ae254
...
e000dcfc51
Author | SHA1 | Date | |
---|---|---|---|
|
e000dcfc51 | ||
|
e7a06159bb | ||
|
c900b6384d |
@@ -3,7 +3,10 @@ package pp.monopoly.client.gui;
|
|||||||
import com.jme3.math.ColorRGBA;
|
import com.jme3.math.ColorRGBA;
|
||||||
import com.jme3.math.Vector2f;
|
import com.jme3.math.Vector2f;
|
||||||
import com.jme3.math.Vector3f;
|
import com.jme3.math.Vector3f;
|
||||||
import com.simsilica.lemur.*;
|
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.IconComponent;
|
import com.simsilica.lemur.component.IconComponent;
|
||||||
import com.simsilica.lemur.component.QuadBackgroundComponent;
|
import com.simsilica.lemur.component.QuadBackgroundComponent;
|
||||||
import com.simsilica.lemur.component.SpringGridLayout;
|
import com.simsilica.lemur.component.SpringGridLayout;
|
||||||
@@ -15,20 +18,22 @@ import pp.monopoly.game.server.Player;
|
|||||||
import pp.monopoly.game.server.PlayerHandler;
|
import pp.monopoly.game.server.PlayerHandler;
|
||||||
import pp.monopoly.message.client.EndTurn;
|
import pp.monopoly.message.client.EndTurn;
|
||||||
import pp.monopoly.message.client.RollDice;
|
import pp.monopoly.message.client.RollDice;
|
||||||
import pp.monopoly.notification.DiceRollEvent;
|
import pp.monopoly.notification.*;
|
||||||
import pp.monopoly.notification.GameEventListener;
|
|
||||||
import pp.monopoly.notification.Sound;
|
|
||||||
import pp.monopoly.notification.UpdatePlayerView;
|
|
||||||
|
|
||||||
public class Toolbar extends Dialog implements GameEventListener {
|
public class Toolbar extends Dialog implements GameEventListener {
|
||||||
|
|
||||||
private final MonopolyApp app;
|
private final MonopolyApp app;
|
||||||
private final Container toolbarContainer;
|
private final Container toolbarContainer;
|
||||||
private Label imageLabel;
|
|
||||||
private Label imageLabel2;
|
|
||||||
private Container overviewContainer;
|
private Container overviewContainer;
|
||||||
private Container accountContainer;
|
private Container accountContainer;
|
||||||
private PlayerHandler playerHandler;
|
private PlayerHandler playerHandler;
|
||||||
|
private Label imageLabel;
|
||||||
|
private Label imageLabel2;
|
||||||
|
private Button diceButton;
|
||||||
|
private Button tradeButton;
|
||||||
|
private Button propertyMenuButton;
|
||||||
|
private Button endTurnButton;
|
||||||
|
|
||||||
private volatile boolean animatingDice = false;
|
private volatile boolean animatingDice = false;
|
||||||
private volatile DiceRollEvent latestDiceRollEvent = null;
|
private volatile DiceRollEvent latestDiceRollEvent = null;
|
||||||
|
|
||||||
@@ -37,73 +42,82 @@ public class Toolbar extends Dialog implements GameEventListener {
|
|||||||
this.app = app;
|
this.app = app;
|
||||||
|
|
||||||
app.getGameLogic().addListener(this);
|
app.getGameLogic().addListener(this);
|
||||||
playerHandler = app.getGameLogic().getPlayerHandler();
|
this.playerHandler = app.getGameLogic().getPlayerHandler();
|
||||||
|
|
||||||
// Erstelle die Toolbar
|
toolbarContainer = createToolbarContainer();
|
||||||
toolbarContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y), "toolbar");
|
app.getGuiNode().attachChild(toolbarContainer);
|
||||||
toolbarContainer.setLocalTranslation(0, 200, 0);
|
}
|
||||||
toolbarContainer.setPreferredSize(new Vector3f(app.getCamera().getWidth(), 200, 0));
|
|
||||||
|
|
||||||
// Account- und Übersichtskontainer
|
private Container createToolbarContainer() {
|
||||||
accountContainer = toolbarContainer.addChild(new Container());
|
Container container = new Container(new SpringGridLayout(Axis.X, Axis.Y), "toolbar");
|
||||||
overviewContainer = toolbarContainer.addChild(new Container());
|
container.setLocalTranslation(0, 200, 0);
|
||||||
|
container.setPreferredSize(new Vector3f(app.getCamera().getWidth(), 200, 0));
|
||||||
|
|
||||||
|
// Create account and overview containers
|
||||||
|
accountContainer = container.addChild(new Container());
|
||||||
|
overviewContainer = container.addChild(new Container());
|
||||||
receivedEvent(new UpdatePlayerView());
|
receivedEvent(new UpdatePlayerView());
|
||||||
|
|
||||||
overviewContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
|
// Dice section
|
||||||
|
container.addChild(createDiceSection());
|
||||||
|
|
||||||
// Würfelbereich
|
// Action menu
|
||||||
Container diceContainer = toolbarContainer.addChild(new Container());
|
Container menuContainer = container.addChild(new Container());
|
||||||
diceContainer.setLayout(new SpringGridLayout(Axis.X, Axis.Y));
|
menuContainer.addChild(createTradeButton());
|
||||||
|
menuContainer.addChild(createPropertyMenuButton());
|
||||||
|
menuContainer.addChild(createEndTurnButton());
|
||||||
|
menuContainer.setBackground(createBackground());
|
||||||
|
|
||||||
Container horizontalContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y));
|
return container;
|
||||||
horizontalContainer.setPreferredSize(new Vector3f(200, 150, 0));
|
}
|
||||||
|
|
||||||
// Linker Würfel
|
private Container createDiceSection() {
|
||||||
Container leftContainer = new Container();
|
Container diceContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y));
|
||||||
leftContainer.setPreferredSize(new Vector3f(100, 150, 0));
|
diceContainer.addChild(createDiceDisplay());
|
||||||
imageLabel = new Label("");
|
|
||||||
IconComponent icon = new IconComponent("Pictures/dice/one.png");
|
|
||||||
icon.setIconSize(new Vector2f(100, 100));
|
|
||||||
imageLabel.setIcon(icon);
|
|
||||||
|
|
||||||
// Rechter Würfel
|
diceButton = new Button("Würfeln", new ElementId("button-toolbar"));
|
||||||
Container rightContainer = new Container();
|
|
||||||
rightContainer.setPreferredSize(new Vector3f(100, 150, 0));
|
|
||||||
imageLabel2 = new Label("");
|
|
||||||
IconComponent icon2 = new IconComponent("Pictures/dice/two.png");
|
|
||||||
icon2.setIconSize(new Vector2f(100, 100));
|
|
||||||
imageLabel2.setIcon(icon2);
|
|
||||||
|
|
||||||
leftContainer.addChild(imageLabel);
|
|
||||||
rightContainer.addChild(imageLabel2);
|
|
||||||
|
|
||||||
horizontalContainer.addChild(leftContainer);
|
|
||||||
horizontalContainer.addChild(rightContainer);
|
|
||||||
diceContainer.addChild(horizontalContainer);
|
|
||||||
|
|
||||||
// Würfeln-Button
|
|
||||||
Button diceButton = new Button("Würfeln", new ElementId("button-toolbar"));
|
|
||||||
diceButton.setPreferredSize(new Vector3f(200, 50, 0));
|
diceButton.setPreferredSize(new Vector3f(200, 50, 0));
|
||||||
diceButton.addClickCommands(s -> ifTopDialog(() -> {
|
diceButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||||
|
diceButton.setEnabled(false);
|
||||||
startDiceAnimation();
|
startDiceAnimation();
|
||||||
app.getGameLogic().send(new RollDice());
|
app.getGameLogic().send(new RollDice());
|
||||||
app.getGameLogic().playSound(Sound.BUTTON);
|
app.getGameLogic().playSound(Sound.BUTTON);
|
||||||
}));
|
}));
|
||||||
diceContainer.addChild(diceButton);
|
diceContainer.addChild(diceButton);
|
||||||
|
|
||||||
// Menü-Container für weitere Aktionen
|
return diceContainer;
|
||||||
Container menuContainer = toolbarContainer.addChild(new Container());
|
|
||||||
menuContainer.addChild(addTradeMenuButton());
|
|
||||||
menuContainer.addChild(addPropertyMenuButton());
|
|
||||||
menuContainer.addChild(addEndTurnButton());
|
|
||||||
menuContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
|
|
||||||
|
|
||||||
app.getGuiNode().attachChild(toolbarContainer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Button addTradeMenuButton() {
|
private Container createDiceDisplay() {
|
||||||
Button tradeButton = new Button("Handeln", new ElementId("button-toolbar"));
|
Container horizontalContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y));
|
||||||
|
horizontalContainer.setPreferredSize(new Vector3f(200, 150, 0));
|
||||||
|
|
||||||
|
imageLabel = createDiceLabel("Pictures/dice/one.png");
|
||||||
|
imageLabel2 = createDiceLabel("Pictures/dice/two.png");
|
||||||
|
|
||||||
|
horizontalContainer.addChild(createDiceContainer(imageLabel));
|
||||||
|
horizontalContainer.addChild(createDiceContainer(imageLabel2));
|
||||||
|
|
||||||
|
return horizontalContainer;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Label createDiceLabel(String iconPath) {
|
||||||
|
Label label = new Label("");
|
||||||
|
IconComponent icon = new IconComponent(iconPath);
|
||||||
|
icon.setIconSize(new Vector2f(100, 100));
|
||||||
|
label.setIcon(icon);
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Container createDiceContainer(Label label) {
|
||||||
|
Container container = new Container();
|
||||||
|
container.setPreferredSize(new Vector3f(100, 150, 0));
|
||||||
|
container.addChild(label);
|
||||||
|
return container;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Button createTradeButton() {
|
||||||
|
tradeButton = new Button("Handeln", new ElementId("button-toolbar"));
|
||||||
tradeButton.setPreferredSize(new Vector3f(150, 50, 0));
|
tradeButton.setPreferredSize(new Vector3f(150, 50, 0));
|
||||||
tradeButton.addClickCommands(s -> ifTopDialog(() -> {
|
tradeButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||||
app.getGameLogic().playSound(Sound.BUTTON);
|
app.getGameLogic().playSound(Sound.BUTTON);
|
||||||
@@ -112,99 +126,100 @@ public class Toolbar extends Dialog implements GameEventListener {
|
|||||||
return tradeButton;
|
return tradeButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Button addPropertyMenuButton() {
|
private Button createPropertyMenuButton() {
|
||||||
Button propertyMenuButton = new Button("Grundstücke", new ElementId("button-toolbar"));
|
propertyMenuButton = new Button("Grundstücke", new ElementId("button-toolbar"));
|
||||||
propertyMenuButton.setPreferredSize(new Vector3f(150, 50, 0));
|
propertyMenuButton.setPreferredSize(new Vector3f(150, 50, 0));
|
||||||
propertyMenuButton.setFontSize(30);
|
propertyMenuButton.setFontSize(30);
|
||||||
propertyMenuButton.addClickCommands(s -> ifTopDialog(() -> {
|
propertyMenuButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||||
app.getGameLogic().playSound(Sound.BUTTON);
|
app.getGameLogic().playSound(Sound.BUTTON);
|
||||||
// new BuildingAdminMenu(app).open();
|
|
||||||
new PropertyOverviewMenu(app).open();
|
new PropertyOverviewMenu(app).open();
|
||||||
}));
|
}));
|
||||||
return propertyMenuButton;
|
return propertyMenuButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Button addEndTurnButton() {
|
private Button createEndTurnButton() {
|
||||||
Button endTurnButton = new Button("Zug beenden", new ElementId("button-toolbar"));
|
endTurnButton = new Button("Zug beenden", new ElementId("button-toolbar"));
|
||||||
endTurnButton.setPreferredSize(new Vector3f(150, 50, 0));
|
endTurnButton.setPreferredSize(new Vector3f(150, 50, 0));
|
||||||
endTurnButton.addClickCommands(s -> ifTopDialog(() -> {
|
endTurnButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||||
app.getGameLogic().playSound(Sound.BUTTON);
|
app.getGameLogic().playSound(Sound.BUTTON);
|
||||||
app.getGameLogic().send(new EndTurn());
|
app.getGameLogic().send(new EndTurn());
|
||||||
|
receivedEvent(new ButtonStatusEvent(false));
|
||||||
}));
|
}));
|
||||||
return endTurnButton;
|
return endTurnButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private QuadBackgroundComponent createBackground() {
|
||||||
|
return new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f));
|
||||||
|
}
|
||||||
|
|
||||||
private void startDiceAnimation() {
|
private void startDiceAnimation() {
|
||||||
animatingDice = true;
|
animatingDice = true;
|
||||||
|
|
||||||
// Starte die Animation und speichere die Startzeit
|
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
Thread diceAnimation = new Thread(() -> {
|
new Thread(() -> {
|
||||||
int[] currentFace = {1};
|
|
||||||
try {
|
try {
|
||||||
while (System.currentTimeMillis() - startTime < 2500) { // Animation läuft für 4 Sekunden
|
animateDice(startTime);
|
||||||
|
animatingDice = false;
|
||||||
|
if (latestDiceRollEvent != null) {
|
||||||
|
showFinalDiceResult(latestDiceRollEvent);
|
||||||
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
System.err.println("Dice animation interrupted: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void animateDice(long startTime) throws InterruptedException {
|
||||||
|
int[] currentFace = {1};
|
||||||
|
while (System.currentTimeMillis() - startTime < 2500) { // Animation duration
|
||||||
currentFace[0] = (currentFace[0] % 6) + 1;
|
currentFace[0] = (currentFace[0] % 6) + 1;
|
||||||
|
|
||||||
String rotatingImage1 = diceToString(currentFace[0]);
|
String rotatingImage1 = diceToString(currentFace[0]);
|
||||||
String rotatingImage2 = diceToString((currentFace[0] % 6) + 1);
|
String rotatingImage2 = diceToString((currentFace[0] % 6) + 1);
|
||||||
|
|
||||||
IconComponent newIcon1 = new IconComponent(rotatingImage1);
|
app.enqueue(() -> {
|
||||||
newIcon1.setIconSize(new Vector2f(100, 100));
|
setDiceIcon(imageLabel, rotatingImage1);
|
||||||
app.enqueue(() -> imageLabel.setIcon(newIcon1));
|
setDiceIcon(imageLabel2, rotatingImage2);
|
||||||
|
|
||||||
IconComponent newIcon2 = new IconComponent(rotatingImage2);
|
|
||||||
newIcon2.setIconSize(new Vector2f(100, 100));
|
|
||||||
app.enqueue(() -> imageLabel2.setIcon(newIcon2));
|
|
||||||
|
|
||||||
// Warte 100 ms, bevor die Bilder wechseln
|
|
||||||
Thread.sleep(100);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Animation beenden
|
|
||||||
animatingDice = false;
|
|
||||||
|
|
||||||
// Zeige das finale Ergebnis
|
|
||||||
if (latestDiceRollEvent != null) {
|
|
||||||
showFinalDiceResult(latestDiceRollEvent);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
System.err.println("Würfelanimation unterbrochen: " + e.getMessage());
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
diceAnimation.start();
|
|
||||||
|
Thread.sleep(100); // Time between frame updates
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showFinalDiceResult(DiceRollEvent event) {
|
private void showFinalDiceResult(DiceRollEvent event) {
|
||||||
int diceRoll1 = event.a();
|
app.enqueue(() -> {
|
||||||
int diceRoll2 = event.b();
|
setDiceIcon(imageLabel, diceToString(event.a()));
|
||||||
|
setDiceIcon(imageLabel2, diceToString(event.b()));
|
||||||
String finalImage1 = diceToString(diceRoll1);
|
|
||||||
String finalImage2 = diceToString(diceRoll2);
|
|
||||||
|
|
||||||
IconComponent finalIcon1 = new IconComponent(finalImage1);
|
|
||||||
finalIcon1.setIconSize(new Vector2f(100, 100));
|
|
||||||
app.enqueue(() -> imageLabel.setIcon(finalIcon1));
|
|
||||||
|
|
||||||
IconComponent finalIcon2 = new IconComponent(finalImage2);
|
|
||||||
finalIcon2.setIconSize(new Vector2f(100, 100));
|
|
||||||
app.enqueue(() -> imageLabel2.setIcon(finalIcon2));
|
|
||||||
|
|
||||||
app.getGameLogic().playSound(Sound.BUTTON);
|
app.getGameLogic().playSound(Sound.BUTTON);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setDiceIcon(Label label, String imagePath) {
|
||||||
|
IconComponent icon = new IconComponent(imagePath);
|
||||||
|
icon.setIconSize(new Vector2f(80, 80)); // Set consistent dice size
|
||||||
|
label.setIcon(icon);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private String diceToString(int i) {
|
||||||
|
switch (i) {
|
||||||
|
case 1: return "Pictures/dice/one.png";
|
||||||
|
case 2: return "Pictures/dice/two.png";
|
||||||
|
case 3: return "Pictures/dice/three.png";
|
||||||
|
case 4: return "Pictures/dice/four.png";
|
||||||
|
case 5: return "Pictures/dice/five.png";
|
||||||
|
case 6: return "Pictures/dice/six.png";
|
||||||
|
default: throw new IllegalArgumentException("Invalid dice number: " + i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void receivedEvent(DiceRollEvent event) {
|
public void receivedEvent(DiceRollEvent event) {
|
||||||
latestDiceRollEvent = event; // Speichere das Event
|
latestDiceRollEvent = event;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void receivedEvent(UpdatePlayerView event) {
|
public void receivedEvent(UpdatePlayerView event) {
|
||||||
playerHandler = app.getGameLogic().getPlayerHandler();
|
|
||||||
System.err.println("Update Player View");
|
|
||||||
|
|
||||||
// Clear existing accountContainer and overviewContainer content
|
|
||||||
accountContainer.clearChildren();
|
accountContainer.clearChildren();
|
||||||
overviewContainer.clearChildren();
|
overviewContainer.clearChildren();
|
||||||
|
|
||||||
@@ -218,7 +233,7 @@ public class Toolbar extends Dialog implements GameEventListener {
|
|||||||
playerHandler.getPlayerById(app.getId()).getNumJailCard() + "",
|
playerHandler.getPlayerById(app.getId()).getNumJailCard() + "",
|
||||||
new ElementId("label-Text")
|
new ElementId("label-Text")
|
||||||
));
|
));
|
||||||
accountContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
|
accountContainer.setBackground(createBackground());
|
||||||
|
|
||||||
overviewContainer.addChild(new Label("Übersicht", new ElementId("label-Bold")));
|
overviewContainer.addChild(new Label("Übersicht", new ElementId("label-Bold")));
|
||||||
for (Player player : playerHandler.getPlayers()) {
|
for (Player player : playerHandler.getPlayers()) {
|
||||||
@@ -229,26 +244,16 @@ public class Toolbar extends Dialog implements GameEventListener {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
overviewContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
|
overviewContainer.setBackground(createBackground());
|
||||||
}
|
}
|
||||||
|
|
||||||
private String diceToString(int i) {
|
@Override
|
||||||
switch (i) {
|
public void receivedEvent(ButtonStatusEvent event) {
|
||||||
case 1:
|
boolean enabled = event.buttonsEnabled();
|
||||||
return "Pictures/dice/one.png";
|
diceButton.setEnabled(enabled);
|
||||||
case 2:
|
tradeButton.setEnabled(enabled);
|
||||||
return "Pictures/dice/two.png";
|
propertyMenuButton.setEnabled(enabled);
|
||||||
case 3:
|
endTurnButton.setEnabled(enabled);
|
||||||
return "Pictures/dice/three.png";
|
|
||||||
case 4:
|
|
||||||
return "Pictures/dice/four.png";
|
|
||||||
case 5:
|
|
||||||
return "Pictures/dice/five.png";
|
|
||||||
case 6:
|
|
||||||
return "Pictures/dice/six.png";
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException("Invalid dice number: " + i);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -5,10 +5,8 @@ import java.lang.System.Logger.Level;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import pp.monopoly.game.server.Player;
|
|
||||||
import pp.monopoly.game.server.PlayerHandler;
|
import pp.monopoly.game.server.PlayerHandler;
|
||||||
import pp.monopoly.message.client.ClientMessage;
|
import pp.monopoly.message.client.ClientMessage;
|
||||||
import pp.monopoly.message.server.BuyPropertyResponse;
|
|
||||||
import pp.monopoly.message.server.DiceResult;
|
import pp.monopoly.message.server.DiceResult;
|
||||||
import pp.monopoly.message.server.EventDrawCard;
|
import pp.monopoly.message.server.EventDrawCard;
|
||||||
import pp.monopoly.message.server.GameOver;
|
import pp.monopoly.message.server.GameOver;
|
||||||
@@ -26,6 +24,7 @@ import pp.monopoly.model.IntPoint;
|
|||||||
import pp.monopoly.model.fields.BoardManager;
|
import pp.monopoly.model.fields.BoardManager;
|
||||||
import pp.monopoly.notification.ClientStateEvent;
|
import pp.monopoly.notification.ClientStateEvent;
|
||||||
import pp.monopoly.notification.DiceRollEvent;
|
import pp.monopoly.notification.DiceRollEvent;
|
||||||
|
import pp.monopoly.notification.ButtonStatusEvent;
|
||||||
import pp.monopoly.notification.EventCardEvent;
|
import pp.monopoly.notification.EventCardEvent;
|
||||||
import pp.monopoly.notification.GameEvent;
|
import pp.monopoly.notification.GameEvent;
|
||||||
import pp.monopoly.notification.GameEventBroker;
|
import pp.monopoly.notification.GameEventBroker;
|
||||||
@@ -194,21 +193,6 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
|||||||
state.update(delta);
|
state.update(delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles the response for buying a property.
|
|
||||||
*
|
|
||||||
* @param msg the message containing the buy property response
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void received(BuyPropertyResponse msg) {
|
|
||||||
if (msg.isSuccessful()) {
|
|
||||||
|
|
||||||
playSound(Sound.MONEY_LOST);
|
|
||||||
} else {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the result of a dice roll.
|
* Handles the result of a dice roll.
|
||||||
*
|
*
|
||||||
@@ -258,7 +242,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
|||||||
public void received(GameStart msg) {
|
public void received(GameStart msg) {
|
||||||
playerHandler = msg.getPlayerHandler();
|
playerHandler = msg.getPlayerHandler();
|
||||||
setState(new WaitForTurnState(this));
|
setState(new WaitForTurnState(this));
|
||||||
|
notifyListeners(new ButtonStatusEvent(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -342,7 +326,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void received(NextPlayerTurn msg) {
|
public void received(NextPlayerTurn msg) {
|
||||||
|
notifyListeners(new ButtonStatusEvent(true));
|
||||||
setState(new ActiveState(this));
|
setState(new ActiveState(this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -15,6 +15,7 @@ import com.jme3.network.serializing.Serializable;
|
|||||||
|
|
||||||
import pp.monopoly.message.server.DiceResult;
|
import pp.monopoly.message.server.DiceResult;
|
||||||
import pp.monopoly.message.server.EventDrawCard;
|
import pp.monopoly.message.server.EventDrawCard;
|
||||||
|
import pp.monopoly.message.server.NextPlayerTurn;
|
||||||
import pp.monopoly.message.server.PlayerStatusUpdate;
|
import pp.monopoly.message.server.PlayerStatusUpdate;
|
||||||
import pp.monopoly.model.FieldVisitor;
|
import pp.monopoly.model.FieldVisitor;
|
||||||
import pp.monopoly.model.Figure;
|
import pp.monopoly.model.Figure;
|
||||||
@@ -44,7 +45,9 @@ public class Player implements FieldVisitor<Void>{
|
|||||||
private int fieldID;
|
private int fieldID;
|
||||||
private DiceResult rollResult;
|
private DiceResult rollResult;
|
||||||
private transient final PlayerHandler handler;
|
private transient final PlayerHandler handler;
|
||||||
private transient PlayerState state = new LobbyState();
|
private transient PlayerState state = new WaitForTurnState();
|
||||||
|
private int doubletscounter = 0;
|
||||||
|
private boolean mayRollDice = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor for serialization purposes.
|
* Default constructor for serialization purposes.
|
||||||
@@ -127,6 +130,8 @@ public class Player implements FieldVisitor<Void>{
|
|||||||
}
|
}
|
||||||
void setActive() {
|
void setActive() {
|
||||||
state = new ActiveState();
|
state = new ActiveState();
|
||||||
|
doubletscounter = 0;
|
||||||
|
mayRollDice = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean finishTurn() {
|
boolean finishTurn() {
|
||||||
@@ -162,9 +167,23 @@ public class Player implements FieldVisitor<Void>{
|
|||||||
earnMoney(2000);
|
earnMoney(2000);
|
||||||
}
|
}
|
||||||
figure.moveTo(fieldID);
|
figure.moveTo(fieldID);
|
||||||
|
handler.getLogic().getBoardManager().getFieldAtIndex(fieldID).accept(this);
|
||||||
return fieldID;
|
return fieldID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the player to the specified Position on the board
|
||||||
|
* @param position the position to move to
|
||||||
|
* @return the new position
|
||||||
|
*/
|
||||||
|
public int setPosition(int position){
|
||||||
|
if(position < 40 && position > 0) {
|
||||||
|
fieldID = position;
|
||||||
|
figure.moveTo(fieldID);
|
||||||
|
handler.getLogic().getBoardManager().getFieldAtIndex(fieldID).accept(this);
|
||||||
|
}
|
||||||
|
return fieldID;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all the properties owned by this player
|
* Gets all the properties owned by this player
|
||||||
@@ -330,15 +349,13 @@ public class Player implements FieldVisitor<Void>{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Void visit(WacheField field) {
|
public Void visit(WacheField field) {
|
||||||
movePos(10);
|
setPosition(10);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Void visit(GoField field) {
|
public Void visit(GoField field) {
|
||||||
earnMoney(2000);
|
earnMoney(2000);
|
||||||
GulagField res = (GulagField) handler.getLogic().getBoardManager().getFieldAtIndex(10);
|
|
||||||
res.accept(this);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -410,11 +427,21 @@ public class Player implements FieldVisitor<Void>{
|
|||||||
* @return a List of two integers representing the dice roll results
|
* @return a List of two integers representing the dice roll results
|
||||||
*/
|
*/
|
||||||
DiceResult rollDice() {
|
DiceResult rollDice() {
|
||||||
return state.rollDice();
|
if (mayRollDice) {
|
||||||
|
state.rollDice();
|
||||||
}
|
}
|
||||||
|
if (rollResult.isDoublets()) {
|
||||||
private void visitEvent() {
|
doubletscounter++;
|
||||||
getHandler().getLogic().getBoardManager().getFieldAtIndex(36).accept(this);
|
mayRollDice = true;
|
||||||
|
getHandler().getLogic().send(this, new NextPlayerTurn());
|
||||||
|
setName(name);
|
||||||
|
if (doubletscounter >= 3) {
|
||||||
|
setPosition(10);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mayRollDice = false;
|
||||||
|
}
|
||||||
|
return rollResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -464,31 +491,6 @@ public class Player implements FieldVisitor<Void>{
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A class to represent the Lobby PlayerState
|
|
||||||
* Set when in Lobby
|
|
||||||
*/
|
|
||||||
private class LobbyState implements PlayerState{
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public DiceResult rollDice() {
|
|
||||||
//do nothing
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void payBail() {
|
|
||||||
//do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void useJailCard() {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class to represent the Jailed PlayerState
|
* A class to represent the Jailed PlayerState
|
||||||
* Set when in Gulag
|
* Set when in Gulag
|
||||||
|
@@ -169,12 +169,14 @@ public class ServerGameLogic implements ClientInterpreter {
|
|||||||
@Override
|
@Override
|
||||||
public void received(EndTurn msg, int from) {
|
public void received(EndTurn msg, int from) {
|
||||||
Player player = playerHandler.getPlayerById(from);
|
Player player = playerHandler.getPlayerById(from);
|
||||||
if (player != null && state == ServerState.INGAME) {
|
if (player != null && player == playerHandler.getPlayerAtIndex(0)) {
|
||||||
if (player.finishTurn()) {
|
if (player.finishTurn()) {
|
||||||
LOGGER.log(Level.DEBUG, "Ending turn for player {0}", player.getName());
|
LOGGER.log(Level.DEBUG, "Ending turn for player {0}", player.getName());
|
||||||
Player next = playerHandler.nextPlayer();
|
Player next = playerHandler.nextPlayer();
|
||||||
next.setActive();
|
next.setActive();
|
||||||
send(next, new NextPlayerTurn());
|
send(next, new NextPlayerTurn());
|
||||||
|
send(next, new PlayerStatusUpdate(playerHandler));
|
||||||
|
send(player, new PlayerStatusUpdate(playerHandler));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,47 +0,0 @@
|
|||||||
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 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;
|
|
||||||
this.propertyName = propertyName;
|
|
||||||
this.reason = reason;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSuccessful() {
|
|
||||||
return successful;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPropertyName() {
|
|
||||||
return propertyName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getReason() {
|
|
||||||
return reason;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void accept(ServerInterpreter interpreter) {
|
|
||||||
interpreter.received(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getInfoTextKey() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
throw new UnsupportedOperationException("Unimplemented method 'getInfoTextKey'");
|
|
||||||
}
|
|
||||||
}
|
|
@@ -13,13 +13,6 @@ package pp.monopoly.message.server;
|
|||||||
*/
|
*/
|
||||||
public interface ServerInterpreter {
|
public interface ServerInterpreter {
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles a BuyPropertyResponse message received from the server.
|
|
||||||
*
|
|
||||||
* @param msg the BuyPropertyResponse message received
|
|
||||||
*/
|
|
||||||
void received(BuyPropertyResponse msg);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles a DiceResult message received from the server.
|
* Handles a DiceResult message received from the server.
|
||||||
*
|
*
|
||||||
|
@@ -0,0 +1,13 @@
|
|||||||
|
package pp.monopoly.notification;
|
||||||
|
|
||||||
|
public record ButtonStatusEvent(boolean buttonsEnabled) implements GameEvent{
|
||||||
|
/**
|
||||||
|
* Notifies the game event listener of this event.
|
||||||
|
*
|
||||||
|
* @param listener the game event listener
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void notifyListener(GameEventListener listener) {
|
||||||
|
listener.receivedEvent(this);
|
||||||
|
}
|
||||||
|
}
|
@@ -66,4 +66,11 @@ public interface GameEventListener {
|
|||||||
* @param event the received event
|
* @param event the received event
|
||||||
*/
|
*/
|
||||||
default void receivedEvent(EventCardEvent event) { /*Do nothing */}
|
default void receivedEvent(EventCardEvent event) { /*Do nothing */}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates that all buttons in the toolbar should be disabled
|
||||||
|
*
|
||||||
|
* @param event the received event
|
||||||
|
*/
|
||||||
|
default void receivedEvent(ButtonStatusEvent event) { /*Do nothing */}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user