Merge remote-tracking branch 'origin/gui' into gui

This commit is contained in:
Yvonne Schmidt 2024-12-01 21:19:20 +01:00
commit 0c90d1f185
7 changed files with 63 additions and 11 deletions

View File

@ -292,6 +292,8 @@ public class TestWorld implements GameEventListener {
new TimeOut(app).open();
} else if(event.msg().equals("tradeRequest")) {
new ConfirmTrade(app).open();
} else if (event.msg().equals("goingToJail")) {
new Gulag(app).open();
}
}

View File

@ -261,10 +261,8 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
@Override
public void received(JailEvent msg) {
if (msg.isGoingToJail()) {
playSound(Sound.GULAG);
} else {
System.out.println("NO MORE JAIL");
notifyListeners(new PopUpEvent("goingToJail", msg));
}
}
@ -345,6 +343,8 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
public void received(NotificationMessage msg) {
if (msg.getKeyWord().equals("rent")) {
notifyListeners(new PopUpEvent("rent", msg));
} else if (msg.getKeyWord().equals("jailpay")) {
notifyListeners(new PopUpEvent(msg.getKeyWord(), msg));
}
}
}

View File

@ -494,6 +494,7 @@ public class Player implements FieldVisitor<Void>{
*/
private static int rollDice() {
return random.nextInt(6) + 1;
// return 3;
}
}
@ -612,6 +613,7 @@ public class Player implements FieldVisitor<Void>{
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"));
}
@ -622,23 +624,15 @@ public class Player implements FieldVisitor<Void>{
@Override
public void payBail() {
if (accountBalance >= 500) {
pay(500);
handler.getLogic().send(Player.this, new NotificationMessage(""));
state = new ActiveState();
} else {
handler.getLogic().send(Player.this, new NotificationMessage(""));
}
}
@Override
public void useJailCard() {
if (getOutOfJailCard > 0) {
removeJailCard();
handler.getLogic().send(Player.this, new NotificationMessage(""));
state = new ActiveState();
} else {
handler.getLogic().send(Player.this, new NotificationMessage(""));
}
}
}

View File

@ -14,11 +14,13 @@ import pp.monopoly.message.client.AlterProperty;
import pp.monopoly.message.client.BuyPropertyResponse;
import pp.monopoly.message.client.ClientInterpreter;
import pp.monopoly.message.client.EndTurn;
import pp.monopoly.message.client.NotificationAnswer;
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.GameOver;
import pp.monopoly.message.server.GameStart;
import pp.monopoly.message.server.NextPlayerTurn;
import pp.monopoly.message.server.PlayerStatusUpdate;
@ -181,8 +183,14 @@ public class ServerGameLogic implements ClientInterpreter {
send(next, new NextPlayerTurn());
send(next, new PlayerStatusUpdate(playerHandler));
send(player, new PlayerStatusUpdate(playerHandler));
} else {
send(player, new GameOver(false));
playerHandler.removePlayer(player);
}
}
if(playerHandler.getPlayers().size() == 1) {
send(playerHandler.getPlayerAtIndex(0), new GameOver(true));
}
updateAllPlayers();
}
@ -400,5 +408,18 @@ public class ServerGameLogic implements ClientInterpreter {
}
}
}
updateAllPlayers();
}
@Override
public void received(NotificationAnswer msg, int from) {
if(msg.getKeyword().equals("UseJailCard")) {
playerHandler.getPlayerById(from).useJailCard();
} else if (msg.getKeyword().equals("PayJail")) {
playerHandler.getPlayerById(from).payBail();
}
updateAllPlayers();
}
}

View File

@ -74,4 +74,12 @@ public interface ClientInterpreter {
* @param from the connection ID from which the message was received
*/
void received(AlterProperty msg, int from);
/**
* Processes a received NotificationAnswer.
*
* @param msg the NotificationAnswer to be processed
* @param from the connection ID from which the message was received
*/
void received(NotificationAnswer msg, int from);
}

View File

@ -0,0 +1,25 @@
package pp.monopoly.message.client;
import com.jme3.network.serializing.Serializable;
@Serializable
public class NotificationAnswer extends ClientMessage{
private String keyword;
private NotificationAnswer() {}
public NotificationAnswer(String keyword) {
this.keyword = keyword;
}
public String getKeyword() {
return keyword;
}
@Override
public void accept(ClientInterpreter interpreter, int from) {
interpreter.received(this, from);
}
}

View File

@ -41,6 +41,7 @@ import pp.monopoly.message.client.ViewAssetsRequest;
import pp.monopoly.message.server.BuyPropertyRequest;
import pp.monopoly.message.server.DiceResult;
import pp.monopoly.message.server.EventDrawCard;
import pp.monopoly.message.server.GameOver;
import pp.monopoly.message.server.GameStart;
import pp.monopoly.message.server.JailEvent;
import pp.monopoly.message.server.NextPlayerTurn;
@ -176,6 +177,7 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
Serializer.registerClass(NotificationMessage.class);
Serializer.registerClass(JailEvent.class);
Serializer.registerClass(AlterProperty.class);
Serializer.registerClass(GameOver.class);
}
private void registerListeners() {