mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2024-11-24 22:49: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.FieldVisitor;
|
||||||
import pp.monopoly.model.Figure;
|
import pp.monopoly.model.Figure;
|
||||||
import pp.monopoly.model.card.Card;
|
import pp.monopoly.model.card.Card;
|
||||||
import pp.monopoly.model.card.DeckHelper;
|
|
||||||
import pp.monopoly.model.fields.BuildingProperty;
|
import pp.monopoly.model.fields.BuildingProperty;
|
||||||
import pp.monopoly.model.fields.EventField;
|
import pp.monopoly.model.fields.EventField;
|
||||||
import pp.monopoly.model.fields.FineField;
|
import pp.monopoly.model.fields.FineField;
|
||||||
@ -112,6 +111,21 @@ public class Player implements FieldVisitor<Void>{
|
|||||||
public int getFieldID() {
|
public int getFieldID() {
|
||||||
return fieldID;
|
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
|
* 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 {
|
private class WaitForTurnState implements PlayerState {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DiceResult rollDice() {
|
public DiceResult rollDice() {
|
||||||
// TODO Auto-generated method stub
|
throw new UnsupportedOperationException("not allowed");
|
||||||
throw new UnsupportedOperationException("Unimplemented method 'rollDice'");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void payBail() {
|
public void payBail() {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
throw new UnsupportedOperationException("Unimplemented method 'payBail'");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void useJailCard() {
|
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() {
|
void randomOrder() {
|
||||||
Collections.shuffle(players);
|
Collections.shuffle(players);
|
||||||
|
for (Player player : players) {
|
||||||
|
player.finishTurn();
|
||||||
|
}
|
||||||
|
players.get(0).setActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setStartBalance(int amount) {
|
void setStartBalance(int amount) {
|
||||||
|
@ -171,9 +171,12 @@ public class ServerGameLogic implements ClientInterpreter {
|
|||||||
public void received(EndTurn msg, int from) {
|
public void received(EndTurn msg, int from) {
|
||||||
Player player = playerHandler.getPlayerById(from);
|
Player player = playerHandler.getPlayerById(from);
|
||||||
if (player != null && state == ServerState.INGAME) {
|
if (player != null && state == ServerState.INGAME) {
|
||||||
LOGGER.log(Level.DEBUG, "Ending turn for player {0}", player.getName());
|
if (player.finishTurn()) {
|
||||||
Player next = playerHandler.nextPlayer();
|
LOGGER.log(Level.DEBUG, "Ending turn for player {0}", player.getName());
|
||||||
send(next, new NextPlayerTurn(next));
|
Player next = playerHandler.nextPlayer();
|
||||||
|
next.setActive();
|
||||||
|
send(next, new NextPlayerTurn(next));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user