merge Development into test #27
@@ -3,15 +3,9 @@
|
|||||||
import pp.mdga.client.ClientGameLogic;
|
import pp.mdga.client.ClientGameLogic;
|
||||||
import pp.mdga.client.ClientState;
|
import pp.mdga.client.ClientState;
|
||||||
import pp.mdga.client.gameState.TurnState;
|
import pp.mdga.client.gameState.TurnState;
|
||||||
import pp.mdga.game.BonusCard;
|
|
||||||
import pp.mdga.game.Piece;
|
|
||||||
import pp.mdga.game.ShieldState;
|
|
||||||
import pp.mdga.message.client.AnimationEndMessage;
|
import pp.mdga.message.client.AnimationEndMessage;
|
||||||
import pp.mdga.message.server.PlayCardMessage;
|
import pp.mdga.message.server.PlayCardMessage;
|
||||||
import pp.mdga.notification.PlayCardNotification;
|
import pp.mdga.notification.PlayCardNotification;
|
||||||
import pp.mdga.notification.ShieldActiveNotification;
|
|
||||||
import pp.mdga.notification.ShieldSuppressedNotification;
|
|
||||||
import pp.mdga.notification.SwapPieceNotification;
|
|
||||||
|
|
||||||
public class PlayPowerCardState extends TurnStates {
|
public class PlayPowerCardState extends TurnStates {
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
package pp.mdga.server;
|
|
||||||
|
|
||||||
import pp.mdga.server.automaton.GameState;
|
|
||||||
|
|
||||||
public class DetermineStartPlayerState extends GameState {
|
|
||||||
public DetermineStartPlayerState(ServerGameLogic logic) {
|
|
||||||
super(logic);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package pp.mdga.server;
|
|
||||||
|
|
||||||
public class FirstRollStateState extends RollDiceState {
|
|
||||||
public FirstRollStateState(ServerGameLogic logic) {
|
|
||||||
super(logic);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package pp.mdga.server;
|
|
||||||
|
|
||||||
public class MovePieceState extends TurnState {
|
|
||||||
public MovePieceState(ServerGameLogic logic) {
|
|
||||||
super(logic);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package pp.mdga.server;
|
|
||||||
|
|
||||||
public class NoPieceState extends ChoosePieceState {
|
|
||||||
public NoPieceState(ServerGameLogic logic) {
|
|
||||||
super(logic);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package pp.mdga.server;
|
|
||||||
|
|
||||||
public class NoTurnState extends ChoosePieceState {
|
|
||||||
public NoTurnState(ServerGameLogic logic) {
|
|
||||||
super(logic);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package pp.mdga.server;
|
|
||||||
|
|
||||||
public class PowerCardState extends TurnState {
|
|
||||||
public PowerCardState(ServerGameLogic logic) {
|
|
||||||
super(logic);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package pp.mdga.server;
|
|
||||||
|
|
||||||
public class RollDiceState extends TurnState {
|
|
||||||
public RollDiceState(ServerGameLogic logic) {
|
|
||||||
super(logic);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package pp.mdga.server;
|
|
||||||
|
|
||||||
public class SecondRollState extends RollDiceState {
|
|
||||||
public SecondRollState(ServerGameLogic logic) {
|
|
||||||
super(logic);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package pp.mdga.server;
|
|
||||||
|
|
||||||
public class SelectPieceState extends ChoosePieceState {
|
|
||||||
public SelectPieceState(ServerGameLogic logic) {
|
|
||||||
super(logic);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package pp.mdga.server;
|
|
||||||
|
|
||||||
public class StartPieceState extends ChoosePieceState {
|
|
||||||
public StartPieceState(ServerGameLogic logic) {
|
|
||||||
super(logic);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package pp.mdga.server;
|
|
||||||
|
|
||||||
public class ThirdRollState extends RollDiceState {
|
|
||||||
public ThirdRollState(ServerGameLogic logic) {
|
|
||||||
super(logic);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package pp.mdga.server;
|
|
||||||
|
|
||||||
import pp.mdga.server.automaton.GameState;
|
|
||||||
|
|
||||||
public class TurnState extends GameState {
|
|
||||||
public TurnState(ServerGameLogic logic) {
|
|
||||||
super(logic);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package pp.mdga.server;
|
|
||||||
|
|
||||||
public class WaitingPieceState extends ChoosePieceState {
|
|
||||||
public WaitingPieceState(ServerGameLogic logic) {
|
|
||||||
super(logic);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -8,6 +8,8 @@
|
|||||||
import pp.mdga.server.automaton.game.AnimationState;
|
import pp.mdga.server.automaton.game.AnimationState;
|
||||||
import pp.mdga.server.automaton.game.DetermineStartPlayerState;
|
import pp.mdga.server.automaton.game.DetermineStartPlayerState;
|
||||||
import pp.mdga.server.ServerGameLogic;
|
import pp.mdga.server.ServerGameLogic;
|
||||||
|
import pp.mdga.server.automaton.game.GameAutomatonState;
|
||||||
|
import pp.mdga.server.automaton.game.TurnState;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class represents the game state of this application.
|
* This class represents the game state of this application.
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package pp.mdga.server.automaton.game;
|
||||||
|
|
||||||
|
import pp.mdga.message.client.AnimationEndMessage;
|
||||||
|
import pp.mdga.message.server.DiceNowMessage;
|
||||||
|
import pp.mdga.server.ServerGameLogic;
|
||||||
|
import pp.mdga.server.automaton.GameState;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class represents the animation state of the game state.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class AnimationState extends GameAutomatonState {
|
||||||
|
/**
|
||||||
|
* Constructs a server state of the specified game logic.
|
||||||
|
*
|
||||||
|
* @param gameAutomaton as the automaton of the game state as a GameState object.
|
||||||
|
* @param logic the game logic
|
||||||
|
*/
|
||||||
|
public AnimationState(GameState gameAutomaton, ServerGameLogic logic) {
|
||||||
|
super(gameAutomaton, logic);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enter() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void exit() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method will be called whenever the server received an AnimationEndMessage message.
|
||||||
|
* It will also get the client id of the player who send this message.
|
||||||
|
*
|
||||||
|
* @param msg as the message which was sent by the player as a AnimationEndMessage object.
|
||||||
|
* @param from as the client id of the player as an Integer.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void received(AnimationEndMessage msg, int from) {
|
||||||
|
this.logic.getServerSender().send(from, new DiceNowMessage());
|
||||||
|
this.gameAutomaton.setCurrentState(this.gameAutomaton.getTurnState());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
package pp.mdga.server.automaton.game;
|
||||||
|
|
||||||
|
import pp.mdga.game.Player;
|
||||||
|
import pp.mdga.message.client.RequestDieMessage;
|
||||||
|
import pp.mdga.message.server.DieMessage;
|
||||||
|
import pp.mdga.server.ServerGameLogic;
|
||||||
|
import pp.mdga.server.automaton.GameState;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class DetermineStartPlayerState extends GameAutomatonState {
|
||||||
|
/**
|
||||||
|
* Create DetermineStartPlayerState attributes.
|
||||||
|
*/
|
||||||
|
private Map<Player, Integer> diceResults = new HashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a server state of the specified game logic.
|
||||||
|
*
|
||||||
|
* @param gameAutomaton as the automaton of the game state as a GameState object.
|
||||||
|
* @param logic the game logic
|
||||||
|
*/
|
||||||
|
public DetermineStartPlayerState(GameState gameAutomaton, ServerGameLogic logic) {
|
||||||
|
super(gameAutomaton, logic);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enter() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void exit() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method will be called whenever the server received a RequestDieMessage message.
|
||||||
|
* It will also get the client id of the player who send this message.
|
||||||
|
*
|
||||||
|
* @param msg as the message which was sent by the player as a RequestDieMessage object.
|
||||||
|
* @param from as the client id of the player as an Integer.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void received(RequestDieMessage msg, int from) {
|
||||||
|
int roll = this.logic.getGame().getDie().shuffle();
|
||||||
|
this.diceResults.put(this.logic.getGame().getPlayerById(from), roll);
|
||||||
|
if (this.diceResults.size() == this.logic.getGame().getPlayers().size()) {
|
||||||
|
Map<Integer, Long> frequencyMap = diceResults.values().stream()
|
||||||
|
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
|
||||||
|
Map.Entry<Integer, Long> result = frequencyMap.entrySet().stream()
|
||||||
|
.max(Map.Entry.comparingByKey())
|
||||||
|
.orElseThrow(() -> new IllegalStateException("Die Map ist leer"));
|
||||||
|
}
|
||||||
|
this.logic.getServerSender().send(from, new DieMessage(roll));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method will be used to return diceResults attribute of DetermineStartPlayerState class.
|
||||||
|
*
|
||||||
|
* @return diceResults as a Map combing Player objects and Integers.
|
||||||
|
*/
|
||||||
|
public Map<Player, Integer> getDiceResults() {
|
||||||
|
return this.diceResults;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package pp.mdga.server.automaton.game;
|
||||||
|
|
||||||
|
import pp.mdga.server.ServerGameLogic;
|
||||||
|
import pp.mdga.server.automaton.GameState;
|
||||||
|
import pp.mdga.server.automaton.ServerState;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This abstract class represents the game automaton state of the game state automaton.
|
||||||
|
*/
|
||||||
|
public abstract class GameAutomatonState extends ServerState {
|
||||||
|
/**
|
||||||
|
* Create GameAutomatonState attributes.
|
||||||
|
*/
|
||||||
|
protected final GameState gameAutomaton;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a server state of the specified game logic.
|
||||||
|
*
|
||||||
|
* @param gameAutomaton as the automaton of the game state as a GameState object.
|
||||||
|
* @param logic the game logic
|
||||||
|
*/
|
||||||
|
public GameAutomatonState(GameState gameAutomaton, ServerGameLogic logic) {
|
||||||
|
super(logic);
|
||||||
|
this.gameAutomaton = gameAutomaton;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package pp.mdga.server.automaton.game;
|
||||||
|
|
||||||
|
import pp.mdga.server.ServerGameLogic;
|
||||||
|
import pp.mdga.server.automaton.GameState;
|
||||||
|
|
||||||
|
public class TurnState extends GameAutomatonState {
|
||||||
|
/**
|
||||||
|
* Constructs a server state of the specified game logic.
|
||||||
|
*
|
||||||
|
* @param gameAutomaton as the automaton of the game state as a GameState object.
|
||||||
|
* @param logic the game logic
|
||||||
|
*/
|
||||||
|
public TurnState(GameState gameAutomaton, ServerGameLogic logic) {
|
||||||
|
super(gameAutomaton, logic);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enter() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void exit() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,7 @@
|
|||||||
package pp.mdga.server;
|
package pp.mdga.server.automaton.game.turn;
|
||||||
|
|
||||||
|
import pp.mdga.server.ServerGameLogic;
|
||||||
|
import pp.mdga.server.automaton.game.TurnState;
|
||||||
|
|
||||||
public class ChoosePieceState extends TurnState {
|
public class ChoosePieceState extends TurnState {
|
||||||
public ChoosePieceState(ServerGameLogic logic) {
|
public ChoosePieceState(ServerGameLogic logic) {
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package pp.mdga.server.automaton.game.turn;
|
||||||
|
|
||||||
|
import pp.mdga.server.ServerGameLogic;
|
||||||
|
import pp.mdga.server.automaton.game.TurnState;
|
||||||
|
|
||||||
|
public class MovePieceState extends TurnState {
|
||||||
|
public MovePieceState(ServerGameLogic logic) {
|
||||||
|
super(logic);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package pp.mdga.server.automaton.game.turn;
|
||||||
|
|
||||||
|
import pp.mdga.server.ServerGameLogic;
|
||||||
|
import pp.mdga.server.automaton.game.TurnState;
|
||||||
|
|
||||||
|
public class PowerCardState extends TurnState {
|
||||||
|
public PowerCardState(ServerGameLogic logic) {
|
||||||
|
super(logic);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package pp.mdga.server.automaton.game.turn;
|
||||||
|
|
||||||
|
import pp.mdga.server.ServerGameLogic;
|
||||||
|
import pp.mdga.server.automaton.game.TurnState;
|
||||||
|
|
||||||
|
public class RollDiceState extends TurnState {
|
||||||
|
public RollDiceState(ServerGameLogic logic) {
|
||||||
|
super(logic);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package pp.mdga.server.automaton.game.turn.choosepiece;
|
||||||
|
|
||||||
|
import pp.mdga.server.ServerGameLogic;
|
||||||
|
import pp.mdga.server.automaton.game.turn.ChoosePieceState;
|
||||||
|
|
||||||
|
public class NoPieceState extends ChoosePieceState {
|
||||||
|
public NoPieceState(ServerGameLogic logic) {
|
||||||
|
super(logic);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package pp.mdga.server.automaton.game.turn.choosepiece;
|
||||||
|
|
||||||
|
import pp.mdga.server.ServerGameLogic;
|
||||||
|
import pp.mdga.server.automaton.game.turn.ChoosePieceState;
|
||||||
|
|
||||||
|
public class NoTurnState extends ChoosePieceState {
|
||||||
|
public NoTurnState(ServerGameLogic logic) {
|
||||||
|
super(logic);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package pp.mdga.server.automaton.game.turn.choosepiece;
|
||||||
|
|
||||||
|
import pp.mdga.server.ServerGameLogic;
|
||||||
|
import pp.mdga.server.automaton.game.turn.ChoosePieceState;
|
||||||
|
|
||||||
|
public class SelectPieceState extends ChoosePieceState {
|
||||||
|
public SelectPieceState(ServerGameLogic logic) {
|
||||||
|
super(logic);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package pp.mdga.server.automaton.game.turn.choosepiece;
|
||||||
|
|
||||||
|
import pp.mdga.server.ServerGameLogic;
|
||||||
|
import pp.mdga.server.automaton.game.turn.ChoosePieceState;
|
||||||
|
|
||||||
|
public class StartPieceState extends ChoosePieceState {
|
||||||
|
public StartPieceState(ServerGameLogic logic) {
|
||||||
|
super(logic);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package pp.mdga.server.automaton.game.turn.choosepiece;
|
||||||
|
|
||||||
|
import pp.mdga.server.ServerGameLogic;
|
||||||
|
import pp.mdga.server.automaton.game.turn.ChoosePieceState;
|
||||||
|
|
||||||
|
public class WaitingPieceState extends ChoosePieceState {
|
||||||
|
public WaitingPieceState(ServerGameLogic logic) {
|
||||||
|
super(logic);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package pp.mdga.server.automaton.game.turn.rolldice;
|
||||||
|
|
||||||
|
import pp.mdga.server.ServerGameLogic;
|
||||||
|
import pp.mdga.server.automaton.game.turn.RollDiceState;
|
||||||
|
|
||||||
|
public class FirstRollStateState extends RollDiceState {
|
||||||
|
public FirstRollStateState(ServerGameLogic logic) {
|
||||||
|
super(logic);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package pp.mdga.server.automaton.game.turn.rolldice;
|
||||||
|
|
||||||
|
import pp.mdga.server.ServerGameLogic;
|
||||||
|
import pp.mdga.server.automaton.game.turn.RollDiceState;
|
||||||
|
|
||||||
|
public class SecondRollState extends RollDiceState {
|
||||||
|
public SecondRollState(ServerGameLogic logic) {
|
||||||
|
super(logic);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package pp.mdga.server.automaton.game.turn.rolldice;
|
||||||
|
|
||||||
|
import pp.mdga.server.ServerGameLogic;
|
||||||
|
import pp.mdga.server.automaton.game.turn.RollDiceState;
|
||||||
|
|
||||||
|
public class ThirdRollState extends RollDiceState {
|
||||||
|
public ThirdRollState(ServerGameLogic logic) {
|
||||||
|
super(logic);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user