Fix: full model refactor
This commit is contained in:
@@ -84,7 +84,7 @@ public class Game implements Serializable {
|
||||
* @return {@code true} if the choice is applied successfully, {@code false} otherwise.
|
||||
*/
|
||||
public synchronized boolean totemChoice(Player player,Totems totem) {
|
||||
if(!currentState.getGameStage().equals(GameStages.TOTEM_CHOICE))
|
||||
if(currentState.getGameStage() != GameStages.TOTEM_CHOICE)
|
||||
return false;
|
||||
if(!getCurrentState().getCurrentPlayer().equals(player))
|
||||
return false;
|
||||
@@ -120,8 +120,18 @@ public class Game implements Serializable {
|
||||
|
||||
/**
|
||||
* Map tracking the players who are currently disconnected.
|
||||
* Key: player; value: {@code true} if currently disconnected, {@code false} if reconnected.
|
||||
*/
|
||||
public Map<Player,Boolean> disconnectedPlayers = new HashMap<>();
|
||||
private Map<Player,Boolean> disconnectedPlayers = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Returns an unmodifiable view of the disconnected-players map.
|
||||
*
|
||||
* @return map from player to disconnection status.
|
||||
*/
|
||||
public Map<Player,Boolean> getDisconnectedPlayers() {
|
||||
return Collections.unmodifiableMap(disconnectedPlayers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks the specified player as disconnected and updates the game flow accordingly.
|
||||
@@ -142,13 +152,13 @@ public class Game implements Serializable {
|
||||
return false;
|
||||
}
|
||||
disconnectedPlayers.put(player,true);
|
||||
if (currentState.getGameStage().equals(GameStages.WAITING)) {
|
||||
if (currentState.getGameStage() == GameStages.WAITING) {
|
||||
playersList.remove(player);
|
||||
totemChoiceQueue.remove(player);
|
||||
return true;
|
||||
}
|
||||
if(currentState.getCurrentPlayer().equals(player)) {
|
||||
if (!currentState.getGameStage().equals(GameStages.TOTEM_CHOICE)) {
|
||||
if (currentState.getGameStage() != GameStages.TOTEM_CHOICE) {
|
||||
nextPlayerSetup();
|
||||
return true;
|
||||
}
|
||||
@@ -184,15 +194,15 @@ public class Game implements Serializable {
|
||||
return false;
|
||||
}
|
||||
disconnectedPlayers.put(player,false);
|
||||
if(currentState.getGameStage().equals(GameStages.SLOT_CHOICE) )
|
||||
if(currentState.getGameStage() == GameStages.SLOT_CHOICE)
|
||||
{
|
||||
disconnectedPlayers.remove(player);
|
||||
if(!orderLogicCard.players.contains(player))
|
||||
if(!orderLogicCard.containsInQueue(player))
|
||||
{
|
||||
orderLogicCard.pushNoEffect(player);
|
||||
}
|
||||
}
|
||||
else if(currentState.getGameStage().equals(GameStages.RES_ACTIONS)) {
|
||||
else if(currentState.getGameStage() == GameStages.RES_ACTIONS) {
|
||||
if(slotMap.containsValue(player))
|
||||
{
|
||||
disconnectedPlayers.remove(player);
|
||||
@@ -247,7 +257,7 @@ public class Game implements Serializable {
|
||||
/**
|
||||
* The queue of players involved in optional card resolution.
|
||||
*/
|
||||
private Queue<Player> OptionalCardQueue;
|
||||
private Queue<Player> optionalCardQueue;
|
||||
|
||||
/**
|
||||
* The order logic card associated with this game.
|
||||
@@ -274,39 +284,39 @@ public class Game implements Serializable {
|
||||
public Board getBoard() {return board;}
|
||||
|
||||
/**
|
||||
* Returns clones of the upper tribe cards currently available on the board.
|
||||
* Returns a copy of the upper tribe cards currently available on the board.
|
||||
*
|
||||
* @return a list containing clones of the upper tribe cards currently available on the board.
|
||||
* @return a new list containing the upper tribe cards currently on the board.
|
||||
*/
|
||||
public ArrayList<TribeCard>getUpperListTribeCards() {
|
||||
return (ArrayList<TribeCard>)board.upperListTribe;
|
||||
public ArrayList<TribeCard> getUpperListTribeCards() {
|
||||
return new ArrayList<>(board.getUpperListTribe());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns clones of the lower tribe cards currently available on the board.
|
||||
* Returns a copy of the lower tribe cards currently available on the board.
|
||||
*
|
||||
* @return a list containing clones of the lower tribe cards currently available on the board.
|
||||
* @return a new list containing the lower tribe cards currently on the board.
|
||||
*/
|
||||
public ArrayList<TribeCard>getLowerListTribeCards() {
|
||||
return (ArrayList<TribeCard> )board.lowerListTribe;
|
||||
public ArrayList<TribeCard> getLowerListTribeCards() {
|
||||
return new ArrayList<>(board.getLowerListTribe());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns clones of the upper building cards currently available on the board.
|
||||
* Returns a copy of the upper building cards currently available on the board.
|
||||
*
|
||||
* @return a list containing clones of the upper building cards currently available on the board.
|
||||
* @return a new list containing the upper building cards currently on the board.
|
||||
*/
|
||||
public ArrayList<BuildingCard>getUpperListBuilding() {
|
||||
return (ArrayList<BuildingCard>)board.upperListBuilding;
|
||||
public ArrayList<BuildingCard> getUpperListBuilding() {
|
||||
return new ArrayList<>(board.getUpperListBuilding());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns clones of the lower building cards currently available on the board.
|
||||
* Returns a copy of the lower building cards currently available on the board.
|
||||
*
|
||||
* @return a list containing clones of the lower building cards currently available on the board.
|
||||
* @return a new list containing the lower building cards currently on the board.
|
||||
*/
|
||||
public ArrayList<BuildingCard>getLowerListBuilding() {
|
||||
return (ArrayList<BuildingCard>) board.lowerListBuilding;
|
||||
public ArrayList<BuildingCard> getLowerListBuilding() {
|
||||
return new ArrayList<>(board.getLowerListBuilding());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -316,7 +326,7 @@ public class Game implements Serializable {
|
||||
*/
|
||||
public CurrentState getCurrentState() {
|
||||
return currentState;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the player with the specified username, if present.
|
||||
@@ -357,7 +367,7 @@ public class Game implements Serializable {
|
||||
}
|
||||
currentState= new CurrentState();
|
||||
playersList = new ArrayList<>();
|
||||
OptionalCardQueue = new LinkedList<>();
|
||||
optionalCardQueue = new LinkedList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -482,7 +492,7 @@ public class Game implements Serializable {
|
||||
* @return {@code true} if the draw succeeds, {@code false} otherwise.
|
||||
*/
|
||||
public boolean drawUpperTribeCardByIndex(Player player,int cardIndex) {
|
||||
if( cardIndex<0 || cardIndex >=board.upperListTribe.size())
|
||||
if( cardIndex<0 || cardIndex >=board.getUpperListTribe().size())
|
||||
return false;
|
||||
if(currentState.getGameStage()!= GameStages.RES_ACTIONS && currentState.getGameStage()!=GameStages.OPT_CARD_E)
|
||||
{
|
||||
@@ -494,7 +504,7 @@ public class Game implements Serializable {
|
||||
}
|
||||
if(currentState.getNUpper() <1 && currentState.getGameStage()==GameStages.RES_ACTIONS)
|
||||
return false;
|
||||
TribeCard tribeCard = board.upperListTribe.get(cardIndex);
|
||||
TribeCard tribeCard = board.getUpperListTribe().get(cardIndex);
|
||||
if(tribeCard.isEventCard())
|
||||
return false;
|
||||
|
||||
@@ -525,7 +535,7 @@ public class Game implements Serializable {
|
||||
* @return {@code true} if the skip succeeds, {@code false} otherwise.
|
||||
*/
|
||||
public boolean skipTurn(Player player) {
|
||||
if(currentState.getGameStage()!= GameStages.RES_ACTIONS && !currentState.getGameStage().equals(GameStages.OPT_CARD_E))
|
||||
if(currentState.getGameStage() != GameStages.RES_ACTIONS && currentState.getGameStage() != GameStages.OPT_CARD_E)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -565,7 +575,7 @@ public class Game implements Serializable {
|
||||
* @return {@code true} if the draw succeeds, {@code false} otherwise.
|
||||
*/
|
||||
public boolean drawLowerTribeCardByIndex(Player player, int cardIndex) {
|
||||
if( cardIndex<0 || cardIndex >=board.lowerListTribe.size())
|
||||
if( cardIndex<0 || cardIndex >=board.getLowerListTribe().size())
|
||||
return false;
|
||||
if(currentState.getGameStage()!= GameStages.RES_ACTIONS)
|
||||
{
|
||||
@@ -579,7 +589,7 @@ public class Game implements Serializable {
|
||||
|
||||
if(currentState.getNLower() <1)
|
||||
return false;
|
||||
TribeCard tribeCard = board.lowerListTribe.get(cardIndex);
|
||||
TribeCard tribeCard = board.getLowerListTribe().get(cardIndex);
|
||||
if(tribeCard.isEventCard())
|
||||
return false;
|
||||
|
||||
@@ -606,7 +616,7 @@ public class Game implements Serializable {
|
||||
* @return {@code true} if the draw succeeds, {@code false} otherwise.
|
||||
*/
|
||||
public boolean drawUpperBuildingCardByIndex(Player player,int cardIndex) {
|
||||
if( cardIndex<0 || cardIndex >=board.upperListBuilding.size())
|
||||
if( cardIndex<0 || cardIndex >=board.getUpperListBuilding().size())
|
||||
return false;
|
||||
if(currentState.getGameStage()!= GameStages.RES_ACTIONS && currentState.getGameStage()!=GameStages.OPT_CARD_E)
|
||||
{
|
||||
@@ -616,7 +626,7 @@ public class Game implements Serializable {
|
||||
{
|
||||
return false;
|
||||
}
|
||||
BuildingCard buildingCard = board.upperListBuilding.get(cardIndex);
|
||||
BuildingCard buildingCard = board.getUpperListBuilding().get(cardIndex);
|
||||
if(currentState.getNUpper() <1 && currentState.getGameStage()==GameStages.RES_ACTIONS)
|
||||
return false;
|
||||
if(!buildingCard.buy(player))
|
||||
@@ -624,7 +634,7 @@ public class Game implements Serializable {
|
||||
return false;
|
||||
}
|
||||
board.removeUpperBuildingCard(buildingCard);
|
||||
if(currentState.getGameStage().equals(GameStages.RES_ACTIONS))
|
||||
if(currentState.getGameStage() == GameStages.RES_ACTIONS)
|
||||
{
|
||||
currentState.upperDrawn();
|
||||
if((currentState.getNLower() ==0 ||( !hasDrawableDown() && getLowerListBuilding().isEmpty())) && ((currentState.getNUpper() ==0)||(!hasDrawableUp() && getUpperListBuilding().isEmpty())))
|
||||
@@ -650,7 +660,7 @@ public class Game implements Serializable {
|
||||
* @return {@code true} if the draw succeeds, {@code false} otherwise.
|
||||
*/
|
||||
public boolean drawLowerBuildingCardByIndex(Player player,int cardIndex) {
|
||||
if( cardIndex<0 || cardIndex >=board.lowerListBuilding.size())
|
||||
if( cardIndex<0 || cardIndex >=board.getLowerListBuilding().size())
|
||||
return false;
|
||||
if(currentState.getGameStage()!= GameStages.RES_ACTIONS)
|
||||
{
|
||||
@@ -661,7 +671,7 @@ public class Game implements Serializable {
|
||||
{
|
||||
return false;
|
||||
}
|
||||
BuildingCard buildingCard = board.lowerListBuilding.get(cardIndex);
|
||||
BuildingCard buildingCard = board.getLowerListBuilding().get(cardIndex);
|
||||
if(currentState.getNLower() <1)
|
||||
return false;
|
||||
if(buildingCard.buy(player))
|
||||
@@ -788,7 +798,7 @@ public class Game implements Serializable {
|
||||
}
|
||||
|
||||
if (GameStages.OPT_CARD_E == currentState.getGameStage()) {
|
||||
Player optionalPlayer = OptionalCardQueue.poll();
|
||||
Player optionalPlayer = optionalCardQueue.poll();
|
||||
|
||||
if (optionalPlayer != null) {
|
||||
currentState.playerUpdate(optionalPlayer, null);
|
||||
@@ -821,7 +831,7 @@ public class Game implements Serializable {
|
||||
private synchronized void transitionToOptionalOrNextRound() {
|
||||
currentState.gameStageUpdate(GameStages.OPT_CARD_E);
|
||||
|
||||
OptionalCardQueue = new LinkedList<>();
|
||||
optionalCardQueue = new LinkedList<>();
|
||||
for (Player p :playersList) {
|
||||
long count = p.getBuildingCards().stream().filter(x -> x.getEffectId() == 12).count();
|
||||
if (count > 0) {
|
||||
@@ -829,11 +839,11 @@ public class Game implements Serializable {
|
||||
{
|
||||
continue;
|
||||
}
|
||||
OptionalCardQueue.add(p);
|
||||
optionalCardQueue.add(p);
|
||||
}
|
||||
}
|
||||
|
||||
Player optionalPlayer = OptionalCardQueue.poll();
|
||||
Player optionalPlayer = optionalCardQueue.poll();
|
||||
|
||||
if (optionalPlayer != null) {
|
||||
currentState.playerUpdate(optionalPlayer, null);
|
||||
@@ -847,8 +857,7 @@ public class Game implements Serializable {
|
||||
orderLogicCard.pushNoEffect(entry.getKey());
|
||||
disconnectedPlayers.remove(entry.getKey());
|
||||
} else {
|
||||
orderLogicCard.players.removeIf(x -> x.equals(entry.getKey()));
|
||||
orderLogicCard.playerList.removeIf(x -> x.player.equals(entry.getKey()));
|
||||
orderLogicCard.removeFromQueue(entry.getKey());
|
||||
}
|
||||
}
|
||||
currentState.playerUpdate(orderLogicCard.pull(), null);
|
||||
@@ -927,7 +936,7 @@ public class Game implements Serializable {
|
||||
*/
|
||||
private void endGame() {
|
||||
Queue<EventCard> events;
|
||||
events=Stream.concat(board.lowerListTribe.stream().filter(TribeCard::isEventCard),board.upperListTribe.stream().filter(TribeCard::isEventCard)).map(x->((EventCard)x)).collect(Collectors.toCollection(LinkedList::new));
|
||||
events=Stream.concat(board.getLowerListTribe().stream().filter(TribeCard::isEventCard),board.getUpperListTribe().stream().filter(TribeCard::isEventCard)).map(x->((EventCard)x)).collect(Collectors.toCollection(LinkedList::new));
|
||||
ArrayList<EventCard>sustenance=events.stream().filter(x->x.getType().equals(EventType.SUSTENANCE)).collect(Collectors.toCollection(ArrayList::new));
|
||||
events.removeAll(sustenance);
|
||||
events.forEach(event->event.activateEvent(playersList));
|
||||
@@ -985,7 +994,7 @@ public class Game implements Serializable {
|
||||
|
||||
currentState = new CurrentState();
|
||||
playersList = new ArrayList<>();
|
||||
OptionalCardQueue = new LinkedList<>();
|
||||
optionalCardQueue = new LinkedList<>();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user