mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2025-08-03 12:37:42 +02:00
jail logic complete
This commit is contained in:
@@ -347,6 +347,10 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
notifyListeners(new PopUpEvent(msg.getKeyWord(), msg));
|
||||
} else if(msg.getKeyWord().equals("NoMoneyWarning")) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -140,6 +140,9 @@ public class Player implements FieldVisitor<Void>{
|
||||
System.out.println("State: "+state.getClass().getName());
|
||||
if(!(state instanceof JailState)) {
|
||||
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() {
|
||||
setPosition(10); // Jail position on the board
|
||||
state = new JailState();
|
||||
System.out.println("JAIL EVENT");
|
||||
handler.getLogic().send(this, new JailEvent(true));
|
||||
}
|
||||
|
||||
@@ -481,6 +483,7 @@ public class Player implements FieldVisitor<Void>{
|
||||
return total;
|
||||
}
|
||||
|
||||
// private static int c = 0;
|
||||
/**
|
||||
* Inner class for dice functionality in the game.
|
||||
* Rolls random dice values.
|
||||
@@ -495,7 +498,13 @@ public class Player implements FieldVisitor<Void>{
|
||||
*/
|
||||
private static int rollDice() {
|
||||
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();
|
||||
} else {
|
||||
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);
|
||||
return rollResult;
|
||||
|
@@ -234,10 +234,10 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
@Override
|
||||
public void received(RollDice msg, int from) {
|
||||
Player player = playerHandler.getPlayerById(from);
|
||||
if (player != null) {
|
||||
if (player != null && player == playerHandler.getPlayerAtIndex(0)) {
|
||||
send(player, player.rollDice());
|
||||
updateAllPlayers();
|
||||
}
|
||||
updateAllPlayers();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -414,12 +414,11 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
|
||||
@Override
|
||||
public void received(NotificationAnswer msg, int from) {
|
||||
if(msg.getKeyword().equals("UseJailCard")) {
|
||||
if(msg.getA().equals("UseJailCard")) {
|
||||
playerHandler.getPlayerById(from).useJailCard();
|
||||
} else if (msg.getKeyword().equals("PayJail")) {
|
||||
} else if (msg.getA().equals("PayJail")) {
|
||||
playerHandler.getPlayerById(from).payBail();
|
||||
}
|
||||
|
||||
updateAllPlayers();
|
||||
}
|
||||
}
|
||||
|
@@ -5,16 +5,16 @@ import com.jme3.network.serializing.Serializable;
|
||||
@Serializable
|
||||
public class NotificationAnswer extends ClientMessage{
|
||||
|
||||
private String keyword;
|
||||
private String A;
|
||||
|
||||
private NotificationAnswer() {}
|
||||
|
||||
public NotificationAnswer(String keyword) {
|
||||
this.keyword = keyword;
|
||||
public NotificationAnswer(String A) {
|
||||
this.A = A;
|
||||
}
|
||||
|
||||
public String getKeyword() {
|
||||
return keyword;
|
||||
public String getA() {
|
||||
return A;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user