jail logic complete

This commit is contained in:
Johannes Schmelz 2024-12-01 23:11:02 +01:00
parent 93152f4073
commit eda2fcd327
8 changed files with 46 additions and 31 deletions

View File

@ -279,7 +279,7 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
//logik zum wechselnden erscheinen und verschwinden beim drücken von B //TODO süäter entfernen //logik zum wechselnden erscheinen und verschwinden beim drücken von B //TODO süäter entfernen
private void handleB(boolean isPressed) { private void handleB(boolean isPressed) {
if (isPressed) { if (isPressed) {
Dialog tmp = new GulagInfo(this); Dialog tmp = new GulagInfo(this, 3);
tmp.open(); tmp.open();
} }
} }

View File

@ -18,6 +18,7 @@ import pp.monopoly.client.gui.popups.EventCardPopup;
import pp.monopoly.client.gui.popups.FoodFieldCard; import pp.monopoly.client.gui.popups.FoodFieldCard;
import pp.monopoly.client.gui.popups.GateFieldCard; import pp.monopoly.client.gui.popups.GateFieldCard;
import pp.monopoly.client.gui.popups.Gulag; import pp.monopoly.client.gui.popups.Gulag;
import pp.monopoly.client.gui.popups.GulagInfo;
import pp.monopoly.client.gui.popups.LooserPopUp; import pp.monopoly.client.gui.popups.LooserPopUp;
import pp.monopoly.client.gui.popups.NoMoneyWarning; import pp.monopoly.client.gui.popups.NoMoneyWarning;
import pp.monopoly.client.gui.popups.Rent; import pp.monopoly.client.gui.popups.Rent;
@ -380,8 +381,11 @@ public class TestWorld implements GameEventListener {
new NoMoneyWarning(app).open(); new NoMoneyWarning(app).open();
} else if(event.msg().equals("rent")) { } else if(event.msg().equals("rent")) {
new Rent(app, ( (NotificationMessage) event.message()).getRentOwner(), ( (NotificationMessage) event.message()).getRentAmount() ).open(); new Rent(app, ( (NotificationMessage) event.message()).getRentOwner(), ( (NotificationMessage) event.message()).getRentAmount() ).open();
} else if (event.msg().equals("jailtryagain")) {
new GulagInfo(app, 1).open();
} else if (event.msg().equals("jailpay")) {
new GulagInfo(app, 3).open();
} }
} }
@Override @Override

View File

