Merge branch 'development' into 'dev/test'
merge dev into test See merge request progproj/gruppen-ht24/Gruppe-01!30
This commit was merged in pull request #30.
This commit is contained in:
@@ -53,6 +53,10 @@ public void setOwnPlayerName(String ownPlayerName) {
|
||||
this.ownPlayerName = ownPlayerName;
|
||||
}
|
||||
|
||||
public void setOwnPlayerId(int ownPlayerId) {
|
||||
this.ownPlayerID = ownPlayerId;
|
||||
}
|
||||
|
||||
public LobbyState getLobby() {
|
||||
return lobbyState;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
|
||||
public class GameState extends ClientState {
|
||||
|
||||
/**
|
||||
* the current substate
|
||||
*/
|
||||
private GameStates state;
|
||||
|
||||
private final AnimationState animationState = new AnimationState(this, logic);
|
||||
@@ -16,21 +19,38 @@ public class GameState extends ClientState {
|
||||
private final TurnState turnState = new TurnState(this, logic);
|
||||
private final WaitingState waitingState = new WaitingState(this, logic);
|
||||
|
||||
/**
|
||||
* Constructor for GameState
|
||||
*
|
||||
* @param parent the parent of this state
|
||||
* @param logic the ClientGameLogic
|
||||
*/
|
||||
public GameState(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
state = determineStartPlayerState;
|
||||
}
|
||||
|
||||
/**
|
||||
* The method to enter the state
|
||||
*/
|
||||
@Override
|
||||
public void enter() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* the method to exit this state
|
||||
*/
|
||||
@Override
|
||||
public void exit() {
|
||||
|
||||
state.exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to set a new SubState
|
||||
*
|
||||
* @param newState the state to be set
|
||||
*/
|
||||
public void setState(GameStates newState){
|
||||
state.exit();
|
||||
state.enter();
|
||||
|
||||
@@ -26,19 +26,35 @@ public void enter() {
|
||||
previousState = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* exits this state
|
||||
*/
|
||||
@Override
|
||||
public void exit() {
|
||||
previousState = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method sets the stores the gamestate as previous state
|
||||
*
|
||||
* @param previousState
|
||||
*/
|
||||
public void setPreviousState(ClientState previousState) {
|
||||
this.previousState = previousState;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns teh previous gamestate
|
||||
*
|
||||
* @return the previous gamestate
|
||||
*/
|
||||
public ClientState getPreviousState() {
|
||||
return previousState;
|
||||
}
|
||||
|
||||
/**
|
||||
* The host resumes the game
|
||||
*/
|
||||
@Override
|
||||
public void selectResume(){
|
||||
if(logic.isHost()){
|
||||
@@ -46,6 +62,11 @@ public void selectResume(){
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The server resumes the game
|
||||
*
|
||||
* @param msg the ResumeGame message received
|
||||
*/
|
||||
public void received(ResumeGameMessage msg) {
|
||||
//TODO: logic.addNotification(new ResumeNotification());
|
||||
logic.setState(previousState);
|
||||
|
||||
@@ -4,17 +4,18 @@
|
||||
import pp.mdga.client.ClientState;
|
||||
import pp.mdga.client.DialogsState;
|
||||
import pp.mdga.game.Color;
|
||||
import pp.mdga.game.Piece;
|
||||
import pp.mdga.game.Player;
|
||||
import pp.mdga.game.PlayerData;
|
||||
import pp.mdga.message.client.*;
|
||||
import pp.mdga.message.server.LobbyPlayerJoinedMessage;
|
||||
import pp.mdga.message.server.LobbyPlayerLeaveMessage;
|
||||
import pp.mdga.message.server.ServerStartGameMessage;
|
||||
import pp.mdga.message.server.UpdateReadyMessage;
|
||||
import pp.mdga.message.server.UpdateTSKMessage;
|
||||
import pp.mdga.notification.LobbyReadyNotification;
|
||||
import pp.mdga.notification.StartDialogNotification;
|
||||
import pp.mdga.notification.TskSelectNotification;
|
||||
import pp.mdga.notification.TskUnselectNotification;
|
||||
import pp.mdga.notification.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class LobbyState extends DialogStates {
|
||||
|
||||
@@ -74,12 +75,26 @@ public void selectStart(){
|
||||
|
||||
@Override
|
||||
public void received(ServerStartGameMessage msg){
|
||||
|
||||
logic.getGame().setBoard(msg.getBoard());
|
||||
logic.addNotification(new GameNotification(logic.getGame().getPlayers().get(parent.getOwnPlayerId()).getColor()));
|
||||
for(Map.Entry<Color, PlayerData> entry : msg.getBoard().getPlayerData().entrySet()){
|
||||
List<UUID> pieceIds = new ArrayList<>();
|
||||
for(Piece piece : entry.getValue().getPieces()){
|
||||
pieceIds.add(piece.getUuid());
|
||||
}
|
||||
logic.addNotification(new PlayerInGameNotification(entry.getKey(), pieceIds, logic.getGame().getPlayerByColor(entry.getKey()).getName()));
|
||||
}
|
||||
parent.startGame();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(LobbyPlayerJoinedMessage msg){
|
||||
if(msg.getPlayer().getName().equals(parent.getOwnPlayerName())){
|
||||
parent.setOwnPlayerId(msg.getId());
|
||||
}
|
||||
if (msg.isHost() && msg.getId() == parent.getOwnPlayerId()){
|
||||
logic.setHost(true);
|
||||
}
|
||||
logic.addNotification(new TskSelectNotification(msg.getPlayer().getColor(), msg.getPlayer().getName(), parent.getOwnPlayerId()== msg.getId()));
|
||||
logic.getGame().getPlayers().put(msg.getId(), msg.getPlayer());
|
||||
}
|
||||
@@ -99,6 +114,7 @@ public void received(LobbyPlayerLeaveMessage msg){
|
||||
|
||||
@Override
|
||||
public void received(UpdateReadyMessage msg){
|
||||
//TODO server sendet kein update on UNready
|
||||
logic.addNotification(new LobbyReadyNotification(logic.getGame().getPlayers().get(msg.getPlayerId()).getColor(), msg.isReady()));
|
||||
logic.getGame().getPlayers().get(msg.getPlayerId()).setReady(msg.isReady());
|
||||
}
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
package pp.mdga.game;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This class will be used to hold all Board relevant data.
|
||||
*/
|
||||
@Serializable
|
||||
public class Board {
|
||||
private Map<Color, PlayerData> playerData;
|
||||
private Map<Color, PlayerData> playerData = new HashMap<>();
|
||||
private final Node[] infield;
|
||||
|
||||
/**
|
||||
@@ -30,6 +34,17 @@ public Board() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used to add the given color and playerData parameters to the playerData attribute of
|
||||
* Board class.
|
||||
*
|
||||
* @param color as the color of the player as a Color enumeration.
|
||||
* @param playerData as the playerData of the player as a PlayerData object.
|
||||
*/
|
||||
public void addPlayerData(Color color, PlayerData playerData) {
|
||||
this.playerData.put(color, playerData);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the playerData
|
||||
*
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
package pp.mdga.game;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
/**
|
||||
* This class represents a BonusNode
|
||||
*/
|
||||
@Serializable
|
||||
public class BonusNode extends Node {
|
||||
BonusNode(){
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,9 @@ public class Game {
|
||||
// The die used in the game.
|
||||
private Die die;
|
||||
|
||||
// The host of this game
|
||||
private int host;
|
||||
|
||||
// The color of the active player.
|
||||
private Color activeColor;
|
||||
|
||||
@@ -232,6 +235,15 @@ public Color getActiveColor() {
|
||||
return activeColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used to return host attribute of Game class.
|
||||
*
|
||||
* @return host as an Integer.
|
||||
*/
|
||||
public int getHost() {
|
||||
return this.host;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method sets the dice modifier.
|
||||
*
|
||||
@@ -304,6 +316,15 @@ public void setActiveColor(Color activeColor) {
|
||||
this.activeColor = activeColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used to set host attribute of Game class to the given host parameter.
|
||||
*
|
||||
* @param host as the new value of host as an Integer.
|
||||
*/
|
||||
public void setHost(int host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the all ready state.
|
||||
*
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
package pp.mdga.game;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
/**
|
||||
* Represents a home node.
|
||||
*/
|
||||
@Serializable
|
||||
public class HomeNode extends Node {
|
||||
public HomeNode() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,18 @@
|
||||
package pp.mdga.game;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
/**
|
||||
* This class will be used the represent a Node on which the pieces can travel along
|
||||
*/
|
||||
@Serializable
|
||||
public class Node {
|
||||
protected Piece occupant;
|
||||
|
||||
public Node(){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to get an occupant of the Node.
|
||||
*
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package pp.mdga.game;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* This class will be used to hold all Piece relevant data.
|
||||
*/
|
||||
@Serializable
|
||||
public class Piece {
|
||||
/**
|
||||
* The shield state of the piece.
|
||||
@@ -38,6 +41,10 @@ public Piece(Color color, PieceState state, int id) {
|
||||
shield = ShieldState.NONE;
|
||||
}
|
||||
|
||||
private Piece() {
|
||||
color = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to get the color of the piece
|
||||
*
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package pp.mdga.game;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
/**
|
||||
* This class is used to represent PlayerData related to the board
|
||||
*/
|
||||
@Serializable
|
||||
public class PlayerData {
|
||||
/**
|
||||
* An array of HomeNode objects representing the home nodes of the player.
|
||||
@@ -31,6 +34,7 @@ public class PlayerData {
|
||||
*/
|
||||
public PlayerData(Color color) {
|
||||
homeNodes = new HomeNode[4];
|
||||
pieces = new Piece[4];
|
||||
waitingArea = new Piece[4];
|
||||
for (int i = 0; i < 4; i++) {
|
||||
homeNodes[i] = new HomeNode();
|
||||
@@ -39,6 +43,12 @@ public PlayerData(Color color) {
|
||||
}
|
||||
}
|
||||
|
||||
private PlayerData() {
|
||||
homeNodes = null;
|
||||
waitingArea = null;
|
||||
pieces = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns an Array of HomeNodes
|
||||
*
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package pp.mdga.game;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
/**
|
||||
* Represents a start node.
|
||||
*/
|
||||
@Serializable
|
||||
public class StartNode extends Node {
|
||||
/**
|
||||
* The color of the node.
|
||||
@@ -18,6 +21,10 @@ public StartNode(Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
private StartNode() {
|
||||
color = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to get the color of the node
|
||||
*
|
||||
|
||||
@@ -19,16 +19,23 @@ public class LobbyPlayerJoinedMessage extends ServerMessage {
|
||||
*/
|
||||
private final int id;
|
||||
|
||||
/**
|
||||
* The flag is the new player is the host
|
||||
*/
|
||||
private final boolean host;
|
||||
|
||||
/**
|
||||
* Constructs a new LobbyPlayerJoin instance with the specified player name.
|
||||
*
|
||||
* @param player the player joining the lobby
|
||||
* @param id the id of the player
|
||||
* @param id the id of the player
|
||||
* @param host as the flag if the player is the host as a Boolean.
|
||||
*/
|
||||
public LobbyPlayerJoinedMessage(int id, Player player) {
|
||||
public LobbyPlayerJoinedMessage(int id, Player player, boolean host) {
|
||||
super();
|
||||
this.player = player;
|
||||
this.id = id;
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,6 +44,7 @@ public LobbyPlayerJoinedMessage(int id, Player player) {
|
||||
private LobbyPlayerJoinedMessage() {
|
||||
player = null;
|
||||
id = 0;
|
||||
host = false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,6 +65,10 @@ public int getId(){
|
||||
return id;
|
||||
}
|
||||
|
||||
public boolean isHost() {
|
||||
return this.host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a visitor to process this message.
|
||||
*
|
||||
|
||||
@@ -1,17 +1,33 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
import pp.mdga.game.Board;
|
||||
|
||||
/**
|
||||
* A message indicating that the game shall start.
|
||||
*/
|
||||
@Serializable
|
||||
public class ServerStartGameMessage extends ServerMessage {
|
||||
/**
|
||||
* Create ServerStartGameMessage attributes.
|
||||
*/
|
||||
private final Board board;
|
||||
|
||||
/**
|
||||
* Constructs a new ServerStartGame instance.
|
||||
*/
|
||||
public ServerStartGameMessage() {
|
||||
super();
|
||||
this.board = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param board as the complete board of this game as a Board object.
|
||||
*/
|
||||
public ServerStartGameMessage(Board board) {
|
||||
this.board = board;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -24,6 +40,15 @@ public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used to return board attribute of ServerStartGameMessage class.
|
||||
*
|
||||
* @return board as a Board object.
|
||||
*/
|
||||
public Board getBoard() {
|
||||
return this.board;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this message.
|
||||
*
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
package pp.mdga.notification;
|
||||
|
||||
import pp.mdga.game.Color;
|
||||
|
||||
/**
|
||||
* Notification that is sent when a player has diced.
|
||||
*/
|
||||
public class DicingNotification extends Notification {
|
||||
/**
|
||||
* The color of the player that diced.
|
||||
*/
|
||||
private final Color color;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param color The color of the player that diced.
|
||||
*/
|
||||
public DicingNotification(Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the color of the player that diced.
|
||||
*
|
||||
* @return The color of the player that diced.
|
||||
*/
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package pp.mdga.notification;
|
||||
|
||||
import pp.mdga.game.Color;
|
||||
|
||||
public class FinishNotification extends Notification{
|
||||
private Color colorFinished;
|
||||
|
||||
public FinishNotification(Color colorFinished){
|
||||
this.colorFinished = colorFinished;
|
||||
}
|
||||
|
||||
public Color getColorFinished() {
|
||||
return colorFinished;
|
||||
}
|
||||
}
|
||||
@@ -25,9 +25,9 @@ public class GameState extends ServerState {
|
||||
* Create GameState states.
|
||||
*/
|
||||
private GameAutomatonState currentState;
|
||||
private final GameAutomatonState determineStartPlayerState;
|
||||
private final GameAutomatonState animationState;
|
||||
private final GameAutomatonState turnState;
|
||||
private final DetermineStartPlayerState determineStartPlayerState;
|
||||
private final AnimationState animationState;
|
||||
private final TurnState turnState;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@@ -122,27 +122,27 @@ public GameAutomatonState getCurrentState() {
|
||||
/**
|
||||
* This method will be used to return determineStartPlayerState attribute of GameState class.
|
||||
*
|
||||
* @return determineStartPlayerState as a GameAutomatonState object.
|
||||
* @return determineStartPlayerState as a DetermineStartPlayerState object.
|
||||
*/
|
||||
public GameAutomatonState getDetermineStartPlayerState() {
|
||||
public DetermineStartPlayerState getDetermineStartPlayerState() {
|
||||
return this.determineStartPlayerState;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used to return animationState attribute of GameState class.
|
||||
*
|
||||
* @return animationState as a GameAutomatonState object.
|
||||
* @return animationState as a AnimationState object.
|
||||
*/
|
||||
public GameAutomatonState getAnimationState() {
|
||||
public AnimationState getAnimationState() {
|
||||
return this.animationState;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used to return turnState attribute of GameState class.
|
||||
*
|
||||
* @return turnState as a GameAutomatonState object.
|
||||
* @return turnState as a TurnState object.
|
||||
*/
|
||||
public GameAutomatonState getTurnState() {
|
||||
public TurnState getTurnState() {
|
||||
return this.turnState;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import pp.mdga.game.Color;
|
||||
import pp.mdga.game.Player;
|
||||
import pp.mdga.game.PlayerData;
|
||||
import pp.mdga.message.client.*;
|
||||
import pp.mdga.message.server.*;
|
||||
import pp.mdga.server.ServerGameLogic;
|
||||
@@ -43,6 +44,15 @@ public void exit() {
|
||||
LOGGER.log(System.Logger.Level.DEBUG, "Exited LobbyState state.");
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used to initialize the game and all necessary objects.
|
||||
*/
|
||||
public void initializeGame() {
|
||||
for (Map.Entry<Integer, Player> entry: this.logic.getGame().getPlayers().entrySet()) {
|
||||
this.logic.getGame().getBoard().addPlayerData(entry.getValue().getColor(), new PlayerData(entry.getValue().getColor()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called whenever the server received a JoinedLobbyMessage message.
|
||||
* It will also get the client id of the player who send this message
|
||||
@@ -55,8 +65,8 @@ public void received(JoinedLobbyMessage msg, int from) {
|
||||
Player player = new Player(msg.getName());
|
||||
player.setColor(Color.getColorByIndex(this.logic.getGame().getPlayers().size()));
|
||||
this.logic.getGame().addPlayer(from, player);
|
||||
for (Map.Entry<Integer, Player> entry: this.logic.getGame().getPlayers().entrySet()) {
|
||||
this.logic.getServerSender().broadcast(new LobbyPlayerJoinedMessage(entry.getKey(), entry.getValue()));
|
||||
for (Map.Entry<Integer, Player> entry : this.logic.getGame().getPlayers().entrySet()) {
|
||||
this.logic.getServerSender().broadcast(new LobbyPlayerJoinedMessage(entry.getKey(), entry.getValue(), entry.getKey() == this.logic.getGame().getHost()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,12 +113,16 @@ public void received(LobbyReadyMessage msg, int from) {
|
||||
this.logic.getGame().getPlayerById(from).setReady(true);
|
||||
this.logic.getServerSender().broadcast(new UpdateReadyMessage(from, true));
|
||||
for (Map.Entry<Integer, Player> entry : this.logic.getGame().getPlayers().entrySet()) {
|
||||
if (!entry.getValue().isActive()) {
|
||||
if (!entry.getValue().isReady()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.logic.getGame().setAllReady(true);
|
||||
if (this.logic.getGame().allReady()) {
|
||||
this.initializeGame();
|
||||
this.logic.getServerSender().broadcast(new ServerStartGameMessage(this.logic.getGame().getBoard()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -149,7 +163,8 @@ public void received(LeaveGameMessage msg, int from) {
|
||||
@Override
|
||||
public void received(StartGameMessage msg, int from) {
|
||||
if (msg.isForceStartGame() || this.logic.getGame().allReady()) {
|
||||
this.logic.getServerSender().broadcast(new ServerStartGameMessage());
|
||||
this.initializeGame();
|
||||
this.logic.getServerSender().broadcast(new ServerStartGameMessage(this.logic.getGame().getBoard()));
|
||||
this.logic.setCurrentState(this.logic.getGameState());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,14 @@
|
||||
|
||||
import pp.mdga.game.Player;
|
||||
import pp.mdga.message.client.RequestDieMessage;
|
||||
import pp.mdga.message.server.ActivePlayerMessage;
|
||||
import pp.mdga.message.server.DieMessage;
|
||||
import pp.mdga.server.ServerGameLogic;
|
||||
import pp.mdga.server.automaton.GameState;
|
||||
import pp.mdga.server.automaton.game.turn.RollDiceState;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -21,7 +23,8 @@ public class DetermineStartPlayerState extends GameAutomatonState {
|
||||
/**
|
||||
* Create DetermineStartPlayerState attributes.
|
||||
*/
|
||||
private Map<Player, Integer> diceResults = new HashMap<>();
|
||||
private Map<Integer, Integer> diceResults = new HashMap<>();
|
||||
private List<Integer> playersHaveToRoll = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Constructs a server state of the specified game logic.
|
||||
@@ -36,6 +39,9 @@ public DetermineStartPlayerState(GameState gameAutomaton, ServerGameLogic logic)
|
||||
@Override
|
||||
public void enter() {
|
||||
LOGGER.log(System.Logger.Level.DEBUG, "Entered DetermineStartPlayerState state.");
|
||||
for (Map.Entry<Integer, Player> entry: this.logic.getGame().getPlayers().entrySet()) {
|
||||
this.playersHaveToRoll.add(entry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -53,23 +59,26 @@ public void exit() {
|
||||
@Override
|
||||
public void received(RequestDieMessage msg, int from) {
|
||||
int roll = this.logic.getGame().getDie().shuffle();
|
||||
this.diceResults.put(this.logic.getGame().getPlayerById(from), roll);
|
||||
this.diceResults.put(from, roll);
|
||||
int maximumRoll = 0;
|
||||
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));
|
||||
}
|
||||
for (Map.Entry<Integer, Integer> entry: this.diceResults.entrySet()) {
|
||||
if (maximumRoll == 0) {
|
||||
maximumRoll = this.diceResults.get(entry.getKey());
|
||||
} else if (maximumRoll < entry.getValue()) {
|
||||
maximumRoll = entry.getValue();
|
||||
} else {
|
||||
this.playersHaveToRoll.remove(entry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
if (this.playersHaveToRoll.size() == 1) {
|
||||
this.logic.getServerSender().broadcast(new ActivePlayerMessage(this.logic.getGame().getPlayerById(this.playersHaveToRoll.get(0)).getColor()));
|
||||
} else {
|
||||
for (Integer id: this.playersHaveToRoll) {
|
||||
this.logic.getServerSender().send(id, new DieMessage(roll));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user