Fix: minor bug

This commit is contained in:
2026-06-12 20:18:51 +02:00
parent 053f0048bc
commit 9a931bfc1b
21 changed files with 268 additions and 274 deletions
@@ -106,7 +106,7 @@ public class GameController {
Player player= model.getPlayerByUsername(playerUsername);
if(player==null)
return false;
return model.DrawUpperTribeCardByIndex(model.getPlayerByUsername(playerUsername),pos);
return model.drawUpperTribeCardByIndex(model.getPlayerByUsername(playerUsername),pos);
}
/**
@@ -122,7 +122,7 @@ public class GameController {
Player player= model.getPlayerByUsername(playerUsername);
if(player==null)
return false;
return model.DrawLowerTribeCardByIndex(model.getPlayerByUsername(playerUsername), pos);
return model.drawLowerTribeCardByIndex(model.getPlayerByUsername(playerUsername), pos);
}
/**
@@ -138,7 +138,7 @@ public class GameController {
Player player= model.getPlayerByUsername(playerUsername);
if(player==null)
return false;
return model.DrawUpperBuildingCardByIndex(model.getPlayerByUsername(playerUsername), pos);
return model.drawUpperBuildingCardByIndex(model.getPlayerByUsername(playerUsername), pos);
}
/**
@@ -154,7 +154,7 @@ public class GameController {
Player player= model.getPlayerByUsername(playerUsername);
if(player==null)
return false;
return model.DrawLowerBuildingCardByIndex(model.getPlayerByUsername(playerUsername), pos);
return model.drawLowerBuildingCardByIndex(model.getPlayerByUsername(playerUsername), pos);
}
@@ -187,7 +187,7 @@ public class GameController {
Player player= model.getPlayerByUsername(playerUsername);
if(player==null)
return false;
return model.SlotChoiceByIndex(model.getPlayerByUsername(playerUsername),pos);
return model.slotChoiceByIndex(model.getPlayerByUsername(playerUsername),pos);
}
/**
@@ -33,7 +33,7 @@ public class Building11 extends BuildingCard {
*
* @return the prestige multiplier associated with this building card effect.
*/
public int getprestigeMul() {return prestigeMul;}
public int getPrestigeMul() {return prestigeMul;}
/**
* Creates a Building11 card with the specified era, price, prestige value,
@@ -79,7 +79,7 @@ public class Building11 extends BuildingCard {
*/
@Override
public BuildingCard clone() {
return new Building11(getIdIMG(),getEra(),getPrice(),getPrestigeValue(), getIcon(), getprestigeMul());
return new Building11(getIdIMG(),getEra(),getPrice(),getPrestigeValue(), getIcon(), getPrestigeMul());
}
/**
@@ -94,7 +94,7 @@ public class Building11 extends BuildingCard {
public void applyEffect(Player player) throws IllegalArgumentException {
if(!player.getBuildingCards().contains(this))
throw new IllegalArgumentException();
player.addPrestige(player.getNType(getIcon()) * this.getprestigeMul());
player.addPrestige(player.getNType(getIcon()) * this.getPrestigeMul());
}
/**
@@ -79,7 +79,7 @@ public class Building4 extends BuildingCard {
}
for(Inventor inv : player.getInventors())
{
map.merge(inv.Icon(),1,Integer::sum);
map.merge(inv.getIcon(),1,Integer::sum);
}
numPair=0;
for(Integer i : map.values())
@@ -141,7 +141,7 @@ public class Building4 extends BuildingCard {
}
for(Inventor inv : player.getInventors())
{
map.merge(inv.Icon(),1,Integer::sum);
map.merge(inv.getIcon(),1,Integer::sum);
}
int temp=0;
for(Integer i : map.values())
@@ -20,7 +20,7 @@ public class Inventor extends Character {
*
* @return the icon value of this Inventor card.
*/
public int Icon() {
public int getIcon() {
return icon;
}
@@ -77,21 +77,21 @@ public class CavePaintings extends EventCard {
@Override
public void activateEvent (ArrayList <Player> playerList){
for (Player player : playerList){
int NArtists = player.getNType(CharacterType.ARTIST);
int NBuildings = 0;
int nArtists = player.getNType(CharacterType.ARTIST);
int nBuildings = 0;
ArrayList<BuildingCard> buildingCards = player.getBuildingCards();
for(BuildingCard card : buildingCards){
if(card.getEffectId() == 9){
NBuildings++;
nBuildings++;
}
}
player.addFood(NBuildings * NArtists);
if (NArtists < nLower){
player.addFood(nBuildings * nArtists);
if (nArtists < nLower){
player.removePrestige(nPrestigeRem);
}
else{
player.addPrestige(nPrestigeMul * NArtists);
player.addPrestige(nPrestigeMul * nArtists);
}
}
}
@@ -28,7 +28,7 @@ public class Sustenance extends EventCard {
*
* @return the prestige penalty multiplier associated with this Sustenance event.
*/
public int getprestigeDebt() {
public int getPrestigeDebt() {
return prestigeDebt;
}
@@ -71,30 +71,30 @@ public class Sustenance extends EventCard {
@Override
public void activateEvent (ArrayList <Player> playerList) throws NullPointerException {
for(Player player : playerList){
int NChar = player.getTotCharacters();
int NGatherers = player.getNType(CharacterType.GATHERER);
int nChar = player.getTotCharacters();
int nGatherers = player.getNType(CharacterType.GATHERER);
int NCharDiscount = 0;
int nCharDiscount = 0;
for(BuildingCard b : player.getBuildingCards()){
if(b.getEffectId() == 1){
CharacterType c = ((Building1)b).getIcon();
NCharDiscount += player.getNType(c);
nCharDiscount += player.getNType(c);
}
}
int FoodDebt = NChar - (FOOD_PER_GATHERER * NGatherers + NCharDiscount);
int foodDebt = nChar - (FOOD_PER_GATHERER * nGatherers + nCharDiscount);
if(FoodDebt <= 0){
if(foodDebt <= 0){
continue;
}
if(player.getFoodValue() >= FoodDebt){
player.removeFood(FoodDebt);
if(player.getFoodValue() >= foodDebt){
player.removeFood(foodDebt);
}
else{
FoodDebt -= player.getFoodValue();
foodDebt -= player.getFoodValue();
player.removeFood(player.getFoodValue()); // player.getFoodValue() == 0
player.removePrestige(FoodDebt * prestigeDebt);
player.removePrestige(foodDebt * prestigeDebt);
}
}
}
@@ -97,8 +97,8 @@ public class Game implements Serializable {
if(nextPlayer==null)
{
currentState.GameStageUpdate(GameStages.SLOT_CHOICE);
currentState.PlayerUpdate(orderLogicCard.pull(),null);
currentState.gameStageUpdate(GameStages.SLOT_CHOICE);
currentState.playerUpdate(orderLogicCard.pull(),null);
}
else
{
@@ -108,12 +108,12 @@ public class Game implements Serializable {
nextPlayer=totemChoiceQueue.poll();
if(nextPlayer==null)
{
currentState.GameStageUpdate(GameStages.SLOT_CHOICE);
currentState.PlayerUpdate(orderLogicCard.pull(),null);
currentState.gameStageUpdate(GameStages.SLOT_CHOICE);
currentState.playerUpdate(orderLogicCard.pull(),null);
return true;
}
}
currentState.PlayerUpdate(nextPlayer,null);
currentState.playerUpdate(nextPlayer,null);
}
return true;
}
@@ -158,7 +158,7 @@ public class Game implements Serializable {
} else {
totemChoiceQueue.add(player);
}
currentState.PlayerUpdate(totemChoiceQueue.poll(), null);
currentState.playerUpdate(totemChoiceQueue.poll(), null);
return true;
}
}
@@ -204,7 +204,7 @@ public class Game implements Serializable {
/**
* Clears the collection of disconnected players.
*/
public synchronized void ClearDisconnected()
public synchronized void clearDisconnected()
{
disconnectedPlayers.clear();
}
@@ -428,8 +428,8 @@ public class Game implements Serializable {
}
}
currentState.PlayerUpdate(totemChoiceQueue.poll(),null);
currentState.GameStageUpdate(GameStages.TOTEM_CHOICE);
currentState.playerUpdate(totemChoiceQueue.poll(),null);
currentState.gameStageUpdate(GameStages.TOTEM_CHOICE);
}
//region Controller Methods
@@ -444,7 +444,7 @@ public class Game implements Serializable {
* @param slotIndex the index of the selected slot.
* @return {@code true} if the slot choice succeeds, {@code false} otherwise.
*/
public boolean SlotChoiceByIndex(Player player, int slotIndex) {
public boolean slotChoiceByIndex(Player player, int slotIndex) {
if(slotIndex<0 || slotIndex>=slotMap.size())
return false;
if(currentState.getGameStage()!= GameStages.SLOT_CHOICE)
@@ -481,7 +481,7 @@ public class Game implements Serializable {
* @param cardIndex the index of the upper tribe card to draw.
* @return {@code true} if the draw succeeds, {@code false} otherwise.
*/
public boolean DrawUpperTribeCardByIndex(Player player,int cardIndex) {
public boolean drawUpperTribeCardByIndex(Player player,int cardIndex) {
if( cardIndex<0 || cardIndex >=board.upperListTribe.size())
return false;
if(currentState.getGameStage()!= GameStages.RES_ACTIONS && currentState.getGameStage()!=GameStages.OPT_CARD_E)
@@ -503,7 +503,7 @@ public class Game implements Serializable {
board.removeUpperTribeCard(tempCard);
if(currentState.getGameStage()==GameStages.RES_ACTIONS)
{
currentState.UpperDrawn();
currentState.upperDrawn();
if((currentState.getNLower() ==0 ||( !hasDrawableDown() && getLowerListBuilding().isEmpty())) && ((currentState.getNUpper() ==0)||(!hasDrawableUp() && getUpperListBuilding().isEmpty())))
nextPlayerSetup();
}
@@ -540,9 +540,9 @@ public class Game implements Serializable {
if(hasDrawableUp() && currentState.getNUpper()>0)
return false;
while(currentState.getNLower()>0)
currentState.LowerDrawn();
currentState.lowerDrawn();
while(currentState.getNUpper()>0)
currentState.UpperDrawn();
currentState.upperDrawn();
nextPlayerSetup();
}
else {
@@ -564,7 +564,7 @@ public class Game implements Serializable {
* @param cardIndex the index of the lower tribe card to draw.
* @return {@code true} if the draw succeeds, {@code false} otherwise.
*/
public boolean DrawLowerTribeCardByIndex(Player player, int cardIndex) {
public boolean drawLowerTribeCardByIndex(Player player, int cardIndex) {
if( cardIndex<0 || cardIndex >=board.lowerListTribe.size())
return false;
if(currentState.getGameStage()!= GameStages.RES_ACTIONS)
@@ -586,7 +586,7 @@ public class Game implements Serializable {
Character tempCard = (Character) tribeCard;
tempCard.insert(player);
board.removeLowerTribeCard(tempCard);
currentState.LowerDrawn();
currentState.lowerDrawn();
if((currentState.getNLower() ==0 ||( !hasDrawableDown() && getLowerListBuilding().isEmpty())) && ((currentState.getNUpper() ==0)||(!hasDrawableUp() && getUpperListBuilding().isEmpty())))
nextPlayerSetup();
return true;
@@ -605,7 +605,7 @@ public class Game implements Serializable {
* @param cardIndex the index of the upper building card to draw.
* @return {@code true} if the draw succeeds, {@code false} otherwise.
*/
public boolean DrawUpperBuildingCardByIndex(Player player,int cardIndex) {
public boolean drawUpperBuildingCardByIndex(Player player,int cardIndex) {
if( cardIndex<0 || cardIndex >=board.upperListBuilding.size())
return false;
if(currentState.getGameStage()!= GameStages.RES_ACTIONS && currentState.getGameStage()!=GameStages.OPT_CARD_E)
@@ -626,7 +626,7 @@ public class Game implements Serializable {
board.removeUpperBuildingCard(buildingCard);
if(currentState.getGameStage().equals(GameStages.RES_ACTIONS))
{
currentState.UpperDrawn();
currentState.upperDrawn();
if((currentState.getNLower() ==0 ||( !hasDrawableDown() && getLowerListBuilding().isEmpty())) && ((currentState.getNUpper() ==0)||(!hasDrawableUp() && getUpperListBuilding().isEmpty())))
nextPlayerSetup();
}
@@ -649,7 +649,7 @@ public class Game implements Serializable {
* @param cardIndex the index of the lower building card to draw.
* @return {@code true} if the draw succeeds, {@code false} otherwise.
*/
public boolean DrawLowerBuildingCardByIndex(Player player,int cardIndex) {
public boolean drawLowerBuildingCardByIndex(Player player,int cardIndex) {
if( cardIndex<0 || cardIndex >=board.lowerListBuilding.size())
return false;
if(currentState.getGameStage()!= GameStages.RES_ACTIONS)
@@ -666,7 +666,7 @@ public class Game implements Serializable {
return false;
if(buildingCard.buy(player))
{
currentState.LowerDrawn();
currentState.lowerDrawn();
board.removeLowerBuildingCard(buildingCard);
}
else
@@ -713,12 +713,12 @@ public class Game implements Serializable {
if (!disconnectedPlayers.containsKey(tempPlayer) || !disconnectedPlayers.get(tempPlayer)) break;
}
if (tempPlayer != null) {
currentState.PlayerUpdate(tempPlayer, null);
currentState.playerUpdate(tempPlayer, null);
return;
}
// All players have chosen a slot → switch to RES_ACTIONS
currentState.GameStageUpdate(GameStages.RES_ACTIONS);
currentState.gameStageUpdate(GameStages.RES_ACTIONS);
boolean anyAssigned = false;
for (Map.Entry<Slot,Player> entry : slotMap.entrySet()) {
@@ -730,7 +730,7 @@ public class Game implements Serializable {
entry.setValue(null);
continue;
}
currentState.PlayerUpdate(entry.getValue(), entry.getKey());
currentState.playerUpdate(entry.getValue(), entry.getKey());
boolean hasDrawableLower = currentState.getNLower() > 0
&& (hasDrawableDown() || !getLowerListBuilding().isEmpty());
boolean hasDrawableUpper = currentState.getNUpper() > 0
@@ -766,7 +766,7 @@ public class Game implements Serializable {
entry.setValue(null);
continue;
}
currentState.PlayerUpdate(entry.getValue(), entry.getKey());
currentState.playerUpdate(entry.getValue(), entry.getKey());
boolean hasDrawableLower = currentState.getNLower() > 0
&& (hasDrawableDown() || !getLowerListBuilding().isEmpty());
boolean hasDrawableUpper = currentState.getNUpper() > 0
@@ -791,21 +791,21 @@ public class Game implements Serializable {
Player optionalPlayer = OptionalCardQueue.poll();
if (optionalPlayer != null) {
currentState.PlayerUpdate(optionalPlayer, null);
currentState.playerUpdate(optionalPlayer, null);
if(disconnectedPlayers.containsKey(currentState.getCurrentPlayer())&& disconnectedPlayers.get(currentState.getCurrentPlayer())) {
nextPlayerSetup();
}
return;
}
currentState.GameStageUpdate(GameStages.RES_EVENT);
currentState.gameStageUpdate(GameStages.RES_EVENT);
if (currentState.getRound() < 10) {
nextRound();
currentState.PlayerUpdate(orderLogicCard.pull(), null);
currentState.GameStageUpdate(GameStages.SLOT_CHOICE);
currentState.playerUpdate(orderLogicCard.pull(), null);
currentState.gameStageUpdate(GameStages.SLOT_CHOICE);
} else {
currentState.GameStageUpdate(GameStages.ENDING);
currentState.gameStageUpdate(GameStages.ENDING);
endGame();
}
}
@@ -819,7 +819,7 @@ public class Game implements Serializable {
* is set to {@link GameStages#SLOT_CHOICE}; if round 10 has been completed, the game ends.
*/
private synchronized void transitionToOptionalOrNextRound() {
currentState.GameStageUpdate(GameStages.OPT_CARD_E);
currentState.gameStageUpdate(GameStages.OPT_CARD_E);
OptionalCardQueue = new LinkedList<>();
for (Player p :playersList) {
@@ -836,29 +836,25 @@ public class Game implements Serializable {
Player optionalPlayer = OptionalCardQueue.poll();
if (optionalPlayer != null) {
currentState.PlayerUpdate(optionalPlayer, null);
currentState.playerUpdate(optionalPlayer, null);
return;
}
if (currentState.getRound() < 10) {
nextRound();
for(Map.Entry<Player,Boolean> entry: disconnectedPlayers.entrySet())
{
if(!entry.getValue())
{
for (Map.Entry<Player, Boolean> entry : new ArrayList<>(disconnectedPlayers.entrySet())) {
if (!entry.getValue()) {
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()));
} else {
orderLogicCard.players.removeIf(x -> x.equals(entry.getKey()));
orderLogicCard.playerList.removeIf(x -> x.player.equals(entry.getKey()));
}
}
currentState.PlayerUpdate(orderLogicCard.pull(), null);
currentState.GameStageUpdate(GameStages.SLOT_CHOICE);
currentState.playerUpdate(orderLogicCard.pull(), null);
currentState.gameStageUpdate(GameStages.SLOT_CHOICE);
} else {
currentState.GameStageUpdate(GameStages.ENDING);
currentState.gameStageUpdate(GameStages.ENDING);
endGame();
}
}
@@ -888,9 +884,9 @@ public class Game implements Serializable {
* All pending events are activated on the player list.
* Event cards of type {@code SUSTENANCE} are resolved after all other pending events.
*/
private void EventResolution() {
private void eventResolution() {
currentState.GameStageUpdate(GameStages.RES_EVENT);
currentState.gameStageUpdate(GameStages.RES_EVENT);
Queue<EventCard> events;
events=board.getPendingEvents();
ArrayList<EventCard>sustenance=events.stream().filter(x->x.getType().equals(EventType.SUSTENANCE)).collect(Collectors.toCollection(ArrayList::new));
@@ -916,12 +912,12 @@ public class Game implements Serializable {
*/
private void nextRound() {
EventResolution();
eventResolution();
if(currentState.getEra()!= board.nextRound()) {
currentState.EraUpdate();
currentState.eraUpdate();
}
currentState.RoundUpdate();
currentState.roundUpdate();
}
@@ -942,7 +938,7 @@ public class Game implements Serializable {
p.addPrestige(temp);
});
playersList.forEach(p->{
int temp=(int) p.getInventors().stream().mapToInt(Inventor::Icon).distinct().count();
int temp=(int) p.getInventors().stream().mapToInt(Inventor::getIcon).distinct().count();
p.addPrestige(temp*p.getNType(CharacterType.INVENTOR));
});
playersList.forEach(p->{
@@ -956,7 +952,7 @@ public class Game implements Serializable {
p -> p.getBuildingCards().stream().filter(x -> x.getEffectType() == EffectType.FINAL).
forEach(x -> x.applyEffect(p))
);
currentState.GameStageUpdate(GameStages.ENDED);
currentState.gameStageUpdate(GameStages.ENDED);
playerStanding=new ArrayList<>(playersList);
playerStanding.sort((y,x)->x.getPrestigeValue()==y.getPrestigeValue()?Integer.compare(x.getFoodValue(),y.getFoodValue()):Integer.compare(x.getPrestigeValue(),y.getPrestigeValue()));
@@ -1006,7 +1002,7 @@ public class Game implements Serializable {
.filter(x -> !disconnectedPlayers.containsKey(x) || !disconnectedPlayers.get(x))
.findFirst().orElse(null);
if (winner == null) return;
currentState.GameStageUpdate(GameStages.ENDED);
currentState.gameStageUpdate(GameStages.ENDED);
playerStanding = new ArrayList<>(playersList);
playerStanding.remove(winner);
playerStanding.sort((y, x) -> x.getPrestigeValue() == y.getPrestigeValue()
@@ -49,7 +49,7 @@ public class CurrentState implements Serializable {
/**
* The current era of the game.
*/
private int Era;
private int era;
/**
* Returns the current era of the game.
@@ -57,7 +57,7 @@ public class CurrentState implements Serializable {
* @return the current era of the game.
*/
public int getEra(){
return Era;
return era;
}
/**
@@ -105,7 +105,7 @@ public class CurrentState implements Serializable {
/**
* The current stage of the game.
*/
private GameStages GameStage;
private GameStages gameStage;
/**
* Returns the current stage of the game.
@@ -113,7 +113,7 @@ public class CurrentState implements Serializable {
* @return the current stage of the game.
*/
public GameStages getGameStage(){
return GameStage;
return gameStage;
}
// endregion getters
@@ -123,28 +123,28 @@ public class CurrentState implements Serializable {
/**
* Increments the current era by 1.
*/
public void EraUpdate(){
Era++;
public void eraUpdate(){
era++;
}
/**
* Increments the current round by 1.
*/
public void RoundUpdate(){
public void roundUpdate(){
round++;
}
/**
* Decrements the number of upper cards by 1.
*/
public void UpperDrawn(){
public void upperDrawn(){
nUpper--;
}
/**
* Decrements the number of lower cards by 1.
*/
public void LowerDrawn(){
public void lowerDrawn(){
nLower--;
}
@@ -153,8 +153,8 @@ public class CurrentState implements Serializable {
*
* @param GameStage the new game stage.
*/
public void GameStageUpdate(GameStages GameStage){
this.GameStage = GameStage;
public void gameStageUpdate(GameStages gameStage){
this.gameStage = gameStage;
}
// endregion setters
@@ -168,11 +168,11 @@ public class CurrentState implements Serializable {
public CurrentState(){
this.player = null;
this.slot = null;
this.Era = 1;
this.era = 1;
this.round = 1;
this.nUpper = 0;
this.nLower = 0;
this.GameStage = GameStages.WAITING;
this.gameStage = GameStages.WAITING;
}
// endregion constructors
@@ -186,7 +186,7 @@ public class CurrentState implements Serializable {
* @param player the new current player.
* @param slot the new current slot.
*/
public void PlayerUpdate(Player player, Slot slot){
public void playerUpdate(Player player, Slot slot){
this.player = player;
this.slot = slot;
if(slot == null){
@@ -212,8 +212,8 @@ public class CurrentState implements Serializable {
List<String>values= new ArrayList<>();
values.add(player.getUserName());
values.add(Integer.toString(round));
values.add(Integer.toString(Era));
values.add(GameStage.toString());
values.add(Integer.toString(era));
values.add(gameStage.toString());
table.addRow(values);
return table.build();
}
@@ -25,7 +25,7 @@ public abstract class PlayableCard implements Serializable {
/**
* The era associated with this playable card.
*/
private int Era;
private int era;
/**
* Returns the era of this playable card.
@@ -33,7 +33,7 @@ public abstract class PlayableCard implements Serializable {
* @return the era of this playable card.
*/
public int getEra(){
return Era;
return era;
}
/**
@@ -45,7 +45,7 @@ public abstract class PlayableCard implements Serializable {
public PlayableCard (int Era) throws IllegalArgumentException{
idIMG="-1";
if (Era>0 && Era<4) {
this.Era = Era;
this.era = Era;
} else {
throw new IllegalArgumentException();
}
@@ -61,7 +61,7 @@ public abstract class PlayableCard implements Serializable {
public PlayableCard (String idIMG,int Era) throws IllegalArgumentException{
this.idIMG = idIMG;
if (Era>0 && Era<4) {
this.Era = Era;
this.era = Era;
} else {
throw new IllegalArgumentException();
}
@@ -34,14 +34,14 @@ public class Player implements Serializable {
* exceed {@link #MAX_VALUE} otherwise an {@link IllegalArgumentException} will be thrown
* when the {@link #Player(String) constructor} is called.
*/
private final String UserName;
private final String userName;
/**
* Getter for the private attribute {@link #UserName}.
* Getter for the private attribute {@link #userName}.
* @return {@code String} - The UserName
*/
public String getUserName() {
return UserName;
return userName;
}
/**
@@ -107,27 +107,27 @@ public class Player implements Serializable {
* The current amount of {@code Food} the Player possesses.
* Cannot be negative.
*/
private int FoodValue;
private int foodValue;
/**
* Getter for the private attribute {@link #FoodValue}.
* Getter for the private attribute {@link #foodValue}.
* @return {@code int} - The amount of Food the player possesses.
*/
public int getFoodValue() {
return FoodValue;
return foodValue;
}
/**
* The current amount of {@code Prestige} the Player possesses.
*/
private int PrestigeValue;
private int prestigeValue;
/**
* Getter for the private attribute {@link #PrestigeValue}.
* Getter for the private attribute {@link #prestigeValue}.
* @return {@code int} - The amount of Prestige the Player possesses.
*/
public int getPrestigeValue() {
return PrestigeValue;
return prestigeValue;
}
// endregion getters
@@ -136,14 +136,14 @@ public class Player implements Serializable {
/**
* Adds {@code Value} amount of {@code Food} to the Player.
* @param Value The amount of {@code Food} to be added.
* @param value The amount of {@code Food} to be added.
* Should be positive for expected results
* (otherwise the method will subtract the absolute
* value of {@code Value}).
* @see #FoodValue
* @see #foodValue
*/
public void addFood(int Value){
this.FoodValue += Value;
public void addFood(int value){
this.foodValue += value;
}
/**
@@ -157,50 +157,50 @@ public class Player implements Serializable {
/**
* Removes {@code Value} amount of {@code Food} from the Player.
* Note: {@link #FoodValue} cannot be negative, so the method returns
* Note: {@link #foodValue} cannot be negative, so the method returns
* {@code false} if {@code Value} is greater than the amount of {@code Food}
* the Player possesses, and {@code true} otherwise.
*
* @param Value The amount of {@code Food} to be removed.
* @param value The amount of {@code Food} to be removed.
* Should be positive for expected results
* (otherwise the method will add the absolute
* value of {@code Value}).
* @return {@code Boolean} - {@code true} if the Food is successfully removed,
* {@code false} otherwise.
* @see #FoodValue
* @see #foodValue
*/
public Boolean removeFood(int Value){
if(Value > this.FoodValue){
public Boolean removeFood(int value){
if(value > this.foodValue){
return false;
}
this.FoodValue -= Value;
this.foodValue -= value;
return true;
}
/**
* Adds {@code Value} amount of {@code Prestige} to the Player.
* @param Value The amount of {@code Prestige} to be added.
* @param value The amount of {@code Prestige} to be added.
* Should be positive for expected results
* (otherwise the method will subtract the absolute
* value of {@code Value}).
* @see #PrestigeValue
* @see #prestigeValue
*/
public void addPrestige(int Value){
public void addPrestige(int value){
this.PrestigeValue += Value;
this.prestigeValue += value;
}
/**
* Removes {@code Value} amount of {@code Prestige} to the Player.
* @param Value The amount of {@code Prestige} to be removed.
* @param value The amount of {@code Prestige} to be removed.
* Should be positive for expected results
* (otherwise the method will add the absolute
* value of {@code Value}).
* @see #PrestigeValue
* @see #prestigeValue
*/
public void removePrestige(int Value){
public void removePrestige(int value){
this.PrestigeValue -= Value;
this.prestigeValue -= value;
}
// endregion setters
@@ -208,21 +208,21 @@ public class Player implements Serializable {
// region Constructors
/**
* Constructor for the class {@code Player}. Each Player is uniquely identified by the {@link #UserName}.
* Constructor for the class {@code Player}. Each Player is uniquely identified by the {@link #userName}.
*
* @param UserName Unique String identifier for a Player.
* @param userName Unique String identifier for a Player.
* @throws IllegalArgumentException when {@code UserName} is empty or exceeds {@link #MAX_VALUE},
* with message:
* <pre>{@code UserName is empty or exceeds maximum permitted length.}</pre>
*
* @see #UserName
* @see #userName
* @see #MAX_VALUE
*/
public Player(String UserName) throws IllegalArgumentException {
if(UserName.isEmpty() || UserName.length() > MAX_VALUE) {
public Player(String userName) throws IllegalArgumentException {
if(userName.isEmpty() || userName.length() > MAX_VALUE) {
throw new IllegalArgumentException("UserName is empty or exceeds maximum permitted length.");
}
this.UserName = UserName;
this.userName = userName;
this.inventors = new ArrayList <>();
this.builders = new ArrayList <>();
@@ -232,8 +232,8 @@ public class Player implements Serializable {
this.artists = new ArrayList<>();
this.buildingCards = new ArrayList<>();
this.FoodValue = 0;
this.PrestigeValue = 0;
this.foodValue = 0;
this.prestigeValue = 0;
this.totem = null;
}
// endregion constructors
@@ -244,20 +244,20 @@ public class Player implements Serializable {
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof Player)) return false;
return UserName.equals(((Player) obj).UserName);
return userName.equals(((Player) obj).userName);
}
@Override
public int hashCode() {
return UserName.hashCode();
return userName.hashCode();
}
/**
* Prints the {@code Player}'s attributes for the {@code Board}'s representation.
* Uses the {@code UNICODE} border style.
* <p><b>Includes:</b>
* <li>{@link #FoodValue Food}
* <li>{@link #PrestigeValue Prestige}
* <li>{@link #foodValue Food}
* <li>{@link #prestigeValue Prestige}
* <li>{@link #artists Artists}
* <li>{@link #builders Builders}
* <li>{@link #gatherers Gatherers}
@@ -271,7 +271,7 @@ public class Player implements Serializable {
*/
@Override
public String toString() {
int Last = -1;
int last = -1;
var table = new AsciiTable(ROUNDED, 1);
@@ -280,55 +280,55 @@ public class Player implements Serializable {
table.addSeparator();
if(!this.hunters.isEmpty()){
Last = 6;
last = 6;
}
else if(!this.inventors.isEmpty()){
Last = 5;
last = 5;
}
else if(!this.shamans.isEmpty()){
Last = 4;
last = 4;
}
else if(!this.gatherers.isEmpty()){
Last = 3;
last = 3;
}
else if(!this.builders.isEmpty()){
Last = 2;
last = 2;
}
else if(!this.artists.isEmpty()){
Last = 1;
last = 1;
}
else{
Last = 0;
last = 0;
}
if(Last == 0){
if(last == 0){
table.addSeparator();
}
table.addRow("CHARACTERS");
if(!this.artists.isEmpty()){
table.addRow(this.artists.size() + " Artists: \uD83C\uDFA8:" + this.artists.size());
if(Last == 1){
if(last == 1){
table.addSeparator();
}
}
if(!this.builders.isEmpty()){
table.addRow(this.builders.size() + " Builders: " + "\uD83D\uDD28:" + this.builders.stream().mapToInt(Builder::getReductionValue).sum() + " \uD83C\uDFC5:" + this.builders.stream().mapToInt(Builder::getPrestigeValue).sum());
if(Last == 2){
if(last == 2){
table.addSeparator();
}
}
if(!this.gatherers.isEmpty()){
table.addRow(this.gatherers.size() + " Gatherers: -\uD83E\uDD57:" + 3*this.gatherers.size());
if(Last == 3){
if(last == 3){
table.addSeparator();
}
}
if(!this.shamans.isEmpty()){
table.addRow(this.shamans.size() + " Shamans: " + "\uD83C\uDF1F:" + this.shamans.stream().mapToInt(Shaman::getIcon).sum());
if(Last == 4){
if(last == 4){
table.addSeparator();
}
}
@@ -336,14 +336,14 @@ public class Player implements Serializable {
if(!this.inventors.isEmpty()){
table.addRow(this.inventors.size() + " Inventors: " + this.inventors.stream()
.collect(Collectors.groupingBy(
Inventor::Icon,
Inventor::getIcon,
Collectors.counting()
))
.entrySet().stream()
.sorted(Map.Entry.comparingByKey())
.map(e -> e.getKey() + ":" + e.getValue())
.collect(Collectors.joining(", ")));
if(Last == 5){
if(last == 5){
table.addSeparator();
}
}
@@ -56,18 +56,17 @@ public class DisconnectedPlayer extends NetworkEvent implements Serializable{
*/
@Override
public boolean apply(MiniModel miniModel){
if (miniModel == null) return true;
synchronized (miniModel) {
if (isError)
return false;
if (miniModel != null) {
miniModel.setPlayers(playerList);
miniModel.setOrderLogicCard(orderLogicCard);
miniModel.setCurrentState(currentState);
miniModel.setSlotPlayerMap(slotPlayerMap);
miniModel.setDisconnectedPlayers(disconnectedPlayers);
miniModel.setAvailableTotems(availableTotems);
miniModel.setLastEvent(this);
}
miniModel.setPlayers(playerList);
miniModel.setOrderLogicCard(orderLogicCard);
miniModel.setCurrentState(currentState);
miniModel.setSlotPlayerMap(slotPlayerMap);
miniModel.setDisconnectedPlayers(disconnectedPlayers);
miniModel.setAvailableTotems(availableTotems);
miniModel.setLastEvent(this);
return true;
}
}
@@ -54,19 +54,16 @@ public class ReconnectPlayer extends NetworkEvent implements Serializable {
*/
@Override
public boolean apply(MiniModel miniModel) {
if (miniModel == null) return true;
synchronized (miniModel) {
if (isError)
return false;
if (miniModel != null) {
miniModel.setPlayers(playerList);
miniModel.setOrderLogicCard(orderLogicCard);
miniModel.setCurrentState(currentState);
miniModel.setSlotPlayerMap(slotPlayerMap);
miniModel.setDisconnectedPlayers(disconnectedPlayers);
miniModel.setLastEvent(this);
}
miniModel.setPlayers(playerList);
miniModel.setOrderLogicCard(orderLogicCard);
miniModel.setCurrentState(currentState);
miniModel.setSlotPlayerMap(slotPlayerMap);
miniModel.setDisconnectedPlayers(disconnectedPlayers);
miniModel.setLastEvent(this);
return true;
}
}
@@ -156,7 +156,7 @@ public class TCPClient implements IClient {
sender.shutdownNow();
}
}
private void disconnect() {
private synchronized void disconnect() {
if (!running) return;
running = false;
try { communicationSocket.close(); } catch (IOException ignored) {}
@@ -139,7 +139,8 @@ public class ClientHandler implements Runnable {
* The player is marked as disconnected, a {@link DisconnectedPlayer} event is
* added to the action queue, and the associated socket is closed.
*/
public void disconnect() {
public synchronized void disconnect() {
if (!running) return;
running = false;
clientHandlers.remove(this);
limitedMap.put(username, false);
@@ -182,6 +182,7 @@ public class GUI extends Application implements IView {
*/
public void render() {
Platform.runLater(() -> {
if (miniModel == null) return;
synchronized (miniModel) {
if (controller.miniModel.currentState.getGameStage() == TOTEM_CHOICE) {
controllerTotem.render();
@@ -260,10 +261,10 @@ public class GUI extends Application implements IView {
controllerLogin.showError(error);
fadeToScene(loginScene);
} else {
if (miniModel == null) return;
synchronized (miniModel) {
controllerMain.isError = true;
controllerMain.render();
}
}
});
@@ -249,13 +249,13 @@ public class MainFXMLController {
HBox prestigeBox = new HBox(1);
prestigeBox.setAlignment(Pos.CENTER);
ImageView PPIcon = new ImageView(loadImage("/GUIImages/Icons/PrestigePoint.png"));
PPIcon.setFitHeight(35);
PPIcon.setPreserveRatio(true);
ImageView ppIcon = new ImageView(loadImage("/GUIImages/Icons/PrestigePoint.png"));
ppIcon.setFitHeight(35);
ppIcon.setPreserveRatio(true);
Label prestigeLabel = new Label(String.valueOf(player.getPrestigeValue()));
prestigeLabel.getStyleClass().add("label-small");
prestigeLabels.put(player.getUserName(), prestigeLabel);
prestigeBox.getChildren().addAll(PPIcon, prestigeLabel);
prestigeBox.getChildren().addAll(ppIcon, prestigeLabel);
ImageView buildingIcon = new ImageView(loadImage("/GUIImages/Icons/Building.png"));
buildingIcon.setFitWidth(28);