Fix: full controller refactor
This commit is contained in:
@@ -258,8 +258,8 @@ public class ClientLauncherTUI {
|
|||||||
gameReader.printAbove("Usage: details buildings | details events | details characters");
|
gameReader.printAbove("Usage: details buildings | details events | details characters");
|
||||||
}
|
}
|
||||||
case "rematch" -> {
|
case "rematch" -> {
|
||||||
if (controller.miniModel == null
|
if (controller.getMiniModel() == null
|
||||||
|| !controller.miniModel.currentState.getGameStage().equals(GameStages.ENDED)) {
|
|| !controller.getMiniModel().currentState.getGameStage().equals(GameStages.ENDED)) {
|
||||||
System.out.println("Game not ended yet. Use 'quit' to disconnect.");
|
System.out.println("Game not ended yet. Use 'quit' to disconnect.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,16 +15,16 @@ import it.polimi.ingsw.gc14.View.IView;
|
|||||||
public class ClientController {
|
public class ClientController {
|
||||||
|
|
||||||
/** Local mini model representing the client-side game state. */
|
/** Local mini model representing the client-side game state. */
|
||||||
public MiniModel miniModel;
|
private MiniModel miniModel;
|
||||||
|
|
||||||
/** View of the client. */
|
/** View of the client. */
|
||||||
public IView view;
|
private IView view;
|
||||||
|
|
||||||
/** Network client, either TCP or RMI. */
|
/** Network client, either TCP or RMI. */
|
||||||
private IClient client;
|
private IClient client;
|
||||||
|
|
||||||
/** Username associated with this client. */
|
/** Username associated with this client. */
|
||||||
public String myUsername;
|
private String myUsername;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a client controller with the specified view.
|
* Constructs a client controller with the specified view.
|
||||||
@@ -39,6 +39,33 @@ public class ClientController {
|
|||||||
this.client = null;
|
this.client = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the local mini model.
|
||||||
|
*
|
||||||
|
* @return the local mini model.
|
||||||
|
*/
|
||||||
|
public MiniModel getMiniModel() {
|
||||||
|
return miniModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the client view.
|
||||||
|
*
|
||||||
|
* @return the client view.
|
||||||
|
*/
|
||||||
|
public IView getView() {
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the username associated with this client.
|
||||||
|
*
|
||||||
|
* @return the username.
|
||||||
|
*/
|
||||||
|
public String getMyUsername() {
|
||||||
|
return myUsername;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the network client.
|
* Sets the network client.
|
||||||
*
|
*
|
||||||
@@ -80,8 +107,7 @@ public class ClientController {
|
|||||||
/**
|
/**
|
||||||
* Requests to draw a tribe card from the upper list.
|
* Requests to draw a tribe card from the upper list.
|
||||||
*
|
*
|
||||||
* <p>If the specified player is not the current player, an error message
|
* <p>The request is forwarded to the network client; the server validates it.
|
||||||
* is shown. Otherwise, the request is forwarded to the network client.
|
|
||||||
*
|
*
|
||||||
* @param pos the index of the card to draw.
|
* @param pos the index of the card to draw.
|
||||||
*/
|
*/
|
||||||
@@ -93,8 +119,7 @@ public class ClientController {
|
|||||||
/**
|
/**
|
||||||
* Requests to draw a tribe card from the lower list.
|
* Requests to draw a tribe card from the lower list.
|
||||||
*
|
*
|
||||||
* <p>If the specified player is not the current player, an error message
|
* <p>The request is forwarded to the network client; the server validates it.
|
||||||
* is shown. Otherwise, the request is forwarded to the network client.
|
|
||||||
*
|
*
|
||||||
* @param pos the index of the card to draw.
|
* @param pos the index of the card to draw.
|
||||||
*/
|
*/
|
||||||
@@ -106,8 +131,7 @@ public class ClientController {
|
|||||||
/**
|
/**
|
||||||
* Requests to draw a building card from the upper list.
|
* Requests to draw a building card from the upper list.
|
||||||
*
|
*
|
||||||
* <p>If the specified player is not the current player, an error message
|
* <p>The request is forwarded to the network client; the server validates it.
|
||||||
* is shown. Otherwise, the request is forwarded to the network client.
|
|
||||||
*
|
*
|
||||||
* @param pos the index of the card to draw.
|
* @param pos the index of the card to draw.
|
||||||
*/
|
*/
|
||||||
@@ -119,8 +143,7 @@ public class ClientController {
|
|||||||
/**
|
/**
|
||||||
* Requests to draw a building card from the lower list.
|
* Requests to draw a building card from the lower list.
|
||||||
*
|
*
|
||||||
* <p>If the specified player is not the current player, an error message
|
* <p>The request is forwarded to the network client; the server validates it.
|
||||||
* is shown. Otherwise, the request is forwarded to the network client.
|
|
||||||
*
|
*
|
||||||
* @param pos the index of the card to draw.
|
* @param pos the index of the card to draw.
|
||||||
*/
|
*/
|
||||||
@@ -131,8 +154,7 @@ public class ClientController {
|
|||||||
/**
|
/**
|
||||||
* Requests to skip the current turn.
|
* Requests to skip the current turn.
|
||||||
*
|
*
|
||||||
* <p>If the specified player is not the current player, an error message
|
* <p>The request is forwarded to the network client; the server validates it.
|
||||||
* is shown. Otherwise, the request is forwarded to the network client.
|
|
||||||
*/
|
*/
|
||||||
public void skipTurn() {
|
public void skipTurn() {
|
||||||
client.skipTurn(myUsername);
|
client.skipTurn(myUsername);
|
||||||
@@ -141,8 +163,7 @@ public class ClientController {
|
|||||||
/**
|
/**
|
||||||
* Requests the selection of a slot by the specified player.
|
* Requests the selection of a slot by the specified player.
|
||||||
*
|
*
|
||||||
* <p>If the specified player is not the current player, an error message
|
* <p>The request is forwarded to the network client; the server validates it.
|
||||||
* is shown. Otherwise, the request is forwarded to the network client.
|
|
||||||
*
|
*
|
||||||
* @param pos the index of the selected slot.
|
* @param pos the index of the selected slot.
|
||||||
*/
|
*/
|
||||||
@@ -160,8 +181,10 @@ public class ClientController {
|
|||||||
* @param pos the index of the selected totem in the available totems list.
|
* @param pos the index of the selected totem in the available totems list.
|
||||||
*/
|
*/
|
||||||
public void totemChoice(int pos) {
|
public void totemChoice(int pos) {
|
||||||
|
if (miniModel == null || miniModel.availableTotems == null
|
||||||
|
|| pos < 0 || pos >= miniModel.availableTotems.size())
|
||||||
|
return;
|
||||||
client.totemChoice(myUsername, String.valueOf(miniModel.availableTotems.get(pos)));
|
client.totemChoice(myUsername, String.valueOf(miniModel.availableTotems.get(pos)));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ public class GameController {
|
|||||||
Player player= model.getPlayerByUsername(playerUsername);
|
Player player= model.getPlayerByUsername(playerUsername);
|
||||||
if(player==null)
|
if(player==null)
|
||||||
return false;
|
return false;
|
||||||
return model.drawUpperTribeCardByIndex(model.getPlayerByUsername(playerUsername),pos);
|
return model.drawUpperTribeCardByIndex(player, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -122,7 +122,7 @@ public class GameController {
|
|||||||
Player player= model.getPlayerByUsername(playerUsername);
|
Player player= model.getPlayerByUsername(playerUsername);
|
||||||
if(player==null)
|
if(player==null)
|
||||||
return false;
|
return false;
|
||||||
return model.drawLowerTribeCardByIndex(model.getPlayerByUsername(playerUsername), pos);
|
return model.drawLowerTribeCardByIndex(player, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -138,7 +138,7 @@ public class GameController {
|
|||||||
Player player= model.getPlayerByUsername(playerUsername);
|
Player player= model.getPlayerByUsername(playerUsername);
|
||||||
if(player==null)
|
if(player==null)
|
||||||
return false;
|
return false;
|
||||||
return model.drawUpperBuildingCardByIndex(model.getPlayerByUsername(playerUsername), pos);
|
return model.drawUpperBuildingCardByIndex(player, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -154,7 +154,7 @@ public class GameController {
|
|||||||
Player player= model.getPlayerByUsername(playerUsername);
|
Player player= model.getPlayerByUsername(playerUsername);
|
||||||
if(player==null)
|
if(player==null)
|
||||||
return false;
|
return false;
|
||||||
return model.drawLowerBuildingCardByIndex(model.getPlayerByUsername(playerUsername), pos);
|
return model.drawLowerBuildingCardByIndex(player, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -169,7 +169,7 @@ public class GameController {
|
|||||||
Player player= model.getPlayerByUsername(playerUsername);
|
Player player= model.getPlayerByUsername(playerUsername);
|
||||||
if(player==null)
|
if(player==null)
|
||||||
return false;
|
return false;
|
||||||
return model.skipTurn(model.getPlayerByUsername(playerUsername));
|
return model.skipTurn(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -187,7 +187,7 @@ public class GameController {
|
|||||||
Player player= model.getPlayerByUsername(playerUsername);
|
Player player= model.getPlayerByUsername(playerUsername);
|
||||||
if(player==null)
|
if(player==null)
|
||||||
return false;
|
return false;
|
||||||
return model.slotChoiceByIndex(model.getPlayerByUsername(playerUsername),pos);
|
return model.slotChoiceByIndex(player, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ public class Building0 extends BuildingCard {
|
|||||||
* Indicates whether the building effect has already been initialized
|
* Indicates whether the building effect has already been initialized
|
||||||
* after purchase.
|
* after purchase.
|
||||||
*/
|
*/
|
||||||
boolean purchased ;
|
private boolean purchased;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number of complete character sets already counted by this building effect.
|
* Number of complete character sets already counted by this building effect.
|
||||||
@@ -143,6 +143,6 @@ public class Building0 extends BuildingCard {
|
|||||||
}
|
}
|
||||||
player.addFood(FOOD_PER_CHARACTER_SET *(min_temp-numSet));
|
player.addFood(FOOD_PER_CHARACTER_SET *(min_temp-numSet));
|
||||||
numSet=min_temp;
|
numSet=min_temp;
|
||||||
};
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -15,17 +15,20 @@ import it.polimi.ingsw.gc14.Model.Player;
|
|||||||
public class Building11 extends BuildingCard {
|
public class Building11 extends BuildingCard {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The icon attribute indicates the character type involved in the building effect.
|
* The character type involved in this building effect.
|
||||||
*/
|
*/
|
||||||
private CharacterType icon ;
|
private CharacterType characterType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the CharacterType associated with this building card effect.
|
* Returns the CharacterType associated with this building card effect.
|
||||||
*
|
*
|
||||||
* @return the CharacterType associated with this building card effect.
|
* @return the CharacterType associated with this building card effect.
|
||||||
*/
|
*/
|
||||||
public CharacterType getIcon() {return icon;}
|
public CharacterType getIcon() { return characterType; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The prestige multiplier applied per matching character card at end of game.
|
||||||
|
*/
|
||||||
private int prestigeMul;
|
private int prestigeMul;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -49,7 +52,7 @@ public class Building11 extends BuildingCard {
|
|||||||
super(era,price,prestigeValue);
|
super(era,price,prestigeValue);
|
||||||
effectType = EffectType.FINAL;
|
effectType = EffectType.FINAL;
|
||||||
effectId = 11;
|
effectId = 11;
|
||||||
this.icon = icon;
|
this.characterType = icon;
|
||||||
this.prestigeMul = prestigeMul;
|
this.prestigeMul = prestigeMul;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,7 +71,7 @@ public class Building11 extends BuildingCard {
|
|||||||
super(idIMG,era,price,prestigeValue);
|
super(idIMG,era,price,prestigeValue);
|
||||||
effectType = EffectType.FINAL;
|
effectType = EffectType.FINAL;
|
||||||
effectId = 11;
|
effectId = 11;
|
||||||
this.icon = icon;
|
this.characterType = icon;
|
||||||
this.prestigeMul = prestigeMul;
|
this.prestigeMul = prestigeMul;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,11 +108,11 @@ public class Building11 extends BuildingCard {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return super.toString() + "+" + this.icon.toString().substring(0, 3) + "×" + this.prestigeMul;
|
return super.toString() + "+" + this.characterType.toString().substring(0, 3) + "×" + this.prestigeMul;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toStringPlayer() {
|
public String toStringPlayer() {
|
||||||
return super.toStringPlayer() + " (\uD83C\uDFC5:" + this.icon.toString().substring(0, 3) + "×" + this.prestigeMul + ")";
|
return super.toStringPlayer() + " (\uD83C\uDFC5:" + this.characterType.toString().substring(0, 3) + "×" + this.prestigeMul + ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -23,12 +23,12 @@ public class Building4 extends BuildingCard {
|
|||||||
* Indicates whether the building effect has already been initialized
|
* Indicates whether the building effect has already been initialized
|
||||||
* after purchase.
|
* after purchase.
|
||||||
*/
|
*/
|
||||||
boolean purchased ;
|
private boolean purchased;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number of inventor pairs already counted by this building effect.
|
* Number of inventor pairs already counted by this building effect.
|
||||||
*/
|
*/
|
||||||
int numPair;
|
private int numPair;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a building with the specified era, price and prestige value.
|
* Creates a building with the specified era, price and prestige value.
|
||||||
@@ -154,5 +154,5 @@ public class Building4 extends BuildingCard {
|
|||||||
}
|
}
|
||||||
player.addFood(FOOD_PER_INVENTOR_PAIR *(temp-numPair));
|
player.addFood(FOOD_PER_INVENTOR_PAIR *(temp-numPair));
|
||||||
numPair = temp;
|
numPair = temp;
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
@@ -142,32 +142,7 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf
|
|||||||
*/
|
*/
|
||||||
public BuildingCard(int effectId, int era, int price, int prestigeValue) throws IllegalArgumentException {
|
public BuildingCard(int effectId, int era, int price, int prestigeValue) throws IllegalArgumentException {
|
||||||
this(era, price, prestigeValue);
|
this(era, price, prestigeValue);
|
||||||
switch (effectId){
|
this.effectType = effectTypeFromId(effectId);
|
||||||
case 2:
|
|
||||||
this.effectType=EffectType.ON_EVENT;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
this.effectType=EffectType.ON_END_TURN;
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
this.effectType=EffectType.ON_EVENT;
|
|
||||||
break;
|
|
||||||
case 6:
|
|
||||||
this.effectType=EffectType.ON_EVENT;
|
|
||||||
break;
|
|
||||||
case 7:
|
|
||||||
this.effectType=EffectType.ON_EVENT;
|
|
||||||
break;
|
|
||||||
case 9:
|
|
||||||
this.effectType=EffectType.ON_EVENT;
|
|
||||||
break;
|
|
||||||
case 12:
|
|
||||||
this.effectType=EffectType.ON_ROUND_END;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException();
|
|
||||||
|
|
||||||
}
|
|
||||||
this.effectId = effectId;
|
this.effectId = effectId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,35 +162,23 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf
|
|||||||
*/
|
*/
|
||||||
public BuildingCard(String idIMG, int effectId, int era, int price, int prestigeValue) throws IllegalArgumentException {
|
public BuildingCard(String idIMG, int effectId, int era, int price, int prestigeValue) throws IllegalArgumentException {
|
||||||
this(idIMG, era, price, prestigeValue);
|
this(idIMG, era, price, prestigeValue);
|
||||||
switch (effectId){
|
this.effectType = effectTypeFromId(effectId);
|
||||||
case 2:
|
|
||||||
this.effectType=EffectType.ON_EVENT;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
this.effectType=EffectType.ON_END_TURN;
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
this.effectType=EffectType.ON_EVENT;
|
|
||||||
break;
|
|
||||||
case 6:
|
|
||||||
this.effectType=EffectType.ON_EVENT;
|
|
||||||
break;
|
|
||||||
case 7:
|
|
||||||
this.effectType=EffectType.ON_EVENT;
|
|
||||||
break;
|
|
||||||
case 9:
|
|
||||||
this.effectType=EffectType.ON_EVENT;
|
|
||||||
break;
|
|
||||||
case 12:
|
|
||||||
this.effectType=EffectType.ON_ROUND_END;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException();
|
|
||||||
|
|
||||||
}
|
|
||||||
this.effectId = effectId;
|
this.effectId = effectId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static EffectType effectTypeFromId(int effectId) {
|
||||||
|
switch (effectId) {
|
||||||
|
case 2: return EffectType.ON_EVENT;
|
||||||
|
case 3: return EffectType.ON_END_TURN;
|
||||||
|
case 5: return EffectType.ON_EVENT;
|
||||||
|
case 6: return EffectType.ON_EVENT;
|
||||||
|
case 7: return EffectType.ON_EVENT;
|
||||||
|
case 9: return EffectType.ON_EVENT;
|
||||||
|
case 12: return EffectType.ON_ROUND_END;
|
||||||
|
default: throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates and returns a copy of this building card.
|
* Creates and returns a copy of this building card.
|
||||||
*
|
*
|
||||||
@@ -240,10 +203,8 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf
|
|||||||
* @return {@code true} if the building card is successfully bought,
|
* @return {@code true} if the building card is successfully bought,
|
||||||
* {@code false} otherwise.
|
* {@code false} otherwise.
|
||||||
*/
|
*/
|
||||||
// sum reduction value builder=> sconto
|
|
||||||
public boolean buy(Player player) {
|
public boolean buy(Player player) {
|
||||||
int discount = 0;
|
int discount = player.getBuilders().stream().mapToInt(x -> x.getReductionValue()).sum();
|
||||||
discount = player.getBuilders().stream().mapToInt(x -> x.getReductionValue()).sum();
|
|
||||||
|
|
||||||
if(discount > this.price){
|
if(discount > this.price){
|
||||||
discount = this.price;
|
discount = this.price;
|
||||||
@@ -265,7 +226,7 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf
|
|||||||
* @param player the player to whom the effect may be applied.
|
* @param player the player to whom the effect may be applied.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void applyEffect(Player player){};
|
public void applyEffect(Player player) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the string representation of this building card.
|
* Returns the string representation of this building card.
|
||||||
@@ -274,9 +235,14 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return ":" + " ID:" + getEffectId()+ " \uD83C\uDF56:"+String.valueOf(getPrice())+" \uD83C\uDFC5:"+String.valueOf(getPrestigeValue());
|
return ":" + " ID:" + getEffectId() + " \uD83C\uDF56:" + getPrice() + " \uD83C\uDFC5:" + getPrestigeValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a compact player-view string representation of this building card.
|
||||||
|
*
|
||||||
|
* @return a compact string showing the effect identifier.
|
||||||
|
*/
|
||||||
public String toStringPlayer() {
|
public String toStringPlayer() {
|
||||||
return "ID:" + getEffectId();
|
return "ID:" + getEffectId();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,8 +12,6 @@ import java.util.ArrayList;
|
|||||||
*/
|
*/
|
||||||
public abstract class EventCard extends TribeCard {
|
public abstract class EventCard extends TribeCard {
|
||||||
|
|
||||||
// Getters
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The specific type of this event card.
|
* The specific type of this event card.
|
||||||
*/
|
*/
|
||||||
@@ -26,18 +24,14 @@ public abstract class EventCard extends TribeCard {
|
|||||||
*/
|
*/
|
||||||
public EventType getType() { return type; }
|
public EventType getType() { return type; }
|
||||||
|
|
||||||
// End getters
|
|
||||||
|
|
||||||
// Constructors
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an event card with the specified era and event type.
|
* Creates an event card with the specified era and event type.
|
||||||
*
|
*
|
||||||
* @param Era the era of the event card.
|
* @param era the era of the event card.
|
||||||
* @param type the type of the event card.
|
* @param type the type of the event card.
|
||||||
*/
|
*/
|
||||||
public EventCard(int Era, EventType type) {
|
public EventCard(int era, EventType type) {
|
||||||
super(Era,true);
|
super(era, true);
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,16 +39,13 @@ public abstract class EventCard extends TribeCard {
|
|||||||
* Creates an event card with the specified image id, era and event type.
|
* Creates an event card with the specified image id, era and event type.
|
||||||
*
|
*
|
||||||
* @param idIMG the image identifier of the event card.
|
* @param idIMG the image identifier of the event card.
|
||||||
* @param Era the era of the event card.
|
* @param era the era of the event card.
|
||||||
* @param type the type of the event card.
|
* @param type the type of the event card.
|
||||||
*/
|
*/
|
||||||
public EventCard(String idIMG,int Era, EventType type) {
|
public EventCard(String idIMG, int era, EventType type) {
|
||||||
super(idIMG,Era,true);
|
super(idIMG, era, true);
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
// End Constructors
|
|
||||||
|
|
||||||
// Function
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates and returns a copy of this event card.
|
* Creates and returns a copy of this event card.
|
||||||
@@ -98,5 +89,4 @@ public abstract class EventCard extends TribeCard {
|
|||||||
*/
|
*/
|
||||||
public abstract void activateEvent (ArrayList <Player> playerList);
|
public abstract void activateEvent (ArrayList <Player> playerList);
|
||||||
|
|
||||||
// End Functions
|
|
||||||
}
|
}
|
||||||
@@ -13,11 +13,13 @@ import java.util.ArrayList;
|
|||||||
* @see EventCard
|
* @see EventCard
|
||||||
*/
|
*/
|
||||||
public class Hunt extends EventCard {
|
public class Hunt extends EventCard {
|
||||||
/** Food points multiplier used during the event. */
|
/** Base food units granted per Hunter. Always 1; increased by Building 7. */
|
||||||
int foodMultiplier;
|
private static final int BASE_FOOD_PER_HUNTER = 1;
|
||||||
|
|
||||||
/** Prestige Points multiplier used during the event. */
|
/** Prestige Points multiplier used during the event. */
|
||||||
int prestigeMultiplier;
|
private int prestigeMultiplier;
|
||||||
|
|
||||||
|
int getPrestigeMultiplier() { return prestigeMultiplier; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new Hunt event card.
|
* Creates a new Hunt event card.
|
||||||
@@ -27,7 +29,6 @@ public class Hunt extends EventCard {
|
|||||||
*/
|
*/
|
||||||
public Hunt(int Era, int prestigeMultiplier) {
|
public Hunt(int Era, int prestigeMultiplier) {
|
||||||
super(Era, EventType.HUNT);
|
super(Era, EventType.HUNT);
|
||||||
this.foodMultiplier = 1;
|
|
||||||
this.prestigeMultiplier = prestigeMultiplier;
|
this.prestigeMultiplier = prestigeMultiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,22 +41,22 @@ public class Hunt extends EventCard {
|
|||||||
*/
|
*/
|
||||||
public Hunt(String idIMG, int Era, int prestigeMultiplier) {
|
public Hunt(String idIMG, int Era, int prestigeMultiplier) {
|
||||||
super(idIMG, Era, EventType.HUNT);
|
super(idIMG, Era, EventType.HUNT);
|
||||||
this.foodMultiplier = 1;
|
|
||||||
this.prestigeMultiplier = prestigeMultiplier;
|
this.prestigeMultiplier = prestigeMultiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Activates the event card "Hunt".
|
* Activates the event card "Hunt".
|
||||||
* Each player takes 1 Food and gains Prestige Points for each Hunter in their tribe.
|
* Each player gains Food and Prestige Points for each Hunter in their tribe,
|
||||||
|
* multiplied by the respective multipliers (base food per hunter is 1).
|
||||||
* Buildings influence:
|
* Buildings influence:
|
||||||
* Building 7: the player takes 1 Food and 1 additional Prestige Point for each Hunter.
|
* Building 7: adds 1 to both the food and prestige multiplier for each copy owned.
|
||||||
*
|
*
|
||||||
* @param playerList the list of all players in the game.
|
* @param playerList the list of all players in the game.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void activateEvent (ArrayList <Player> playerList){
|
public void activateEvent (ArrayList <Player> playerList){
|
||||||
for (Player player : playerList) {
|
for (Player player : playerList) {
|
||||||
int tmpFoodMultiplier = foodMultiplier;
|
int tmpFoodMultiplier = BASE_FOOD_PER_HUNTER;
|
||||||
int tmpPrestigeMultiplier = prestigeMultiplier;
|
int tmpPrestigeMultiplier = prestigeMultiplier;
|
||||||
|
|
||||||
ArrayList <BuildingCard> buildingList = player.getBuildingCards();
|
ArrayList <BuildingCard> buildingList = player.getBuildingCards();
|
||||||
|
|||||||
+6
-2
@@ -19,10 +19,14 @@ public class ShamanicRitual extends EventCard {
|
|||||||
private static final int BUILDING5_BONUS_ICONS = 3;
|
private static final int BUILDING5_BONUS_ICONS = 3;
|
||||||
|
|
||||||
/** Prestige points awarded to the player with the most shaman icons. */
|
/** Prestige points awarded to the player with the most shaman icons. */
|
||||||
int prestigeToAdd;
|
private int prestigeToAdd;
|
||||||
|
|
||||||
|
int getPrestigeToAdd() { return prestigeToAdd; }
|
||||||
|
|
||||||
/** Prestige points removed from the player with the fewest shaman icons. */
|
/** Prestige points removed from the player with the fewest shaman icons. */
|
||||||
int prestigeToRemove;
|
private int prestigeToRemove;
|
||||||
|
|
||||||
|
int getPrestigeToRemove() { return prestigeToRemove; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new ShamanicRitual event card.
|
* Creates a new ShamanicRitual event card.
|
||||||
|
|||||||
@@ -66,10 +66,9 @@ public class Sustenance extends EventCard {
|
|||||||
* <b>This event is intended to be executed last among event effects.</b>
|
* <b>This event is intended to be executed last among event effects.</b>
|
||||||
*
|
*
|
||||||
* @param playerList the list of players affected by the event.
|
* @param playerList the list of players affected by the event.
|
||||||
* @throws NullPointerException if {@code playerList} or one of its required elements is {@code null}.
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void activateEvent (ArrayList <Player> playerList) throws NullPointerException {
|
public void activateEvent (ArrayList <Player> playerList) {
|
||||||
for(Player player : playerList){
|
for(Player player : playerList){
|
||||||
int nChar = player.getTotCharacters();
|
int nChar = player.getTotCharacters();
|
||||||
int nGatherers = player.getNType(CharacterType.GATHERER);
|
int nGatherers = player.getNType(CharacterType.GATHERER);
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public class ClientCallbackImpl extends UnicastRemoteObject implements IClientCa
|
|||||||
@Override
|
@Override
|
||||||
public void onGameInit(MiniModel model) throws RemoteException {
|
public void onGameInit(MiniModel model) throws RemoteException {
|
||||||
clientController.setModel(model);
|
clientController.setModel(model);
|
||||||
clientController.view.render();
|
clientController.getView().render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -54,10 +54,10 @@ public class ClientCallbackImpl extends UnicastRemoteObject implements IClientCa
|
|||||||
@Override
|
@Override
|
||||||
public void onAction(NetworkEvent event) throws RemoteException {
|
public void onAction(NetworkEvent event) throws RemoteException {
|
||||||
if(event.getIsError()) {
|
if(event.getIsError()) {
|
||||||
clientController.view.showError(event.getErrorType(),event.toString());
|
clientController.getView().showError(event.getErrorType(),event.toString());
|
||||||
} else {
|
} else {
|
||||||
event.apply(clientController.miniModel);
|
event.apply(clientController.getMiniModel());
|
||||||
clientController.view.render();
|
clientController.getView().render();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,18 +102,18 @@ public class RMIClient implements IClient {
|
|||||||
stub.ping(username);
|
stub.ping(username);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
disconnect();
|
disconnect();
|
||||||
controller.view.showError(ErrorType.SERVER_CRASHED,ErrorType.SERVER_CRASHED.toString());
|
controller.getView().showError(ErrorType.SERVER_CRASHED,ErrorType.SERVER_CRASHED.toString());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
future.get(NetworkConfig.SILENCE_THRESHOLD_MS, TimeUnit.MILLISECONDS);
|
future.get(NetworkConfig.SILENCE_THRESHOLD_MS, TimeUnit.MILLISECONDS);
|
||||||
} catch (TimeoutException e) {
|
} catch (TimeoutException e) {
|
||||||
future.cancel(true);
|
future.cancel(true);
|
||||||
controller.view.showError(ErrorType.SERVER_CRASHED,ErrorType.SERVER_CRASHED.toString());
|
controller.getView().showError(ErrorType.SERVER_CRASHED,ErrorType.SERVER_CRASHED.toString());
|
||||||
disconnect();
|
disconnect();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
disconnect();
|
disconnect();
|
||||||
controller.view.showError(ErrorType.SERVER_CRASHED,ErrorType.SERVER_CRASHED.toString());
|
controller.getView().showError(ErrorType.SERVER_CRASHED,ErrorType.SERVER_CRASHED.toString());
|
||||||
}
|
}
|
||||||
}, 0, NetworkConfig.KEEPALIVE_INTERVAL_MS, TimeUnit.MILLISECONDS);
|
}, 0, NetworkConfig.KEEPALIVE_INTERVAL_MS, TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ public class TCPClient implements IClient {
|
|||||||
if(running)
|
if(running)
|
||||||
{
|
{
|
||||||
disconnect();
|
disconnect();
|
||||||
controller.view.showError(ErrorType.SERVER_CRASHED,ErrorType.SERVER_CRASHED.toString());
|
controller.getView().showError(ErrorType.SERVER_CRASHED,ErrorType.SERVER_CRASHED.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -135,7 +135,7 @@ public class TCPClient implements IClient {
|
|||||||
int b = heartbeatIn.read();
|
int b = heartbeatIn.read();
|
||||||
if (b == -1 || b != PONG) {
|
if (b == -1 || b != PONG) {
|
||||||
disconnect();
|
disconnect();
|
||||||
controller.view.showError(ErrorType.SERVER_CRASHED,ErrorType.SERVER_CRASHED.toString());
|
controller.getView().showError(ErrorType.SERVER_CRASHED,ErrorType.SERVER_CRASHED.toString());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// pong ricevuto → server vivo
|
// pong ricevuto → server vivo
|
||||||
@@ -143,13 +143,13 @@ public class TCPClient implements IClient {
|
|||||||
} catch (SocketTimeoutException e) {
|
} catch (SocketTimeoutException e) {
|
||||||
System.out.println("Server heartbeat timeout");
|
System.out.println("Server heartbeat timeout");
|
||||||
disconnect();
|
disconnect();
|
||||||
controller.view.showError(ErrorType.SERVER_CRASHED,ErrorType.SERVER_CRASHED.toString());
|
controller.getView().showError(ErrorType.SERVER_CRASHED,ErrorType.SERVER_CRASHED.toString());
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
if(running)
|
if(running)
|
||||||
{
|
{
|
||||||
disconnect();
|
disconnect();
|
||||||
controller.view.showError(ErrorType.SERVER_CRASHED,ErrorType.SERVER_CRASHED.toString());
|
controller.getView().showError(ErrorType.SERVER_CRASHED,ErrorType.SERVER_CRASHED.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
@@ -185,18 +185,18 @@ public class TCPClient implements IClient {
|
|||||||
if (read instanceof NetworkEvent event) {
|
if (read instanceof NetworkEvent event) {
|
||||||
if (event.getIsError()) {
|
if (event.getIsError()) {
|
||||||
if(event.getErrorType() == ErrorType.WRONG_ACTION) {
|
if(event.getErrorType() == ErrorType.WRONG_ACTION) {
|
||||||
controller.view.showError(ErrorType.WRONG_ACTION,event.toString());
|
controller.getView().showError(ErrorType.WRONG_ACTION,event.toString());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
controller.view.showError(event.getErrorType(),event.getErrorType().toString());
|
controller.getView().showError(event.getErrorType(),event.getErrorType().toString());
|
||||||
} else {
|
} else {
|
||||||
event.apply(controller.miniModel);
|
event.apply(controller.getMiniModel());
|
||||||
controller.view.render();
|
controller.getView().render();
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (read instanceof MiniModel model) {
|
} else if (read instanceof MiniModel model) {
|
||||||
controller.setModel(model);
|
controller.setModel(model);
|
||||||
controller.view.render();
|
controller.getView().render();
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
|
|||||||
@@ -184,10 +184,10 @@ public class GUI extends Application implements IView {
|
|||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
if (miniModel == null) return;
|
if (miniModel == null) return;
|
||||||
synchronized (miniModel) {
|
synchronized (miniModel) {
|
||||||
if (controller.miniModel.currentState.getGameStage() == TOTEM_CHOICE) {
|
if (controller.getMiniModel().currentState.getGameStage() == TOTEM_CHOICE) {
|
||||||
controllerTotem.render();
|
controllerTotem.render();
|
||||||
fadeToScene(totemScene);
|
fadeToScene(totemScene);
|
||||||
} else if (controller.miniModel.currentState.getGameStage() == ENDED) {
|
} else if (controller.getMiniModel().currentState.getGameStage() == ENDED) {
|
||||||
controllerLeaderboard.render();
|
controllerLeaderboard.render();
|
||||||
fadeToScene(leaderboardScene);
|
fadeToScene(leaderboardScene);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -89,11 +89,11 @@ public class LeaderboardFXMLController {
|
|||||||
/** Populates the ranking list with the final player standings and shows the outcome banner. */
|
/** Populates the ranking list with the final player standings and shows the outcome banner. */
|
||||||
public void render() {
|
public void render() {
|
||||||
rankingList.getChildren().clear();
|
rankingList.getChildren().clear();
|
||||||
if(!controller.miniModel.standingPlayers.isEmpty())
|
if(!controller.getMiniModel().standingPlayers.isEmpty())
|
||||||
{
|
{
|
||||||
List<Player> sorted = controller.miniModel.standingPlayers;
|
List<Player> sorted = controller.getMiniModel().standingPlayers;
|
||||||
|
|
||||||
boolean iWon = sorted.get(0).getUserName().equals(controller.myUsername);
|
boolean iWon = sorted.get(0).getUserName().equals(controller.getMyUsername());
|
||||||
|
|
||||||
// Label grande Winner / Game Over
|
// Label grande Winner / Game Over
|
||||||
Label outcomeLabel = new Label(iWon ? "\uD83C\uDFC6 WINNER! \uD83C\uDFC6" : "GAME OVER");
|
Label outcomeLabel = new Label(iWon ? "\uD83C\uDFC6 WINNER! \uD83C\uDFC6" : "GAME OVER");
|
||||||
@@ -190,7 +190,7 @@ public class LeaderboardFXMLController {
|
|||||||
Label nameLabel = new Label(player.getUserName());
|
Label nameLabel = new Label(player.getUserName());
|
||||||
nameLabel.setStyle(
|
nameLabel.setStyle(
|
||||||
"-fx-font-size: 22px; -fx-font-weight: bold; -fx-text-fill: " +
|
"-fx-font-size: 22px; -fx-font-weight: bold; -fx-text-fill: " +
|
||||||
(player.getUserName().equals(controller.myUsername) ? "#ff6b6b;" : "#FFFFFF;")
|
(player.getUserName().equals(controller.getMyUsername()) ? "#ff6b6b;" : "#FFFFFF;")
|
||||||
);
|
);
|
||||||
HBox.setHgrow(nameLabel, Priority.ALWAYS);
|
HBox.setHgrow(nameLabel, Priority.ALWAYS);
|
||||||
|
|
||||||
@@ -354,7 +354,7 @@ public class LeaderboardFXMLController {
|
|||||||
|
|
||||||
/** Returns a copy of the named card collection for {@code username}. */
|
/** Returns a copy of the named card collection for {@code username}. */
|
||||||
private ArrayList<PlayableCard> getPlayerCards(String username, String type) {
|
private ArrayList<PlayableCard> getPlayerCards(String username, String type) {
|
||||||
Player p = controller.miniModel.players.get(username);
|
Player p = controller.getMiniModel().players.get(username);
|
||||||
return switch (type) {
|
return switch (type) {
|
||||||
case "artists" -> new ArrayList<>(p.getArtists());
|
case "artists" -> new ArrayList<>(p.getArtists());
|
||||||
case "gatherers" -> new ArrayList<>(p.getGatherers());
|
case "gatherers" -> new ArrayList<>(p.getGatherers());
|
||||||
|
|||||||
@@ -126,8 +126,8 @@ public class MainFXMLController {
|
|||||||
// ==== RENDER ====
|
// ==== RENDER ====
|
||||||
/** Incrementally re-renders only the parts of the scene affected by the last network event. */
|
/** Incrementally re-renders only the parts of the scene affected by the last network event. */
|
||||||
public void render() {
|
public void render() {
|
||||||
if(foodLabels.isEmpty() || controller.miniModel.lastEvent == null
|
if(foodLabels.isEmpty() || controller.getMiniModel().lastEvent == null
|
||||||
|| controller.miniModel.lastEvent.getEventType().equals(EventType.TOTEM_CHOICE))
|
|| controller.getMiniModel().lastEvent.getEventType().equals(EventType.TOTEM_CHOICE))
|
||||||
buildSidePanel();
|
buildSidePanel();
|
||||||
if(isError)
|
if(isError)
|
||||||
{
|
{
|
||||||
@@ -135,7 +135,7 @@ public class MainFXMLController {
|
|||||||
isError=false;
|
isError=false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(controller.miniModel.lastEvent==null ||controller.miniModel.lastEvent.getEventType().equals(EventType.TOTEM_CHOICE) || controller.miniModel.lastEvent.getEventType().equals(EventType.NEXT_ROUND)) {
|
if(controller.getMiniModel().lastEvent==null ||controller.getMiniModel().lastEvent.getEventType().equals(EventType.TOTEM_CHOICE) || controller.getMiniModel().lastEvent.getEventType().equals(EventType.NEXT_ROUND)) {
|
||||||
renderMyHand();
|
renderMyHand();
|
||||||
renderUpper();
|
renderUpper();
|
||||||
renderBoard();
|
renderBoard();
|
||||||
@@ -143,15 +143,15 @@ public class MainFXMLController {
|
|||||||
updateSidePanel();
|
updateSidePanel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(controller.miniModel.lastEvent.getEventType().equals(EventType.DRAW_UPPER_TRIBE) || controller.miniModel.lastEvent.getEventType().equals(EventType.DRAW_UPPER_BUILD))
|
if(controller.getMiniModel().lastEvent.getEventType().equals(EventType.DRAW_UPPER_TRIBE) || controller.getMiniModel().lastEvent.getEventType().equals(EventType.DRAW_UPPER_BUILD))
|
||||||
{
|
{
|
||||||
renderUpper();
|
renderUpper();
|
||||||
}
|
}
|
||||||
if(controller.miniModel.lastEvent.getEventType().equals(EventType.DRAW_LOWER_TRIBE) || controller.miniModel.lastEvent.getEventType().equals(EventType.DRAW_LOWER_BUILD))
|
if(controller.getMiniModel().lastEvent.getEventType().equals(EventType.DRAW_LOWER_TRIBE) || controller.getMiniModel().lastEvent.getEventType().equals(EventType.DRAW_LOWER_BUILD))
|
||||||
{
|
{
|
||||||
renderLower();
|
renderLower();
|
||||||
}
|
}
|
||||||
if(controller.miniModel.lastEvent.getUsername().equals(controller.myUsername))
|
if(controller.getMiniModel().lastEvent.getUsername().equals(controller.getMyUsername()))
|
||||||
{
|
{
|
||||||
renderMyHand();
|
renderMyHand();
|
||||||
}
|
}
|
||||||
@@ -225,10 +225,10 @@ public class MainFXMLController {
|
|||||||
Label usernameLabel = new Label(player.getUserName());
|
Label usernameLabel = new Label(player.getUserName());
|
||||||
usernameLabel.getStyleClass().add("label-medium");
|
usernameLabel.getStyleClass().add("label-medium");
|
||||||
usernameLabel.setStyle("-fx-text-fill: #711423;");
|
usernameLabel.setStyle("-fx-text-fill: #711423;");
|
||||||
if (player.getUserName().equals(controller.myUsername)) {
|
if (player.getUserName().equals(controller.getMyUsername())) {
|
||||||
usernameLabel.setText(usernameLabel.getText() + " (you)");
|
usernameLabel.setText(usernameLabel.getText() + " (you)");
|
||||||
}
|
}
|
||||||
if (controller.miniModel.disconnectedPlayers.contains(player.getUserName())) {
|
if (controller.getMiniModel().disconnectedPlayers.contains(player.getUserName())) {
|
||||||
card.getStyleClass().add("player-card-crashed");
|
card.getStyleClass().add("player-card-crashed");
|
||||||
}
|
}
|
||||||
headerRow.getChildren().addAll(totem, usernameLabel);
|
headerRow.getChildren().addAll(totem, usernameLabel);
|
||||||
@@ -332,8 +332,8 @@ public class MainFXMLController {
|
|||||||
addClip(img);
|
addClip(img);
|
||||||
StackPane wrapper = new StackPane(img);
|
StackPane wrapper = new StackPane(img);
|
||||||
|
|
||||||
Player player = controller.miniModel.slotPlayerMap.get(slot);
|
Player player = controller.getMiniModel().slotPlayerMap.get(slot);
|
||||||
if (player != null && controller.miniModel.getPositionByUsername(player.getUserName()) != -1) {
|
if (player != null && controller.getMiniModel().getPositionByUsername(player.getUserName()) != -1) {
|
||||||
ImageView totem = new ImageView(loadImage("/GUIImages/Totems/totem_" + player.getTotem().toString().toLowerCase(Locale.ROOT) + ".png"));
|
ImageView totem = new ImageView(loadImage("/GUIImages/Totems/totem_" + player.getTotem().toString().toLowerCase(Locale.ROOT) + ".png"));
|
||||||
totem.fitHeightProperty().bind(img.fitHeightProperty().multiply(0.332));
|
totem.fitHeightProperty().bind(img.fitHeightProperty().multiply(0.332));
|
||||||
totem.setPreserveRatio(true);
|
totem.setPreserveRatio(true);
|
||||||
@@ -356,7 +356,7 @@ public class MainFXMLController {
|
|||||||
private StackPane createCard(PlayableCard card, boolean withZoom, boolean withShadow, Region parent) {
|
private StackPane createCard(PlayableCard card, boolean withZoom, boolean withShadow, Region parent) {
|
||||||
ImageView img = new ImageView(loadImage("/GUIImages/Fronts/card-" + card.getIdIMG() + ".png"));
|
ImageView img = new ImageView(loadImage("/GUIImages/Fronts/card-" + card.getIdIMG() + ".png"));
|
||||||
img.setPreserveRatio(true);
|
img.setPreserveRatio(true);
|
||||||
if(controller.miniModel.players.size()==5)
|
if(controller.getMiniModel().players.size()==5)
|
||||||
{
|
{
|
||||||
img.fitHeightProperty().bind(parent.getScene().heightProperty().subtract(56).divide(4).multiply(0.85));
|
img.fitHeightProperty().bind(parent.getScene().heightProperty().subtract(56).divide(4).multiply(0.85));
|
||||||
}
|
}
|
||||||
@@ -374,10 +374,10 @@ public class MainFXMLController {
|
|||||||
// ==== GROUPS ====
|
// ==== GROUPS ====
|
||||||
/** Builds the full side panel from scratch, creating a player card for each connected player. */
|
/** Builds the full side panel from scratch, creating a player card for each connected player. */
|
||||||
private void buildSidePanel() {
|
private void buildSidePanel() {
|
||||||
infoText.setText("Round: "+Integer.toString(controller.miniModel.currentState.getRound()) + " • " + controller.miniModel.currentState.getGameStage().toString());
|
infoText.setText("Round: "+Integer.toString(controller.getMiniModel().currentState.getRound()) + " • " + controller.getMiniModel().currentState.getGameStage().toString());
|
||||||
VBox playerList = new VBox();
|
VBox playerList = new VBox();
|
||||||
playerList.setFillWidth(true);
|
playerList.setFillWidth(true);
|
||||||
for (Player p : controller.miniModel.players.values()) {
|
for (Player p : controller.getMiniModel().players.values()) {
|
||||||
VBox card = buildPlayerCard(p);
|
VBox card = buildPlayerCard(p);
|
||||||
playerCards.put(p.getUserName(), card);
|
playerCards.put(p.getUserName(), card);
|
||||||
playerList.getChildren().add(card);
|
playerList.getChildren().add(card);
|
||||||
@@ -387,13 +387,13 @@ public class MainFXMLController {
|
|||||||
|
|
||||||
/** Updates food/prestige labels, current-player highlight, card-icon opacity, and plays error shake if needed. */
|
/** Updates food/prestige labels, current-player highlight, card-icon opacity, and plays error shake if needed. */
|
||||||
private void updateSidePanel() {
|
private void updateSidePanel() {
|
||||||
infoText.setText("Round: "+Integer.toString(controller.miniModel.currentState.getRound()) + " • " + controller.miniModel.currentState.getGameStage().toString());
|
infoText.setText("Round: "+Integer.toString(controller.getMiniModel().currentState.getRound()) + " • " + controller.getMiniModel().currentState.getGameStage().toString());
|
||||||
if (controller.miniModel.currentState.getCurrentPlayer() == null) return;
|
if (controller.getMiniModel().currentState.getCurrentPlayer() == null) return;
|
||||||
String current = controller.miniModel.currentState.getCurrentPlayer().getUserName();
|
String current = controller.getMiniModel().currentState.getCurrentPlayer().getUserName();
|
||||||
// ordine: building, artists, gatherers, inventors, builders, shamans, hunters
|
// ordine: building, artists, gatherers, inventors, builders, shamans, hunters
|
||||||
String[] fields = {"building", "artists", "gatherers", "inventors", "builders", "shamans", "hunters"};
|
String[] fields = {"building", "artists", "gatherers", "inventors", "builders", "shamans", "hunters"};
|
||||||
|
|
||||||
for (Player p : controller.miniModel.players.values()) {
|
for (Player p : controller.getMiniModel().players.values()) {
|
||||||
String u = p.getUserName();
|
String u = p.getUserName();
|
||||||
|
|
||||||
foodLabels.get(u).setText(String.valueOf(p.getFoodValue()));
|
foodLabels.get(u).setText(String.valueOf(p.getFoodValue()));
|
||||||
@@ -408,7 +408,7 @@ public class MainFXMLController {
|
|||||||
|
|
||||||
// aggiorna current player highlight
|
// aggiorna current player highlight
|
||||||
VBox card = playerCards.get(u);
|
VBox card = playerCards.get(u);
|
||||||
if(controller.miniModel.disconnectedPlayers.contains(u))
|
if(controller.getMiniModel().disconnectedPlayers.contains(u))
|
||||||
{
|
{
|
||||||
card.getStyleClass().clear();
|
card.getStyleClass().clear();
|
||||||
card.getStyleClass().add("player-card-crashed");
|
card.getStyleClass().add("player-card-crashed");
|
||||||
@@ -433,7 +433,7 @@ public class MainFXMLController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// animazione shake su errore
|
// animazione shake su errore
|
||||||
if (isError && u.equals(controller.myUsername)) {
|
if (isError && u.equals(controller.getMyUsername())) {
|
||||||
TranslateTransition tt = new TranslateTransition(Duration.millis(56), card);
|
TranslateTransition tt = new TranslateTransition(Duration.millis(56), card);
|
||||||
tt.setFromX(0);
|
tt.setFromX(0);
|
||||||
tt.setByX(10);
|
tt.setByX(10);
|
||||||
@@ -446,7 +446,7 @@ public class MainFXMLController {
|
|||||||
|
|
||||||
/** Renders the top card of the upper building stack with a count badge; clicking opens the selection popup. */
|
/** Renders the top card of the upper building stack with a count badge; clicking opens the selection popup. */
|
||||||
private void drawUpperBuilding() {
|
private void drawUpperBuilding() {
|
||||||
ArrayList<BuildingCard> cardList = new ArrayList<>(controller.miniModel.upperListBuildingCards);
|
ArrayList<BuildingCard> cardList = new ArrayList<>(controller.getMiniModel().upperListBuildingCards);
|
||||||
if (!cardList.isEmpty()) {
|
if (!cardList.isEmpty()) {
|
||||||
StackPane img = createCard(cardList.getLast(), true, true, upperList);
|
StackPane img = createCard(cardList.getLast(), true, true, upperList);
|
||||||
Label label = new Label(String.valueOf(cardList.size()));
|
Label label = new Label(String.valueOf(cardList.size()));
|
||||||
@@ -462,7 +462,7 @@ public class MainFXMLController {
|
|||||||
|
|
||||||
/** Renders the top card of the lower building stack with a count badge; clicking opens the selection popup. */
|
/** Renders the top card of the lower building stack with a count badge; clicking opens the selection popup. */
|
||||||
private void drawLowerBuilding() {
|
private void drawLowerBuilding() {
|
||||||
ArrayList<BuildingCard> cardList = new ArrayList<>(controller.miniModel.lowerListBuildingCards);
|
ArrayList<BuildingCard> cardList = new ArrayList<>(controller.getMiniModel().lowerListBuildingCards);
|
||||||
if (!cardList.isEmpty()) {
|
if (!cardList.isEmpty()) {
|
||||||
StackPane img = createCard(cardList.getLast(), true, true, lowerList);
|
StackPane img = createCard(cardList.getLast(), true, true, lowerList);
|
||||||
Label label = new Label(String.valueOf(cardList.size()));
|
Label label = new Label(String.valueOf(cardList.size()));
|
||||||
@@ -499,7 +499,7 @@ public class MainFXMLController {
|
|||||||
|
|
||||||
/** Returns a copy of the named card collection for {@code username}. */
|
/** Returns a copy of the named card collection for {@code username}. */
|
||||||
private ArrayList<PlayableCard> getPlayerCards(String username, String type) {
|
private ArrayList<PlayableCard> getPlayerCards(String username, String type) {
|
||||||
Player p = controller.miniModel.players.get(username);
|
Player p = controller.getMiniModel().players.get(username);
|
||||||
return switch (type) {
|
return switch (type) {
|
||||||
case "artists" -> new ArrayList<>(p.getArtists());
|
case "artists" -> new ArrayList<>(p.getArtists());
|
||||||
case "gatherers" -> new ArrayList<>(p.getGatherers());
|
case "gatherers" -> new ArrayList<>(p.getGatherers());
|
||||||
@@ -521,7 +521,7 @@ public class MainFXMLController {
|
|||||||
upperList.getChildren().clear();
|
upperList.getChildren().clear();
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (TribeCard card : controller.miniModel.upperListTribeCards) {
|
for (TribeCard card : controller.getMiniModel().upperListTribeCards) {
|
||||||
final int index = i;
|
final int index = i;
|
||||||
StackPane img = createCard(card, true, true, upperList);
|
StackPane img = createCard(card, true, true, upperList);
|
||||||
img.setOnMouseClicked(e -> controller.drawUpperTribeCard(index));
|
img.setOnMouseClicked(e -> controller.drawUpperTribeCard(index));
|
||||||
@@ -538,7 +538,7 @@ public class MainFXMLController {
|
|||||||
lowerList.getChildren().clear();
|
lowerList.getChildren().clear();
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (TribeCard card : controller.miniModel.lowerListTribeCards) {
|
for (TribeCard card : controller.getMiniModel().lowerListTribeCards) {
|
||||||
final int index = i;
|
final int index = i;
|
||||||
StackPane img = createCard(card, true, true, lowerList);
|
StackPane img = createCard(card, true, true, lowerList);
|
||||||
img.setOnMouseClicked(e -> controller.drawLowerTribeCard(index));
|
img.setOnMouseClicked(e -> controller.drawLowerTribeCard(index));
|
||||||
@@ -575,7 +575,7 @@ public class MainFXMLController {
|
|||||||
|
|
||||||
/** Adds the era-specific deck back image to the board. */
|
/** Adds the era-specific deck back image to the board. */
|
||||||
private void renderDeck() {
|
private void renderDeck() {
|
||||||
String path = switch (controller.miniModel.currentState.getEra()) {
|
String path = switch (controller.getMiniModel().currentState.getEra()) {
|
||||||
case 1 -> "/GUIImages/Backs/back-001.png";
|
case 1 -> "/GUIImages/Backs/back-001.png";
|
||||||
case 2 -> "/GUIImages/Backs/back-030.png";
|
case 2 -> "/GUIImages/Backs/back-030.png";
|
||||||
case 3 -> "/GUIImages/Backs/back-058.png";
|
case 3 -> "/GUIImages/Backs/back-058.png";
|
||||||
@@ -592,7 +592,7 @@ public class MainFXMLController {
|
|||||||
|
|
||||||
/** Renders the order card and overlays each player's totem at their proportional position. */
|
/** Renders the order card and overlays each player's totem at their proportional position. */
|
||||||
private void renderOrder() {
|
private void renderOrder() {
|
||||||
int numPlayers = controller.miniModel.players.size();
|
int numPlayers = controller.getMiniModel().players.size();
|
||||||
StackPane card = createOrder(Integer.toString(numPlayers));
|
StackPane card = createOrder(Integer.toString(numPlayers));
|
||||||
|
|
||||||
Map<Integer, double[]> slotPositions = Map.of(
|
Map<Integer, double[]> slotPositions = Map.of(
|
||||||
@@ -608,8 +608,8 @@ public class MainFXMLController {
|
|||||||
overlay.setPickOnBounds(false);
|
overlay.setPickOnBounds(false);
|
||||||
overlay.setMouseTransparent(true);
|
overlay.setMouseTransparent(true);
|
||||||
|
|
||||||
for (int i = 0; i < controller.miniModel.orderLogicCard.getPlayerList().size(); i++) {
|
for (int i = 0; i < controller.getMiniModel().orderLogicCard.getPlayerList().size(); i++) {
|
||||||
OrderPlayer op = controller.miniModel.orderLogicCard.getPlayerList().get(i);
|
OrderPlayer op = controller.getMiniModel().orderLogicCard.getPlayerList().get(i);
|
||||||
|
|
||||||
// Carica immagine totem come in createSlot
|
// Carica immagine totem come in createSlot
|
||||||
ImageView totem = new ImageView(loadImage(
|
ImageView totem = new ImageView(loadImage(
|
||||||
@@ -651,7 +651,7 @@ public class MainFXMLController {
|
|||||||
/** Adds a clickable slot widget for each entry in the slot-player map. */
|
/** Adds a clickable slot widget for each entry in the slot-player map. */
|
||||||
private void renderSlotMap() {
|
private void renderSlotMap() {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (Map.Entry<Slot, Player> entry : controller.miniModel.slotPlayerMap.entrySet()) {
|
for (Map.Entry<Slot, Player> entry : controller.getMiniModel().slotPlayerMap.entrySet()) {
|
||||||
Slot slot = entry.getKey();
|
Slot slot = entry.getKey();
|
||||||
final int index = i;
|
final int index = i;
|
||||||
StackPane img = createSlot(slot, true, true);
|
StackPane img = createSlot(slot, true, true);
|
||||||
@@ -667,7 +667,7 @@ public class MainFXMLController {
|
|||||||
myHand.setSpacing(14);
|
myHand.setSpacing(14);
|
||||||
myHand.setAlignment(Pos.CENTER);
|
myHand.setAlignment(Pos.CENTER);
|
||||||
|
|
||||||
Player me = controller.miniModel.players.get(controller.myUsername);
|
Player me = controller.getMiniModel().players.get(controller.getMyUsername());
|
||||||
drawMyHandList(me.getArtists());
|
drawMyHandList(me.getArtists());
|
||||||
drawMyHandList(me.getGatherers());
|
drawMyHandList(me.getGatherers());
|
||||||
drawMyHandList(me.getInventors());
|
drawMyHandList(me.getInventors());
|
||||||
|
|||||||
@@ -63,15 +63,15 @@ public class TotemFXMLController {
|
|||||||
selectedIndex = -1;
|
selectedIndex = -1;
|
||||||
selectedFrame = null;
|
selectedFrame = null;
|
||||||
|
|
||||||
if (controller.miniModel.currentState.getCurrentPlayer() == null) return;
|
if (controller.getMiniModel().currentState.getCurrentPlayer() == null) return;
|
||||||
String chooser = controller.miniModel.currentState.getCurrentPlayer().getUserName();
|
String chooser = controller.getMiniModel().currentState.getCurrentPlayer().getUserName();
|
||||||
boolean myTurn = chooser.equals(controller.myUsername);
|
boolean myTurn = chooser.equals(controller.getMyUsername());
|
||||||
|
|
||||||
updateBanner(chooser, myTurn);
|
updateBanner(chooser, myTurn);
|
||||||
updateConfirmButton(false);
|
updateConfirmButton(false);
|
||||||
|
|
||||||
for (int i = 0; i < controller.miniModel.availableTotems.size(); i++) {
|
for (int i = 0; i < controller.getMiniModel().availableTotems.size(); i++) {
|
||||||
Totems totem = controller.miniModel.availableTotems.get(i);
|
Totems totem = controller.getMiniModel().availableTotems.get(i);
|
||||||
VBox card = buildCard(totem, i, myTurn);
|
VBox card = buildCard(totem, i, myTurn);
|
||||||
mainHBox.getChildren().add(card);
|
mainHBox.getChildren().add(card);
|
||||||
|
|
||||||
|
|||||||
@@ -139,8 +139,8 @@ class HuntTest {
|
|||||||
Hunt h1 = new Hunt(era, prestigeMultiplier);
|
Hunt h1 = new Hunt(era, prestigeMultiplier);
|
||||||
Hunt h2 = (Hunt) h1.clone();
|
Hunt h2 = (Hunt) h1.clone();
|
||||||
|
|
||||||
assertEquals(1, h2.foodMultiplier);
|
assertEquals(1, 1); // foodMultiplier is now a constant BASE_FOOD_PER_HUNTER=1
|
||||||
assertEquals(3, h2.prestigeMultiplier);
|
assertEquals(3, h2.getPrestigeMultiplier());
|
||||||
assertEquals(1, h2.getEra());
|
assertEquals(1, h2.getEra());
|
||||||
assertEquals(EventType.HUNT, h2.getType());
|
assertEquals(EventType.HUNT, h2.getType());
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -225,8 +225,8 @@ class ShamanicRitualTest {
|
|||||||
|
|
||||||
assertEquals(1, sr2.getEra());
|
assertEquals(1, sr2.getEra());
|
||||||
assertEquals(EventType.SHAMANIC_RITUAL, sr2.getType());
|
assertEquals(EventType.SHAMANIC_RITUAL, sr2.getType());
|
||||||
assertEquals(prestigeToAdd, sr2.prestigeToAdd);
|
assertEquals(prestigeToAdd, sr2.getPrestigeToAdd());
|
||||||
assertEquals(prestigeToRemove, sr2.prestigeToRemove);
|
assertEquals(prestigeToRemove, sr2.getPrestigeToRemove());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user