@ -9,10 +9,7 @@ import com.simsilica.lemur.style.ElementId;
import pp.dialog.Dialog; import pp.dialog.Dialog;
import pp.monopoly.client.MonopolyApp; import pp.monopoly.client.MonopolyApp;
import pp.monopoly.client.gui.SettingsMenu; import pp.monopoly.client.gui.SettingsMenu;
import pp.monopoly.client.gui.TradeMenu; import pp.monopoly.message.client.NotificationAnswer;
import pp.monopoly.message.client.TradeResponse;
import pp.monopoly.model.TradeHandler;
import pp.monopoly.model.fields.PropertyField;
import pp.monopoly.notification.Sound; import pp.monopoly.notification.Sound;
/** /**
@ -24,7 +21,7 @@ public class GulagInfo extends Dialog {
private final Container backgroundContainer; private final Container backgroundContainer;
public GulagInfo(MonopolyApp app) { public GulagInfo(MonopolyApp app, int trys) {
super(app.getDialogManager()); super(app.getDialogManager());
this.app = app; this.app = app;
@ -54,12 +51,6 @@ public class GulagInfo extends Dialog {
propertyValuesContainer.addChild(new Label("- löst eine Gulag-Frei-Karte ein", new ElementId("label-Text"))); propertyValuesContainer.addChild(new Label("- löst eine Gulag-Frei-Karte ein", new ElementId("label-Text")));
propertyValuesContainer.addChild(new Label("- wartest 3 Runden und bezahlst dann", new ElementId("label-Text")));// Leerzeile propertyValuesContainer.addChild(new Label("- wartest 3 Runden und bezahlst dann", new ElementId("label-Text")));// Leerzeile
propertyValuesContainer.addChild(new Label("- oder du würfelst einen Pasch", new ElementId("label-Text"))); propertyValuesContainer.addChild(new Label("- oder du würfelst einen Pasch", new ElementId("label-Text")));
/*propertyValuesContainer.addChild(new Label("", new ElementId("label-Text")));// Leerzeile
propertyValuesContainer.addChild(new Label("- ", new ElementId("label-Text")));
propertyValuesContainer.addChild(new Label("- EUR", new ElementId("label-Text")));
propertyValuesContainer.addChild(new Label("- Sonderkaten", new ElementId("label-Text")));
propertyValuesContainer.addChild(new Label("", new ElementId("label-Text")));// Leerzeile
propertyValuesContainer.addChild(new Label("tauschen, willst du das Angebot annehmen?", new ElementId("label-Text")));*/
propertyValuesContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f))); propertyValuesContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
@ -68,6 +59,7 @@ public class GulagInfo extends Dialog {
negotiateButton.setFontSize(32); negotiateButton.setFontSize(32);
negotiateButton.addClickCommands(s -> ifTopDialog( () -> { negotiateButton.addClickCommands(s -> ifTopDialog( () -> {
app.getGameLogic().playSound(Sound.BUTTON); app.getGameLogic().playSound(Sound.BUTTON);
app.getGameLogic().send(new NotificationAnswer("PayJail"));
close(); close();
})); }));
// Ereigniskarte-Button // Ereigniskarte-Button
@ -75,6 +67,7 @@ public class GulagInfo extends Dialog {
confirmButton.setFontSize(32); confirmButton.setFontSize(32);
confirmButton.addClickCommands(s -> ifTopDialog( () -> { confirmButton.addClickCommands(s -> ifTopDialog( () -> {
app.getGameLogic().playSound(Sound.BUTTON); app.getGameLogic().playSound(Sound.BUTTON);
app.getGameLogic().send(new NotificationAnswer("UseJailCard"));
close(); close();
})); }));
// Schließen-Button // Schließen-Button
@ -99,6 +92,14 @@ public class GulagInfo extends Dialog {
7 7
); );
if(app.getGameLogic().getPlayerHandler().getPlayerById(app.getId()).getNumJailCard() == 0) {
confirmButton.setEnabled(false);
}
if(trys == 3) {
declineButton.setEnabled(false);
}
app.getGuiNode().attachChild(confirmTradeContainer); app.getGuiNode().attachChild(confirmTradeContainer);
} }

View File

@ -347,6 +347,10 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
notifyListeners(new PopUpEvent(msg.getKeyWord(), msg)); notifyListeners(new PopUpEvent(msg.getKeyWord(), msg));
} else if(msg.getKeyWord().equals("NoMoneyWarning")) { } else if(msg.getKeyWord().equals("NoMoneyWarning")) {
notifyListeners(new PopUpEvent("NoMoneyWarning", msg)); notifyListeners(new PopUpEvent("NoMoneyWarning", msg));
} else if (msg.getKeyWord().equals("jailpay")) {
notifyListeners(new PopUpEvent("jailpay", msg));
} else if (msg.getKeyWord().equals("jailtryagain")) {
notifyListeners(new PopUpEvent("jailtryagain", msg));
} }
} }
} }

View File

@ -140,6 +140,9 @@ public class Player implements FieldVisitor<Void>{
System.out.println("State: "+state.getClass().getName()); System.out.println("State: "+state.getClass().getName());
if(!(state instanceof JailState)) { if(!(state instanceof JailState)) {
state = new ActiveState(); state = new ActiveState();
} else {
String message = (((JailState)state).remainingAttempts <= 0) ? "jailpay" : "jailtryagain";
handler.getLogic().send(this, new NotificationMessage(message));
} }
} }
@ -439,7 +442,6 @@ public class Player implements FieldVisitor<Void>{
public void moveToJail() { public void moveToJail() {
setPosition(10); // Jail position on the board setPosition(10); // Jail position on the board
state = new JailState(); state = new JailState();
System.out.println("JAIL EVENT");
handler.getLogic().send(this, new JailEvent(true)); handler.getLogic().send(this, new JailEvent(true));
} }
@ -481,6 +483,7 @@ public class Player implements FieldVisitor<Void>{
return total; return total;
} }
// private static int c = 0;
/** /**
* Inner class for dice functionality in the game. * Inner class for dice functionality in the game.
* Rolls random dice values. * Rolls random dice values.
@ -495,7 +498,13 @@ public class Player implements FieldVisitor<Void>{
*/ */
private static int rollDice() { private static int rollDice() {
return random.nextInt(6) + 1; return random.nextInt(6) + 1;
// return 3;
// c++;
// if(c < 7) {
// return 3;
// } else {
// return (c%4)+1;
// }
} }
} }
@ -612,12 +621,6 @@ public class Player implements FieldVisitor<Void>{
state = new ActiveState(); state = new ActiveState();
} else { } else {
remainingAttempts--; remainingAttempts--;
if (remainingAttempts <= 0) {
handler.getLogic().send(Player.this, new NotificationMessage("jailpay"));
if(getOutOfJailCard == 0) payBail();
} else {
handler.getLogic().send(Player.this, new NotificationMessage("jailtryagain"));
}
} }
System.out.println("Feld:"+fieldID); System.out.println("Feld:"+fieldID);
return rollResult; return rollResult;

