Fix color.next
This commit is contained in:
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
import com.jme3.network.serializing.Serializable;
|
import com.jme3.network.serializing.Serializable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This enumeration represents the four different TSK colors that a player can choose.
|
* This enumeration represents the four different TSK colors that a player can choose.
|
||||||
* Additionally, the NONE color indicates the absence of a color.
|
* Additionally, the NONE color indicates the absence of a color.
|
||||||
@@ -48,15 +50,16 @@ public static Color getColorByIndex(int index) {
|
|||||||
*
|
*
|
||||||
* @return color as a Color Enumeration.
|
* @return color as a Color Enumeration.
|
||||||
*/
|
*/
|
||||||
public Color next() {
|
public Color next(Game game) {
|
||||||
Color[] colors = values();
|
ArrayList<Color> colorsInGame = new ArrayList<>();
|
||||||
int nextIndex = (this.ordinal() + 1) % colors.length;
|
|
||||||
|
|
||||||
if (colors[nextIndex] == NONE) {
|
for(Player p : game.getPlayers().values()) {
|
||||||
nextIndex = (nextIndex + 1) % colors.length;
|
colorsInGame.add(p.getColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
return colors[nextIndex];
|
int nextIndex = (this.ordinal() + 1) % colorsInGame.size();
|
||||||
|
|
||||||
|
return colorsInGame.get(nextIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -35,12 +35,12 @@ public void enter() {
|
|||||||
LOGGER.log(System.Logger.Level.DEBUG, "Entered MovePieceState state.");
|
LOGGER.log(System.Logger.Level.DEBUG, "Entered MovePieceState state.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setActivePlayer(Color color) {
|
private void setActivePlayer(Color activePlayer) {
|
||||||
if (!logic.getGame().getPlayerByColor(color.next()).isFinished()) {
|
if (!logic.getGame().getPlayerByColor(activePlayer.next(logic.getGame())).isFinished()) {
|
||||||
logic.getGame().setActiveColor(logic.getGame().getActiveColor().next());
|
logic.getGame().setActiveColor(logic.getGame().getActiveColor().next(logic.getGame()));
|
||||||
logic.getServerSender().broadcast(new ActivePlayerMessage(color.next()));
|
logic.getServerSender().broadcast(new ActivePlayerMessage(activePlayer.next(logic.getGame())));
|
||||||
} else {
|
} else {
|
||||||
setActivePlayer(color.next());
|
setActivePlayer(activePlayer.next(logic.getGame()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,11 +23,11 @@ public NoTurnState(ChoosePieceState choosePieceAutomaton, ServerGameLogic logic)
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setActivePlayer(Color color) {
|
private void setActivePlayer(Color color) {
|
||||||
if (!logic.getGame().getPlayerByColor(color.next()).isFinished()) {
|
if (!logic.getGame().getPlayerByColor(color.next(logic.getGame())).isFinished()) {
|
||||||
logic.getGame().setActiveColor(logic.getGame().getActiveColor().next());
|
logic.getGame().setActiveColor(logic.getGame().getActiveColor().next(logic.getGame()));
|
||||||
logic.getServerSender().broadcast(new ActivePlayerMessage(color.next()));
|
logic.getServerSender().broadcast(new ActivePlayerMessage(color.next(logic.getGame())));
|
||||||
} else {
|
} else {
|
||||||
setActivePlayer(color.next());
|
setActivePlayer(color.next(logic.getGame()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public void received(RequestDieMessage msg, int from) {
|
|||||||
if (this.logic.getGame().getNumberOfActivePlayers() == 1) {
|
if (this.logic.getGame().getNumberOfActivePlayers() == 1) {
|
||||||
this.logic.getServerSender().broadcast(new CeremonyMessage());
|
this.logic.getServerSender().broadcast(new CeremonyMessage());
|
||||||
} else {
|
} else {
|
||||||
this.logic.getGame().setActiveColor(this.logic.getGame().getActiveColor().next());
|
this.logic.getGame().setActiveColor(this.logic.getGame().getActiveColor().next(logic.getGame()));
|
||||||
this.logic.getServerSender().broadcast(new ActivePlayerMessage(this.logic.getGame().getActiveColor()));
|
this.logic.getServerSender().broadcast(new ActivePlayerMessage(this.logic.getGame().getActiveColor()));
|
||||||
this.rollDiceAutomaton.getTurnAutomaton().getGameAutomaton().setCurrentState(this.rollDiceAutomaton.getTurnAutomaton().getGameAutomaton().getAnimationState());
|
this.rollDiceAutomaton.getTurnAutomaton().getGameAutomaton().setCurrentState(this.rollDiceAutomaton.getTurnAutomaton().getGameAutomaton().getAnimationState());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user