mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2025-04-12 04:31:07 +02:00
Compare commits
4 Commits
5143e21ba6
...
9bf9e8406b
Author | SHA1 | Date | |
---|---|---|---|
|
9bf9e8406b | ||
|
6bd1ed6e3a | ||
|
0f6205fbc7 | ||
|
f2a6888fb2 |
@ -54,9 +54,8 @@ public class StartMenu extends Dialog {
|
||||
startButton.setTextHAlignment(HAlignment.Center); // Center the text horizontally
|
||||
|
||||
startButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||
this.close(); // Close the StartMenu dialog
|
||||
app.connect(); // Perform the connection logic
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
app.connect(); // Perform the connection logic
|
||||
}));
|
||||
centerMenu.addChild(startButton);
|
||||
|
||||
|
@ -25,6 +25,7 @@ import pp.monopoly.model.fields.GateField;
|
||||
import pp.monopoly.notification.EventCardEvent;
|
||||
import pp.monopoly.notification.GameEventListener;
|
||||
import pp.monopoly.notification.PopUpEvent;
|
||||
import pp.monopoly.notification.Sound;
|
||||
import pp.monopoly.notification.UpdatePlayerView;
|
||||
|
||||
/**
|
||||
@ -47,7 +48,7 @@ public class TestWorld implements GameEventListener {
|
||||
this.app = app;
|
||||
this.playerHandler = app.getGameLogic().getPlayerHandler(); // Hole den PlayerHandler
|
||||
app.getGameLogic().addListener(this);
|
||||
cameraController = new CameraController(app.getCamera(), playerHandler); // Übergebe PlayerHandler
|
||||
cameraController = new CameraController(app.getCamera()); // Übergebe PlayerHandler
|
||||
}
|
||||
|
||||
/**
|
||||
@ -110,7 +111,7 @@ public class TestWorld implements GameEventListener {
|
||||
Player player = playerHandler.getPlayers().get(i);
|
||||
try {
|
||||
com.jme3.scene.Spatial model = app.getAssetManager().loadModel(
|
||||
"Models/" + player.getFigure().getType() + "/" + player.getFigure().getType() + ".j3o"
|
||||
"models/" + player.getFigure().getType() + "/" + player.getFigure().getType() + ".j3o"
|
||||
);
|
||||
model.setLocalScale(0.5f);
|
||||
|
||||
@ -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")) {
|
||||
new WinnerPopUp(app).open();
|
||||
} else if (event.msg().equals("Looser")) {
|
||||
@ -304,9 +305,12 @@ public class TestWorld implements GameEventListener {
|
||||
timer.schedule(new TimerTask() {
|
||||
@Override
|
||||
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
|
||||
public void received(EventDrawCard msg) {
|
||||
playSound(Sound.EVENT_CARD);
|
||||
notifyListeners(new EventCardEvent(msg.getCardDescription()));
|
||||
}
|
||||
|
||||
@ -265,7 +264,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
|
||||
playSound(Sound.GULAG);
|
||||
} else {
|
||||
|
||||
System.out.println("NO MORE JAIL");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,9 +15,11 @@ import java.util.Set;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import pp.monopoly.game.client.WaitForTurnState;
|
||||
import pp.monopoly.message.server.BuyPropertyRequest;
|
||||
import pp.monopoly.message.server.DiceResult;
|
||||
import pp.monopoly.message.server.EventDrawCard;
|
||||
import pp.monopoly.message.server.JailEvent;
|
||||
import pp.monopoly.message.server.NextPlayerTurn;
|
||||
import pp.monopoly.message.server.NotificationMessage;
|
||||
import pp.monopoly.message.server.PlayerStatusUpdate;
|
||||
@ -50,8 +52,6 @@ public class Player implements FieldVisitor<Void>{
|
||||
private DiceResult rollResult;
|
||||
private transient final PlayerHandler handler;
|
||||
private transient PlayerState state = new WaitForTurnState();
|
||||
private int doubletscounter = 0;
|
||||
private boolean mayRollDice = false;
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
@ -136,15 +136,17 @@ public class Player implements FieldVisitor<Void>{
|
||||
public int getFieldID() {
|
||||
return fieldID;
|
||||
}
|
||||
|
||||
void setActive() {
|
||||
state = new ActiveState();
|
||||
doubletscounter = 0;
|
||||
mayRollDice = true;
|
||||
System.out.println("State: "+state.getClass().getName());
|
||||
if(!(state instanceof JailState)) {
|
||||
state = new ActiveState();
|
||||
}
|
||||
}
|
||||
|
||||
boolean finishTurn() {
|
||||
if(canFinishTurn()) {
|
||||
state = new WaitForTurnState();
|
||||
if (state instanceof ActiveState) state = new WaitForTurnState();
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
@ -177,7 +179,25 @@ public class Player implements FieldVisitor<Void>{
|
||||
* @return the new position
|
||||
*/
|
||||
public int setPosition(int position){
|
||||
if(position < 40 && position > 0) {
|
||||
if(position < 40 && position >= 0) {
|
||||
fieldID = position;
|
||||
figure.moveTo(fieldID);
|
||||
handler.getLogic().send(this, new PlayerStatusUpdate(handler));
|
||||
handler.getLogic().getBoardManager().getFieldAtIndex(fieldID).accept(this);
|
||||
}
|
||||
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 setPositionWithMoney(int position){
|
||||
if(position < 40 && position >= 0) {
|
||||
if(position < fieldID) {
|
||||
earnMoney(2000);
|
||||
}
|
||||
fieldID = position;
|
||||
figure.moveTo(fieldID);
|
||||
handler.getLogic().send(this, new PlayerStatusUpdate(handler));
|
||||
@ -301,7 +321,7 @@ public class Player implements FieldVisitor<Void>{
|
||||
@Override
|
||||
public Void visit(BuildingProperty field) {
|
||||
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){
|
||||
int rent = field.calcRent();
|
||||
field.getOwner().earnMoney(rent);
|
||||
@ -317,7 +337,7 @@ public class Player implements FieldVisitor<Void>{
|
||||
@Override
|
||||
public Void visit(FoodField field) {
|
||||
if(field.getOwner() == null) {
|
||||
getHandler().getLogic().send(this, new BuyPropertyRequest());
|
||||
if (field.getPrice() <= accountBalance) getHandler().getLogic().send(this, new BuyPropertyRequest());
|
||||
} else {
|
||||
int factor = 4;
|
||||
if (field.getOwner().getNumProp(field) == 2) {
|
||||
@ -337,7 +357,7 @@ public class Player implements FieldVisitor<Void>{
|
||||
@Override
|
||||
public Void visit(GateField field) {
|
||||
if(field.getOwner() == null) {
|
||||
getHandler().getLogic().send(this, new BuyPropertyRequest());
|
||||
if (field.getPrice() <= accountBalance) getHandler().getLogic().send(this, new BuyPropertyRequest());
|
||||
} else {
|
||||
int rent = field.calcRent() * field.getOwner().getNumProp(field);
|
||||
|
||||
@ -373,8 +393,7 @@ public class Player implements FieldVisitor<Void>{
|
||||
|
||||
@Override
|
||||
public Void visit(WacheField field) {
|
||||
setPosition(10);
|
||||
jail();
|
||||
moveToJail();
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -403,8 +422,14 @@ public class Player implements FieldVisitor<Void>{
|
||||
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();
|
||||
System.out.println("JAIL EVENT");
|
||||
handler.getLogic().send(this, new JailEvent(true));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -445,7 +470,7 @@ public class Player implements FieldVisitor<Void>{
|
||||
return total;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Inner class for dice functionality in the game.
|
||||
* Rolls random dice values.
|
||||
*/
|
||||
@ -462,36 +487,15 @@ public class Player implements FieldVisitor<Void>{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Rolls two dice, handles movement logic, and checks for doublets.
|
||||
*
|
||||
* @return the DiceResult of the roll
|
||||
*/
|
||||
DiceResult rollDice() {
|
||||
if (!mayRollDice) {
|
||||
throw new IllegalStateException("Player is not allowed to roll dice at this moment.");
|
||||
/**
|
||||
* Rolls two dice, handles movement logic, and checks for doublets.
|
||||
*
|
||||
* @return the DiceResult of the roll
|
||||
*/
|
||||
DiceResult rollDice() {
|
||||
return state.rollDice();
|
||||
}
|
||||
|
||||
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
|
||||
@ -521,12 +525,39 @@ DiceResult rollDice() {
|
||||
*/
|
||||
private class ActiveState implements PlayerState {
|
||||
|
||||
private int doubletscounter = 3;
|
||||
private boolean mayRollDice = true;
|
||||
|
||||
@Override
|
||||
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());
|
||||
rollResult = new DiceResult(roll.get(0), roll.get(1));
|
||||
System.out.println(rollResult.calcTotal());
|
||||
move(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());
|
||||
}
|
||||
|
||||
return rollResult;
|
||||
}
|
||||
|
||||
@ -547,36 +578,56 @@ DiceResult rollDice() {
|
||||
* Set when in Gulag
|
||||
*/
|
||||
private class JailState implements PlayerState {
|
||||
|
||||
private int DoubletsCounter = 3;
|
||||
private int remainingAttempts = 3;
|
||||
|
||||
@Override
|
||||
public DiceResult rollDice() {
|
||||
if (remainingAttempts <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<Integer> roll = List.of(Dice.rollDice(), Dice.rollDice());
|
||||
rollResult = new DiceResult(roll.get(0), roll.get(1));
|
||||
if (rollResult.isDoublets()) {
|
||||
state = new ActiveState();
|
||||
} else if (DoubletsCounter == 0) {
|
||||
handler.getLogic().send(Player.this, new DiceResult (rollResult.getRollResult().get(0), rollResult.getRollResult().get(1)));
|
||||
|
||||
if (rollResult.isDoublets()) {
|
||||
handler.getLogic().send(Player.this, new JailEvent(false));
|
||||
state = new ActiveState();
|
||||
} 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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void payBail() {
|
||||
pay(500);
|
||||
state = new ActiveState();
|
||||
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() {
|
||||
getOutOfJailCard--;
|
||||
state = new ActiveState();
|
||||
if (getOutOfJailCard > 0) {
|
||||
removeJailCard();
|
||||
handler.getLogic().send(Player.this, new NotificationMessage(""));
|
||||
state = new ActiveState();
|
||||
} else {
|
||||
handler.getLogic().send(Player.this, new NotificationMessage(""));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class WaitForTurnState implements PlayerState {
|
||||
|
||||
@Override
|
||||
|
@ -189,7 +189,7 @@ public class DeckHelper{
|
||||
}
|
||||
|
||||
private void spoparty(Player player) {
|
||||
player.setPosition(14);
|
||||
player.setPositionWithMoney(14);
|
||||
}
|
||||
|
||||
private void gulakFrei(Player player) {
|
||||
@ -197,11 +197,11 @@ public class DeckHelper{
|
||||
}
|
||||
|
||||
private void dienstfuehrerschein(Player player) {
|
||||
player.setPosition(20);
|
||||
player.setPositionWithMoney(20);
|
||||
}
|
||||
|
||||
private void pubquiz(Player player) {
|
||||
player.setPosition(39);
|
||||
player.setPositionWithMoney(39);
|
||||
}
|
||||
|
||||
private void namensschildTruppenkueche(Player player) {
|
||||
@ -221,7 +221,7 @@ public class DeckHelper{
|
||||
}
|
||||
|
||||
private void naechstesMonatsgehalt(Player player) {
|
||||
player.setPosition(0);
|
||||
player.setPositionWithMoney(0);
|
||||
}
|
||||
|
||||
private void antretenVerschlafen(Player player) {
|
||||
@ -237,21 +237,19 @@ public class DeckHelper{
|
||||
}
|
||||
|
||||
private void dienstsportGym(Player player) {
|
||||
player.setPosition(1);
|
||||
player.setPositionWithMoney(1);
|
||||
}
|
||||
|
||||
private void schimmelGulak(Player player) {
|
||||
player.setPosition(10);
|
||||
player.jail();
|
||||
player.moveToJail();
|
||||
}
|
||||
|
||||
private void partynachtGulak(Player player) {
|
||||
player.setPosition(10);
|
||||
player.jail();
|
||||
player.moveToJail();
|
||||
}
|
||||
|
||||
private void jahresabschlussantreten(Player player) {
|
||||
player.setPosition(17);
|
||||
player.setPositionWithMoney(17);
|
||||
}
|
||||
|
||||
private void verkaufenVersicherungen(Player player) {
|
||||
|
@ -41,6 +41,7 @@ import pp.monopoly.message.server.BuyPropertyRequest;
|
||||
import pp.monopoly.message.server.DiceResult;
|
||||
import pp.monopoly.message.server.EventDrawCard;
|
||||
import pp.monopoly.message.server.GameStart;
|
||||
import pp.monopoly.message.server.JailEvent;
|
||||
import pp.monopoly.message.server.NextPlayerTurn;
|
||||
import pp.monopoly.message.server.NotificationMessage;
|
||||
import pp.monopoly.message.server.PlayerStatusUpdate;
|
||||
@ -172,6 +173,7 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
|
||||
Serializer.registerClass(TradeReply.class);
|
||||
Serializer.registerClass(TradeHandler.class);
|
||||
Serializer.registerClass(NotificationMessage.class);
|
||||
Serializer.registerClass(JailEvent.class);
|
||||
}
|
||||
|
||||
private void registerListeners() {
|
||||
|
Loading…
Reference in New Issue
Block a user