View File

@ -234,10 +234,10 @@ public class ServerGameLogic implements ClientInterpreter {
@Override @Override
public void received(RollDice msg, int from) { public void received(RollDice msg, int from) {
Player player = playerHandler.getPlayerById(from); Player player = playerHandler.getPlayerById(from);
if (player != null) { if (player != null && player == playerHandler.getPlayerAtIndex(0)) {
send(player, player.rollDice()); send(player, player.rollDice());
updateAllPlayers();
} }
updateAllPlayers();
} }
/** /**
@ -414,12 +414,11 @@ public class ServerGameLogic implements ClientInterpreter {
@Override @Override
public void received(NotificationAnswer msg, int from) { public void received(NotificationAnswer msg, int from) {
if(msg.getKeyword().equals("UseJailCard")) { if(msg.getA().equals("UseJailCard")) {
playerHandler.getPlayerById(from).useJailCard(); playerHandler.getPlayerById(from).useJailCard();
} else if (msg.getKeyword().equals("PayJail")) { } else if (msg.getA().equals("PayJail")) {
playerHandler.getPlayerById(from).payBail(); playerHandler.getPlayerById(from).payBail();
} }
updateAllPlayers(); updateAllPlayers();
} }
} }

View File

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

View File

@ -33,6 +33,7 @@ import pp.monopoly.message.client.AlterProperty;
import pp.monopoly.message.client.BuyPropertyResponse; import pp.monopoly.message.client.BuyPropertyResponse;
import pp.monopoly.message.client.ClientMessage; import pp.monopoly.message.client.ClientMessage;
import pp.monopoly.message.client.EndTurn; import pp.monopoly.message.client.EndTurn;
import pp.monopoly.message.client.NotificationAnswer;
import pp.monopoly.message.client.PlayerReady; import pp.monopoly.message.client.PlayerReady;
import pp.monopoly.message.client.RollDice; import pp.monopoly.message.client.RollDice;
import pp.monopoly.message.client.TradeOffer; import pp.monopoly.message.client.TradeOffer;
@ -175,6 +176,7 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
Serializer.registerClass(TradeReply.class); Serializer.registerClass(TradeReply.class);
Serializer.registerClass(TradeHandler.class); Serializer.registerClass(TradeHandler.class);
Serializer.registerClass(NotificationMessage.class); Serializer.registerClass(NotificationMessage.class);
Serializer.registerClass(NotificationAnswer.class);
Serializer.registerClass(JailEvent.class); Serializer.registerClass(JailEvent.class);
Serializer.registerClass(AlterProperty.class); Serializer.registerClass(AlterProperty.class);
Serializer.registerClass(GameOver.class); Serializer.registerClass(GameOver.class);
@ -188,6 +190,8 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
myServer.addMessageListener(this, TradeOffer.class); myServer.addMessageListener(this, TradeOffer.class);
myServer.addMessageListener(this, TradeResponse.class); myServer.addMessageListener(this, TradeResponse.class);
myServer.addMessageListener(this, ViewAssetsRequest.class); myServer.addMessageListener(this, ViewAssetsRequest.class);
myServer.addMessageListener(this, AlterProperty.class);
myServer.addMessageListener(this, NotificationAnswer.class);
myServer.addConnectionListener(this); myServer.addConnectionListener(this);
} }