mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2024-11-24 21:39:44 +01:00
added playerState changes
This commit is contained in:
parent
7d2c85f617
commit
d582c59a7d
@ -14,7 +14,6 @@ import pp.monopoly.message.server.DiceResult;
|
||||
import pp.monopoly.model.FieldVisitor;
|
||||
import pp.monopoly.model.Figure;
|
||||
import pp.monopoly.model.card.Card;
|
||||
import pp.monopoly.model.card.DeckHelper;
|
||||
import pp.monopoly.model.fields.BuildingProperty;
|
||||
import pp.monopoly.model.fields.EventField;
|
||||
import pp.monopoly.model.fields.FineField;
|
||||
@ -112,6 +111,21 @@ public class Player implements FieldVisitor<Void>{
|
||||
public int getFieldID() {
|
||||
return fieldID;
|
||||
}
|
||||
void setActive() {
|
||||
state = new ActiveState();
|
||||
}
|
||||
|
||||
boolean finishTurn() {
|
||||
if(canFinishTurn()) {
|
||||
state = new WaitForTurnState();
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
boolean canFinishTurn() {
|
||||
return accountBalance >= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves by the specified amount of steps
|
||||
@ -489,47 +503,19 @@ public class Player implements FieldVisitor<Void>{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class BankruptState implements PlayerState {
|
||||
|
||||
@Override
|
||||
public DiceResult rollDice() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'rollDice'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void payBail() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'payBail'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void useJailCard() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'useJailCard'");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class WaitForTurnState implements PlayerState {
|
||||
|
||||
@Override
|
||||
public DiceResult rollDice() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'rollDice'");
|
||||
throw new UnsupportedOperationException("not allowed");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void payBail() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'payBail'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void useJailCard() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'useJailCard'");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -165,10 +165,15 @@ public class PlayerHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Arranges the players turns in a random order
|
||||
* Arranges the players turns in a random order.
|
||||
* Shuffles the players and sets their state to WaitForNextTurn, the first one will be active
|
||||
*/
|
||||
void randomOrder() {
|
||||
Collections.shuffle(players);
|
||||
for (Player player : players) {
|
||||
player.finishTurn();
|
||||
}
|
||||
players.get(0).setActive();
|
||||
}
|
||||
|
||||
void setStartBalance(int amount) {
|
||||
|
@ -171,11 +171,14 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
public void received(EndTurn msg, int from) {
|
||||
Player player = playerHandler.getPlayerById(from);
|
||||
if (player != null && state == ServerState.INGAME) {
|
||||
if (player.finishTurn()) {
|
||||
LOGGER.log(Level.DEBUG, "Ending turn for player {0}", player.getName());
|
||||
Player next = playerHandler.nextPlayer();
|
||||
next.setActive();
|
||||
send(next, new NextPlayerTurn(next));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a PlayerReady message, marking the player as ready.
|
||||
|
Loading…
Reference in New Issue
Block a user