mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2025-01-19 06:06:15 +01:00
fixed JailState
This commit is contained in:
parent
5143e21ba6
commit
f2a6888fb2
@ -25,6 +25,7 @@ import pp.monopoly.model.fields.GateField;
|
|||||||
import pp.monopoly.notification.EventCardEvent;
|
import pp.monopoly.notification.EventCardEvent;
|
||||||
import pp.monopoly.notification.GameEventListener;
|
import pp.monopoly.notification.GameEventListener;
|
||||||
import pp.monopoly.notification.PopUpEvent;
|
import pp.monopoly.notification.PopUpEvent;
|
||||||
|
import pp.monopoly.notification.Sound;
|
||||||
import pp.monopoly.notification.UpdatePlayerView;
|
import pp.monopoly.notification.UpdatePlayerView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -47,7 +48,7 @@ public class TestWorld implements GameEventListener {
|
|||||||
this.app = app;
|
this.app = app;
|
||||||
this.playerHandler = app.getGameLogic().getPlayerHandler(); // Hole den PlayerHandler
|
this.playerHandler = app.getGameLogic().getPlayerHandler(); // Hole den PlayerHandler
|
||||||
app.getGameLogic().addListener(this);
|
app.getGameLogic().addListener(this);
|
||||||
cameraController = new CameraController(app.getCamera(), playerHandler); // Übergebe PlayerHandler
|
cameraController = new CameraController(app.getCamera()); // Übergebe PlayerHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -288,7 +289,7 @@ public class TestWorld implements GameEventListener {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, 5000); // Verzögerung in Millisekunden
|
}, 2500); // Verzögerung in Millisekunden
|
||||||
} else if (event.msg().equals("Winner")) {
|
} else if (event.msg().equals("Winner")) {
|
||||||
new WinnerPopUp(app).open();
|
new WinnerPopUp(app).open();
|
||||||
} else if (event.msg().equals("Looser")) {
|
} else if (event.msg().equals("Looser")) {
|
||||||
@ -304,9 +305,12 @@ public class TestWorld implements GameEventListener {
|
|||||||
timer.schedule(new TimerTask() {
|
timer.schedule(new TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
app.enqueue(() -> new EventCardPopup(app, event.description()).open());
|
app.enqueue(() -> {
|
||||||
|
app.getGameLogic().playSound(Sound.EVENT_CARD);
|
||||||
|
new EventCardPopup(app, event.description()).open();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}, 5000); // 5 Sekunden Verzögerung für Event-Popups
|
}, 2500); // 5 Sekunden Verzögerung für Event-Popups
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -222,7 +222,6 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void received(EventDrawCard msg) {
|
public void received(EventDrawCard msg) {
|
||||||
playSound(Sound.EVENT_CARD);
|
|
||||||
notifyListeners(new EventCardEvent(msg.getCardDescription()));
|
notifyListeners(new EventCardEvent(msg.getCardDescription()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -265,7 +264,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
|||||||
|
|
||||||
playSound(Sound.GULAG);
|
playSound(Sound.GULAG);
|
||||||
} else {
|
} else {
|
||||||
|
System.out.println("NO MORE JAIL");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,9 +15,11 @@ import java.util.Set;
|
|||||||
|
|
||||||
import com.jme3.network.serializing.Serializable;
|
import com.jme3.network.serializing.Serializable;
|
||||||
|
|
||||||
|
import pp.monopoly.game.client.WaitForTurnState;
|
||||||
import pp.monopoly.message.server.BuyPropertyRequest;
|
import pp.monopoly.message.server.BuyPropertyRequest;
|
||||||
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.JailEvent;
|
||||||
import pp.monopoly.message.server.NextPlayerTurn;
|
import pp.monopoly.message.server.NextPlayerTurn;
|
||||||
import pp.monopoly.message.server.NotificationMessage;
|
import pp.monopoly.message.server.NotificationMessage;
|
||||||
import pp.monopoly.message.server.PlayerStatusUpdate;
|
import pp.monopoly.message.server.PlayerStatusUpdate;
|
||||||
@ -50,8 +52,6 @@ public class Player implements FieldVisitor<Void>{
|
|||||||
private DiceResult rollResult;
|
private DiceResult rollResult;
|
||||||
private transient final PlayerHandler handler;
|
private transient final PlayerHandler handler;
|
||||||
private transient PlayerState state = new WaitForTurnState();
|
private transient PlayerState state = new WaitForTurnState();
|
||||||
private int doubletscounter = 0;
|
|
||||||
private boolean mayRollDice = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor for serialization purposes.
|
* Default constructor for serialization purposes.
|
||||||
@ -136,15 +136,17 @@ public class Player implements FieldVisitor<Void>{
|
|||||||
public int getFieldID() {
|
public int getFieldID() {
|
||||||
return fieldID;
|
return fieldID;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setActive() {
|
void setActive() {
|
||||||
|
System.out.println("State: "+state.getClass().getName());
|
||||||
|
if(!(state instanceof JailState)) {
|
||||||
state = new ActiveState();
|
state = new ActiveState();
|
||||||
doubletscounter = 0;
|
}
|
||||||
mayRollDice = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean finishTurn() {
|
boolean finishTurn() {
|
||||||
if(canFinishTurn()) {
|
if(canFinishTurn()) {
|
||||||
state = new WaitForTurnState();
|
if (state instanceof ActiveState) state = new WaitForTurnState();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else return false;
|
else return false;
|
||||||
@ -177,7 +179,7 @@ public class Player implements FieldVisitor<Void>{
|
|||||||
* @return the new position
|
* @return the new position
|
||||||
*/
|
*/
|
||||||
public int setPosition(int position){
|
public int setPosition(int position){
|
||||||
if(position < 40 && position > 0) {
|
if(position < 40 && position >= 0) {
|
||||||
fieldID = position;
|
fieldID = position;
|
||||||
figure.moveTo(fieldID);
|
figure.moveTo(fieldID);
|
||||||
handler.getLogic().send(this, new PlayerStatusUpdate(handler));
|
handler.getLogic().send(this, new PlayerStatusUpdate(handler));
|
||||||
@ -301,7 +303,7 @@ public class Player implements FieldVisitor<Void>{
|
|||||||
@Override
|
@Override
|
||||||
public Void visit(BuildingProperty field) {
|
public Void visit(BuildingProperty field) {
|
||||||
if(field.getOwner() == null) {
|
if(field.getOwner() == null) {
|
||||||
getHandler().getLogic().send(this, new BuyPropertyRequest());
|
if (field.getPrice() <= accountBalance) getHandler().getLogic().send(this, new BuyPropertyRequest());
|
||||||
} else if (field.getOwner() != this){
|
} else if (field.getOwner() != this){
|
||||||
int rent = field.calcRent();
|
int rent = field.calcRent();
|
||||||
field.getOwner().earnMoney(rent);
|
field.getOwner().earnMoney(rent);
|
||||||
@ -317,7 +319,7 @@ public class Player implements FieldVisitor<Void>{
|
|||||||
@Override
|
@Override
|
||||||
public Void visit(FoodField field) {
|
public Void visit(FoodField field) {
|
||||||
if(field.getOwner() == null) {
|
if(field.getOwner() == null) {
|
||||||
getHandler().getLogic().send(this, new BuyPropertyRequest());
|
if (field.getPrice() <= accountBalance) getHandler().getLogic().send(this, new BuyPropertyRequest());
|
||||||
} else {
|
} else {
|
||||||
int factor = 4;
|
int factor = 4;
|
||||||
if (field.getOwner().getNumProp(field) == 2) {
|
if (field.getOwner().getNumProp(field) == 2) {
|
||||||
@ -337,7 +339,7 @@ public class Player implements FieldVisitor<Void>{
|
|||||||
@Override
|
@Override
|
||||||
public Void visit(GateField field) {
|
public Void visit(GateField field) {
|
||||||
if(field.getOwner() == null) {
|
if(field.getOwner() == null) {
|
||||||
getHandler().getLogic().send(this, new BuyPropertyRequest());
|
if (field.getPrice() <= accountBalance) getHandler().getLogic().send(this, new BuyPropertyRequest());
|
||||||
} else {
|
} else {
|
||||||
int rent = field.calcRent() * field.getOwner().getNumProp(field);
|
int rent = field.calcRent() * field.getOwner().getNumProp(field);
|
||||||
|
|
||||||
@ -373,8 +375,7 @@ public class Player implements FieldVisitor<Void>{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Void visit(WacheField field) {
|
public Void visit(WacheField field) {
|
||||||
setPosition(10);
|
moveToJail();
|
||||||
jail();
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -403,8 +404,14 @@ public class Player implements FieldVisitor<Void>{
|
|||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void jail() {
|
/**
|
||||||
|
* Sends the player to jail by setting position and state.
|
||||||
|
*/
|
||||||
|
public void moveToJail() {
|
||||||
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -462,36 +469,15 @@ public class Player implements FieldVisitor<Void>{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rolls two dice, handles movement logic, and checks for doublets.
|
* Rolls two dice, handles movement logic, and checks for doublets.
|
||||||
*
|
*
|
||||||
* @return the DiceResult of the roll
|
* @return the DiceResult of the roll
|
||||||
*/
|
*/
|
||||||
DiceResult rollDice() {
|
DiceResult rollDice() {
|
||||||
if (!mayRollDice) {
|
return state.rollDice();
|
||||||
throw new IllegalStateException("Player is not allowed to roll dice at this moment.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rollResult = state.rollDice();
|
|
||||||
mayRollDice = false;
|
|
||||||
|
|
||||||
if (rollResult.isDoublets()) {
|
|
||||||
doubletscounter++;
|
|
||||||
mayRollDice = true; // Allow another roll for doublets
|
|
||||||
|
|
||||||
if (doubletscounter >= 3) {
|
|
||||||
setPosition(10); // Send to jail on third doublet
|
|
||||||
doubletscounter = 0; // Reset doublets counter
|
|
||||||
} else {
|
|
||||||
getHandler().getLogic().send(this, new NextPlayerTurn());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
doubletscounter = 0; // Reset counter if no doublets
|
|
||||||
}
|
|
||||||
|
|
||||||
return rollResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A interface representing the PlayerStates
|
* A interface representing the PlayerStates
|
||||||
@ -521,12 +507,39 @@ DiceResult rollDice() {
|
|||||||
*/
|
*/
|
||||||
private class ActiveState implements PlayerState {
|
private class ActiveState implements PlayerState {
|
||||||
|
|
||||||
|
private int doubletscounter = 3;
|
||||||
|
private boolean mayRollDice = true;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DiceResult rollDice() {
|
public DiceResult rollDice() {
|
||||||
|
|
||||||
|
if (!mayRollDice) {
|
||||||
|
throw new IllegalStateException("Player is not allowed to roll dice at this moment.");
|
||||||
|
}
|
||||||
|
|
||||||
List<Integer> roll = List.of(Dice.rollDice(), Dice.rollDice());
|
List<Integer> roll = List.of(Dice.rollDice(), Dice.rollDice());
|
||||||
rollResult = new DiceResult(roll.get(0), roll.get(1));
|
rollResult = new DiceResult(roll.get(0), roll.get(1));
|
||||||
System.out.println(rollResult.calcTotal());
|
mayRollDice = false;
|
||||||
|
|
||||||
|
// Check for doublets
|
||||||
|
if (rollResult.isDoublets()) {
|
||||||
|
doubletscounter--; // Decrement doublets counter
|
||||||
|
|
||||||
|
if (doubletscounter <= 0) {
|
||||||
|
// Player rolls third doublet -> move to jail
|
||||||
|
moveToJail();
|
||||||
|
doubletscounter = 3; // Reset doublets counter
|
||||||
|
} else {
|
||||||
|
// Player rolls doublets but can roll again
|
||||||
|
mayRollDice = true;
|
||||||
|
move(rollResult.calcTotal()); // Move player for this roll
|
||||||
|
getHandler().getLogic().send(Player.this, new NextPlayerTurn());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// No doublets -> move normally and reset doublets counter
|
||||||
move(rollResult.calcTotal());
|
move(rollResult.calcTotal());
|
||||||
|
}
|
||||||
|
|
||||||
return rollResult;
|
return rollResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -547,36 +560,56 @@ DiceResult rollDice() {
|
|||||||
* Set when in Gulag
|
* Set when in Gulag
|
||||||
*/
|
*/
|
||||||
private class JailState implements PlayerState {
|
private class JailState implements PlayerState {
|
||||||
|
private int remainingAttempts = 3;
|
||||||
private int DoubletsCounter = 3;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DiceResult rollDice() {
|
public DiceResult rollDice() {
|
||||||
|
if (remainingAttempts <= 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
List<Integer> roll = List.of(Dice.rollDice(), Dice.rollDice());
|
List<Integer> roll = List.of(Dice.rollDice(), Dice.rollDice());
|
||||||
rollResult = new DiceResult(roll.get(0), roll.get(1));
|
rollResult = new DiceResult(roll.get(0), roll.get(1));
|
||||||
if (rollResult.isDoublets()) {
|
handler.getLogic().send(Player.this, new DiceResult (rollResult.getRollResult().get(0), rollResult.getRollResult().get(1)));
|
||||||
state = new ActiveState();
|
|
||||||
} else if (DoubletsCounter == 0) {
|
|
||||||
|
|
||||||
|
if (rollResult.isDoublets()) {
|
||||||
|
handler.getLogic().send(Player.this, new JailEvent(false));
|
||||||
|
state = new ActiveState();
|
||||||
} else {
|
} else {
|
||||||
DoubletsCounter--;
|
remainingAttempts--;
|
||||||
|
if (remainingAttempts <= 0) {
|
||||||
|
handler.getLogic().send(Player.this, new NotificationMessage("jailpay"));
|
||||||
|
} else {
|
||||||
|
handler.getLogic().send(Player.this, new NotificationMessage("jailtryagain"));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
System.out.println("Feld:"+fieldID);
|
||||||
return rollResult;
|
return rollResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void payBail() {
|
public void payBail() {
|
||||||
|
if (accountBalance >= 500) {
|
||||||
pay(500);
|
pay(500);
|
||||||
|
handler.getLogic().send(Player.this, new NotificationMessage(""));
|
||||||
state = new ActiveState();
|
state = new ActiveState();
|
||||||
|
} else {
|
||||||
|
handler.getLogic().send(Player.this, new NotificationMessage(""));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void useJailCard() {
|
public void useJailCard() {
|
||||||
getOutOfJailCard--;
|
if (getOutOfJailCard > 0) {
|
||||||
|
removeJailCard();
|
||||||
|
handler.getLogic().send(Player.this, new NotificationMessage(""));
|
||||||
state = new ActiveState();
|
state = new ActiveState();
|
||||||
|
} else {
|
||||||
|
handler.getLogic().send(Player.this, new NotificationMessage(""));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
private class WaitForTurnState implements PlayerState {
|
private class WaitForTurnState implements PlayerState {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -241,13 +241,11 @@ public class DeckHelper{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void schimmelGulak(Player player) {
|
private void schimmelGulak(Player player) {
|
||||||
player.setPosition(10);
|
player.moveToJail();
|
||||||
player.jail();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void partynachtGulak(Player player) {
|
private void partynachtGulak(Player player) {
|
||||||
player.setPosition(10);
|
player.moveToJail();
|
||||||
player.jail();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void jahresabschlussantreten(Player player) {
|
private void jahresabschlussantreten(Player player) {
|
||||||
|
@ -41,6 +41,7 @@ import pp.monopoly.message.server.BuyPropertyRequest;
|
|||||||
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.GameStart;
|
import pp.monopoly.message.server.GameStart;
|
||||||
|
import pp.monopoly.message.server.JailEvent;
|
||||||
import pp.monopoly.message.server.NextPlayerTurn;
|
import pp.monopoly.message.server.NextPlayerTurn;
|
||||||
import pp.monopoly.message.server.NotificationMessage;
|
import pp.monopoly.message.server.NotificationMessage;
|
||||||
import pp.monopoly.message.server.PlayerStatusUpdate;
|
import pp.monopoly.message.server.PlayerStatusUpdate;
|
||||||
@ -172,6 +173,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(JailEvent.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerListeners() {
|
private void registerListeners() {
|
||||||
|
Loading…
Reference in New Issue
Block a user