Merge branch 'development' into 'dev/test'
merge dev into test See merge request progproj/gruppen-ht24/Gruppe-01!33
This commit was merged in pull request #33.
This commit is contained in:
@@ -18,7 +18,7 @@ public CeremonyState(ClientState parent, ClientGameLogic logic) {
|
||||
|
||||
@Override
|
||||
public void enter() {
|
||||
currentState = podiumState;
|
||||
setState(podiumState);
|
||||
logic.addNotification(createCeremonyNotification());
|
||||
}
|
||||
|
||||
@@ -28,7 +28,9 @@ public void exit() {
|
||||
}
|
||||
|
||||
public void setState(CeremonyStates state){
|
||||
this.currentState.exit();
|
||||
if(this.currentState != null){
|
||||
this.currentState.exit();
|
||||
}
|
||||
state.enter();
|
||||
currentState = state;
|
||||
}
|
||||
|
||||
@@ -190,6 +190,19 @@ public void received(ServerStartGameMessage msg) {
|
||||
state.received(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(ShutdownMessage msg) {state.received(msg);}
|
||||
|
||||
@Override
|
||||
public void received(StartBriefingMessage msg) {
|
||||
state.received(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(PlayerDataMessage msg) {
|
||||
state.received(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(StartPieceMessage msg) {
|
||||
state.received(msg);
|
||||
@@ -236,6 +249,10 @@ public void selectTsk(Color color){
|
||||
state.selectTSK(color);
|
||||
}
|
||||
|
||||
public void deselectTSK(Color color){
|
||||
state.deselectTSK(color);
|
||||
}
|
||||
|
||||
public void selectDice(){
|
||||
state.selectDice();
|
||||
}
|
||||
|
||||
@@ -150,6 +150,9 @@ public void received(ServerStartGameMessage msg) {
|
||||
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(ShutdownMessage msg) {LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg);}
|
||||
|
||||
@Override
|
||||
public void received(StartPieceMessage msg) {
|
||||
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg);
|
||||
@@ -180,6 +183,15 @@ public void received(WaitPieceMessage msg) {
|
||||
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(StartBriefingMessage msg) {
|
||||
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg);
|
||||
}
|
||||
|
||||
public void received(PlayerDataMessage msg) {
|
||||
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg);
|
||||
}
|
||||
|
||||
public void selectPiece(Piece piece) {
|
||||
LOGGER.log(Level.DEBUG, "Selecting piece not allowed.");
|
||||
}
|
||||
|
||||
@@ -30,13 +30,15 @@ public void exit(){
|
||||
|
||||
@Override
|
||||
public void enter(){
|
||||
currentState = startDialogState;
|
||||
setState(startDialogState);
|
||||
ownPlayerID = 0;
|
||||
ownPlayerName = null;
|
||||
}
|
||||
|
||||
public void setState(DialogStates newState){
|
||||
currentState.exit();
|
||||
if(currentState != null){
|
||||
currentState.exit();
|
||||
}
|
||||
newState.enter();
|
||||
currentState = newState;
|
||||
}
|
||||
@@ -69,11 +71,6 @@ public StartDialogState getStartDialog() {
|
||||
return startDialogState;
|
||||
}
|
||||
|
||||
public void startGame(){
|
||||
exit();
|
||||
logic.setState(logic.getGameState());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectLeave(){
|
||||
currentState.selectLeave();
|
||||
@@ -144,6 +141,16 @@ public void received(ServerStartGameMessage msg){
|
||||
currentState.received(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(PlayerDataMessage msg){
|
||||
currentState.received(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(StartBriefingMessage msg){
|
||||
currentState.received(msg);
|
||||
}
|
||||
|
||||
public DialogStates getState() {
|
||||
return currentState;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ public class GameState extends ClientState {
|
||||
*/
|
||||
public GameState(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
state = determineStartPlayerState;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -35,7 +34,7 @@ public GameState(ClientState parent, ClientGameLogic logic) {
|
||||
*/
|
||||
@Override
|
||||
public void enter() {
|
||||
|
||||
this.setState(this.determineStartPlayerState);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -52,8 +51,10 @@ public void exit() {
|
||||
* @param newState the state to be set
|
||||
*/
|
||||
public void setState(GameStates newState){
|
||||
state.exit();
|
||||
state.enter();
|
||||
if(this.state != null){
|
||||
this.state.exit();
|
||||
}
|
||||
newState.enter();
|
||||
state = newState;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,9 @@
|
||||
import pp.mdga.message.client.*;
|
||||
import pp.mdga.message.server.LobbyPlayerJoinedMessage;
|
||||
import pp.mdga.message.server.LobbyPlayerLeaveMessage;
|
||||
import pp.mdga.message.server.PlayerDataMessage;
|
||||
import pp.mdga.message.server.ServerStartGameMessage;
|
||||
import pp.mdga.message.server.StartBriefingMessage;
|
||||
import pp.mdga.message.server.UpdateReadyMessage;
|
||||
import pp.mdga.message.server.UpdateTSKMessage;
|
||||
import pp.mdga.notification.*;
|
||||
@@ -74,17 +76,26 @@ public void selectStart(){
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(ServerStartGameMessage msg){
|
||||
public void received(StartBriefingMessage 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<>();
|
||||
}
|
||||
|
||||
public void received(PlayerDataMessage msg){
|
||||
logic.getGame().getBoard().addPlayerData(msg.getColor(), msg.getPlayerData());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(ServerStartGameMessage msg){
|
||||
logic.addNotification(new GameNotification(logic.getGame().getPlayerById(parent.getOwnPlayerId()).getColor()));
|
||||
for (Map.Entry<Color, PlayerData> entry : logic.getGame().getBoard().getPlayerData().entrySet()) {
|
||||
List<UUID> pieceList = new ArrayList<>();
|
||||
for(Piece piece : entry.getValue().getPieces()){
|
||||
pieceIds.add(piece.getUuid());
|
||||
System.out.println(piece.getUuid());
|
||||
pieceList.add(piece.getUuid());
|
||||
}
|
||||
logic.addNotification(new PlayerInGameNotification(entry.getKey(), pieceIds, logic.getGame().getPlayerByColor(entry.getKey()).getName()));
|
||||
logic.addNotification(new PlayerInGameNotification(entry.getKey(), pieceList , logic.getGame().getPlayerByColor(entry.getKey()).getName()));
|
||||
}
|
||||
parent.startGame();
|
||||
logic.setState(logic.getGameState());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -95,15 +106,20 @@ public void received(LobbyPlayerJoinedMessage msg){
|
||||
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.addNotification(new TskSelectNotification(msg.getPlayer().getColor(), msg.getPlayer().getName(), msg.getPlayer().getName().equals(parent.getOwnPlayerName())));
|
||||
logic.getGame().getPlayers().put(msg.getId(), msg.getPlayer());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(UpdateTSKMessage msg){
|
||||
logic.addNotification(new TskUnselectNotification(logic.getGame().getPlayers().get(msg.getId()).getColor()));
|
||||
if(msg.isTaken()) {
|
||||
logic.addNotification(new TskSelectNotification(msg.getColor(), logic.getGame().getPlayers().get(msg.getId()).getName(), parent.getOwnPlayerId()== msg.getId()));
|
||||
} else {
|
||||
logic.addNotification(new TskUnselectNotification(logic.getGame().getPlayers().get(msg.getId()).getColor()));
|
||||
}
|
||||
|
||||
logic.getGame().getPlayers().get(msg.getId()).setColor(msg.getColor());
|
||||
logic.addNotification(new TskSelectNotification(msg.getColor(), logic.getGame().getPlayers().get(msg.getId()).getName(), parent.getOwnPlayerId()== msg.getId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -14,34 +14,6 @@ public NetworkDialogState(ClientState parent, ClientGameLogic logic) {
|
||||
this.parent = (DialogsState) parent;
|
||||
}
|
||||
|
||||
private boolean checkIP(String IP){
|
||||
String[] parts = IP.split("\\.");
|
||||
|
||||
// Step 2: Check if there are exactly 4 parts
|
||||
if (parts.length != 4) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Step 3: Check each part for valid number
|
||||
for (String part : parts) {
|
||||
try {
|
||||
// Step 4: Convert each part into a number
|
||||
int num = Integer.parseInt(part);
|
||||
|
||||
// Step 5: Check whether the number lies in between 0 and 255
|
||||
if (num < 0 || num > 255) {
|
||||
return false;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
// If parsing fails, it's not a valid number
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// If all checks passed, return true
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enter() {
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public DetermineStartPlayerState(ClientState parent, ClientGameLogic logic) {
|
||||
|
||||
@Override
|
||||
public void enter() {
|
||||
state = rollRankingDiceState;
|
||||
this.setState(this.rollRankingDiceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -34,7 +34,9 @@ public void exit() {
|
||||
}
|
||||
|
||||
public void setState(DetermineStartPlayerStates state) {
|
||||
this.state.exit();
|
||||
if(this.state != null){
|
||||
this.state.exit();
|
||||
}
|
||||
state.enter();
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public TurnState(ClientState parent, ClientGameLogic logic) {
|
||||
|
||||
@Override
|
||||
public void enter() {
|
||||
state = powerCardState;
|
||||
this.setState(this.powerCardState);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -40,7 +40,9 @@ public void exit() {
|
||||
}
|
||||
|
||||
public void setState(TurnStates state){
|
||||
this.state.exit();
|
||||
if(this.state != null){
|
||||
this.state.exit();
|
||||
}
|
||||
state.enter();
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
import pp.mdga.message.client.RequestDieMessage;
|
||||
import pp.mdga.message.server.DieMessage;
|
||||
import pp.mdga.notification.DiceNowNotification;
|
||||
import pp.mdga.notification.RollDiceNotification;
|
||||
|
||||
public class RollRankingDiceState extends DetermineStartPlayerStates {
|
||||
|
||||
@@ -23,16 +24,17 @@ public void enter() {
|
||||
|
||||
@Override
|
||||
public void exit() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectDice(){
|
||||
System.out.println("selectDice");
|
||||
logic.send(new RequestDieMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(DieMessage msg){
|
||||
logic.addNotification(new RollDiceNotification(logic.getGame().getPlayerById(logic.getDialogs().getOwnPlayerId()).getColor(), msg.getDiceEye(),true));
|
||||
parent.setState(parent.getWaitRanking());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ public ChoosePieceState(ClientState parent, ClientGameLogic logic) {
|
||||
|
||||
@Override
|
||||
public void enter() {
|
||||
currentState = noPieceState;
|
||||
this.setState(this.noPieceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -34,9 +34,11 @@ public void exit() {
|
||||
}
|
||||
|
||||
public void setState(ChoosePieceStates state){
|
||||
currentState.exit();
|
||||
if(currentState != null){
|
||||
currentState.exit();
|
||||
}
|
||||
state.enter();
|
||||
currentState = state;
|
||||
currentState.enter();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -31,7 +31,7 @@ public PowerCardState(ClientState parent, ClientGameLogic logic) {
|
||||
|
||||
@Override
|
||||
public void enter() {
|
||||
state = choosePowerCardState;
|
||||
this.setState(this.choosePowerCardState);
|
||||
}
|
||||
|
||||
public void exit() {
|
||||
@@ -40,7 +40,9 @@ public void exit() {
|
||||
}
|
||||
|
||||
public void setState(PowerCardStates state) {
|
||||
this.state.exit();
|
||||
if(this.state != null){
|
||||
this.state.exit();
|
||||
}
|
||||
state.enter();
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
@@ -42,7 +42,9 @@ public Piece(Color color, PieceState state, int id) {
|
||||
}
|
||||
|
||||
private Piece() {
|
||||
color = null;
|
||||
color = Color.NONE;
|
||||
state = PieceState.WAITING;
|
||||
shield = ShieldState.NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package pp.mdga.game;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
/**
|
||||
* Represents the state of a piece.
|
||||
*/
|
||||
@@ -19,5 +21,21 @@ public enum PieceState {
|
||||
/**
|
||||
* The piece is finished.
|
||||
*/
|
||||
HOMEFINISHED
|
||||
HOMEFINISHED;
|
||||
|
||||
PieceState(){
|
||||
|
||||
}
|
||||
|
||||
public static PieceState getPieceStateByIndex(int index){
|
||||
if (index < 0 || index >= values().length) {
|
||||
throw new IllegalArgumentException("");
|
||||
}
|
||||
return values()[index];
|
||||
}
|
||||
|
||||
|
||||
public PieceState next() {
|
||||
return values()[(ordinal() + 1) % values().length];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,10 +43,23 @@ public PlayerData(Color color) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
private PlayerData() {
|
||||
homeNodes = null;
|
||||
waitingArea = null;
|
||||
pieces = null;
|
||||
homeNodes = new HomeNode[4];
|
||||
waitingArea = new Piece[4];
|
||||
pieces = new Piece[4];
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used to check if the player is finished.
|
||||
* ToDo: Currently return always false. Implement logic!
|
||||
*
|
||||
* @return true or false.
|
||||
*/
|
||||
public boolean isFinished() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package pp.mdga.game;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
/**
|
||||
* Represents the state of a piece's shield.
|
||||
*/
|
||||
@Serializable
|
||||
public enum ShieldState {
|
||||
/**
|
||||
* The shield is not active.
|
||||
@@ -15,5 +18,20 @@ public enum ShieldState {
|
||||
/**
|
||||
* The shield is suppressed, when the piece is on a start node.
|
||||
*/
|
||||
SUPPRESSED
|
||||
SUPPRESSED;
|
||||
|
||||
ShieldState(){
|
||||
|
||||
}
|
||||
|
||||
public static ShieldState getShieldStateByIndex(int index){
|
||||
if (index < 0 || index >= values().length) {
|
||||
throw new IllegalArgumentException("");
|
||||
}
|
||||
return values()[index];
|
||||
}
|
||||
|
||||
public ShieldState next() {
|
||||
return values()[(ordinal() + 1) % values().length];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ public StartNode(Color color) {
|
||||
}
|
||||
|
||||
private StartNode() {
|
||||
color = null;
|
||||
color = Color.NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
import pp.mdga.game.Color;
|
||||
import pp.mdga.game.PlayerData;
|
||||
|
||||
@Serializable
|
||||
public class PlayerDataMessage extends ServerMessage{
|
||||
|
||||
private final PlayerData playerData;
|
||||
private final Color color;
|
||||
|
||||
public PlayerDataMessage(PlayerData playerData, Color color){
|
||||
super();
|
||||
this.playerData = playerData;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
private PlayerDataMessage(){
|
||||
this(null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInfoTextKey() {
|
||||
return "";
|
||||
}
|
||||
|
||||
public PlayerData getPlayerData(){
|
||||
return playerData;
|
||||
}
|
||||
|
||||
public Color getColor(){
|
||||
return color;
|
||||
}
|
||||
}
|
||||
@@ -207,4 +207,15 @@ public interface ServerInterpreter {
|
||||
* @param msg the SelectPiece message received.
|
||||
*/
|
||||
void received(SelectPieceMessage msg);
|
||||
|
||||
/**
|
||||
* Handles a SelectTSK message received from the server.
|
||||
*
|
||||
* @param shutdownMessage the SelectTSK message received.
|
||||
*/
|
||||
void received(ShutdownMessage shutdownMessage);
|
||||
|
||||
void received(StartBriefingMessage msg);
|
||||
|
||||
void received(PlayerDataMessage msg);
|
||||
}
|
||||
|
||||
@@ -8,28 +8,13 @@
|
||||
*/
|
||||
@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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a visitor to process this message.
|
||||
*
|
||||
@@ -40,15 +25,6 @@ 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.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
/**
|
||||
* A message sent by the server to inform the clients that the server is shutting down.
|
||||
*/
|
||||
@Serializable
|
||||
public class ShutdownMessage extends ServerMessage {
|
||||
/**
|
||||
* Accepts a visitor to process this message.
|
||||
*
|
||||
* @param interpreter the visitor to process this message
|
||||
*/
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the bundle key of the informational text to be shown at the client.
|
||||
* This key is used to retrieve the appropriate localized text for display.
|
||||
*
|
||||
* @return the bundle key of the informational text
|
||||
*/
|
||||
@Override
|
||||
public String getInfoTextKey() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
import pp.mdga.game.Board;
|
||||
|
||||
@Serializable
|
||||
public class StartBriefingMessage extends ServerMessage {
|
||||
|
||||
private final Board board;
|
||||
|
||||
public StartBriefingMessage(Board board) {
|
||||
super();
|
||||
this.board = board;
|
||||
}
|
||||
|
||||
private StartBriefingMessage() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public Board getBoard() {
|
||||
return this.board;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInfoTextKey() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -18,23 +18,26 @@ public class UpdateTSKMessage extends ServerMessage {
|
||||
*/
|
||||
private final Color color;
|
||||
|
||||
private final boolean isTaken;
|
||||
|
||||
/**
|
||||
* Constructs a new UpdateTSK instance with the specified id and color.
|
||||
*
|
||||
* @param id the name associated with the update
|
||||
* @param color the color associated with the update
|
||||
*/
|
||||
public UpdateTSKMessage(int id, Color color) {
|
||||
public UpdateTSKMessage(int id, Color color, boolean isTaken) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.color = color;
|
||||
this.isTaken = isTaken;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
*/
|
||||
private UpdateTSKMessage() {
|
||||
this(0, null);
|
||||
this(0, null, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,4 +87,8 @@ public String toString() {
|
||||
public String getInfoTextKey() {
|
||||
return "";
|
||||
}
|
||||
|
||||
public boolean isTaken() {
|
||||
return isTaken;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ public class RollDiceNotification extends Notification{
|
||||
private int eyes;
|
||||
private boolean turbo;
|
||||
private int multiplier;
|
||||
private boolean isRanking;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@@ -22,6 +23,15 @@ public RollDiceNotification(Color color, int eyes) {
|
||||
this.eyes = eyes;
|
||||
this.turbo = false;
|
||||
this.multiplier = -1;
|
||||
this.isRanking = false;
|
||||
}
|
||||
|
||||
public RollDiceNotification(Color color, int eyes, boolean isRanking) {
|
||||
this.color = color;
|
||||
this.eyes = eyes;
|
||||
this.turbo = false;
|
||||
this.multiplier = -1;
|
||||
this.isRanking = isRanking;
|
||||
}
|
||||
|
||||
public RollDiceNotification(Color color, int eyes, boolean turbo, int multiplier) {
|
||||
@@ -29,6 +39,7 @@ public RollDiceNotification(Color color, int eyes, boolean turbo, int multiplier
|
||||
this.eyes = eyes;
|
||||
this.turbo = turbo;
|
||||
this.multiplier = multiplier;
|
||||
this.isRanking = false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,4 +65,6 @@ public int getMultiplier() {
|
||||
public boolean isTurbo() {
|
||||
return turbo;
|
||||
}
|
||||
|
||||
public boolean isRanking() { return isRanking; }
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
import pp.mdga.message.server.*;
|
||||
import pp.mdga.server.ServerGameLogic;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -48,7 +49,7 @@ public void exit() {
|
||||
* 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()) {
|
||||
for (Map.Entry<Integer, Player> entry : this.logic.getGame().getPlayers().entrySet()) {
|
||||
this.logic.getGame().getBoard().addPlayerData(entry.getValue().getColor(), new PlayerData(entry.getValue().getColor()));
|
||||
}
|
||||
}
|
||||
@@ -63,7 +64,7 @@ public void initializeGame() {
|
||||
@Override
|
||||
public void received(JoinedLobbyMessage msg, int from) {
|
||||
Player player = new Player(msg.getName());
|
||||
player.setColor(Color.getColorByIndex(this.logic.getGame().getPlayers().size()));
|
||||
player.setColor(Color.NONE);
|
||||
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(), entry.getKey() == this.logic.getGame().getHost()));
|
||||
@@ -84,8 +85,13 @@ public void received(SelectTSKMessage msg, int from) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.logic.getGame().getPlayerById(from).getColor() != Color.NONE) {
|
||||
this.logic.getServerSender().broadcast(new UpdateTSKMessage(from, this.logic.getGame().getPlayerById(from).getColor(), false));
|
||||
}
|
||||
|
||||
this.logic.getGame().getPlayerById(from).setColor(msg.getColor());
|
||||
this.logic.getServerSender().broadcast(new UpdateTSKMessage(from, msg.getColor()));
|
||||
this.logic.getServerSender().broadcast(new UpdateTSKMessage(from, msg.getColor(), true));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,7 +104,7 @@ public void received(SelectTSKMessage msg, int from) {
|
||||
@Override
|
||||
public void received(DeselectTSKMessage msg, int from) {
|
||||
this.logic.getGame().getPlayerById(from).setColor(Color.NONE);
|
||||
this.logic.getServerSender().broadcast(new UpdateTSKMessage(from, Color.NONE));
|
||||
this.logic.getServerSender().broadcast(new UpdateTSKMessage(from, Color.NONE, false));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -110,6 +116,28 @@ public void received(DeselectTSKMessage msg, int from) {
|
||||
*/
|
||||
@Override
|
||||
public void received(LobbyReadyMessage msg, int from) {
|
||||
//assign a free color
|
||||
if (this.logic.getGame().getPlayerById(from).getColor() == Color.NONE) {
|
||||
ArrayList<Color> colors = new ArrayList<>();
|
||||
colors.add(Color.ARMY);
|
||||
colors.add(Color.AIRFORCE);
|
||||
colors.add(Color.NAVY);
|
||||
colors.add(Color.CYBER);
|
||||
|
||||
for (Map.Entry<Integer, Player> entry : this.logic.getGame().getPlayers().entrySet()) {
|
||||
if (colors.contains(entry.getValue().getColor())) {
|
||||
colors.remove(entry.getValue().getColor());
|
||||
}
|
||||
}
|
||||
|
||||
if (colors.size() < 1) {
|
||||
throw new RuntimeException("can not assign a color");
|
||||
}
|
||||
|
||||
this.logic.getGame().getPlayerById(from).setColor(colors.get(0));
|
||||
this.logic.getServerSender().broadcast(new UpdateTSKMessage(from, colors.get(0), true));
|
||||
}
|
||||
|
||||
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()) {
|
||||
@@ -120,8 +148,12 @@ public void received(LobbyReadyMessage msg, int from) {
|
||||
|
||||
this.logic.getGame().setAllReady(true);
|
||||
if (this.logic.getGame().allReady()) {
|
||||
this.logic.getServerSender().broadcast(new StartBriefingMessage(this.logic.getGame().getBoard()));
|
||||
this.initializeGame();
|
||||
this.logic.getServerSender().broadcast(new ServerStartGameMessage(this.logic.getGame().getBoard()));
|
||||
for (Map.Entry<Color, PlayerData> entry : logic.getGame().getBoard().getPlayerData().entrySet()) {
|
||||
this.logic.getServerSender().broadcast(new PlayerDataMessage(entry.getValue(), entry.getKey()));
|
||||
}
|
||||
this.logic.getServerSender().broadcast(new ServerStartGameMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,6 +180,9 @@ public void received(LobbyNotReadyMessage msg, int from) {
|
||||
*/
|
||||
@Override
|
||||
public void received(LeaveGameMessage msg, int from) {
|
||||
if (from == this.logic.getGame().getHost()) {
|
||||
this.logic.getServerSender().broadcast(new ShutdownMessage());
|
||||
}
|
||||
this.logic.getGame().removePlayer(from);
|
||||
this.logic.getServerSender().broadcast(new LobbyPlayerLeaveMessage(from));
|
||||
this.logic.getServerSender().disconnectClient(from);
|
||||
@@ -164,7 +199,7 @@ public void received(LeaveGameMessage msg, int from) {
|
||||
public void received(StartGameMessage msg, int from) {
|
||||
if (msg.isForceStartGame() || this.logic.getGame().allReady()) {
|
||||
this.initializeGame();
|
||||
this.logic.getServerSender().broadcast(new ServerStartGameMessage(this.logic.getGame().getBoard()));
|
||||
this.logic.getServerSender().broadcast(new ServerStartGameMessage());
|
||||
this.logic.setCurrentState(this.logic.getGameState());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
import pp.mdga.message.client.RequestDieMessage;
|
||||
import pp.mdga.message.server.ActivePlayerMessage;
|
||||
import pp.mdga.message.server.DieMessage;
|
||||
import pp.mdga.message.server.EndOfTurnMessage;
|
||||
import pp.mdga.server.ServerGameLogic;
|
||||
import pp.mdga.server.automaton.GameState;
|
||||
|
||||
@@ -69,6 +70,7 @@ public void received(RequestDieMessage msg, int from) {
|
||||
maximumRoll = entry.getValue();
|
||||
} else {
|
||||
this.playersHaveToRoll.remove(entry.getKey());
|
||||
this.logic.getServerSender().send(entry.getKey(), new EndOfTurnMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user