Initial problem solving (identified by Intellij)
This commit is contained in:
@@ -121,7 +121,7 @@ public class ClientLauncherTUI {
|
||||
if (!doLogin(controller)) continue;
|
||||
|
||||
while (controller.getClient() != null) {
|
||||
String prompt = buildPrompt(controller);
|
||||
String prompt = buildPrompt();
|
||||
String line;
|
||||
try {
|
||||
line = gameReader.readLine(prompt);
|
||||
@@ -247,10 +247,9 @@ public class ClientLauncherTUI {
|
||||
/**
|
||||
* Returns the command-line prompt string showing the current username.
|
||||
*
|
||||
* @param controller the client controller (reserved for future use).
|
||||
* @return the prompt string.
|
||||
*/
|
||||
private String buildPrompt(ClientController controller) {
|
||||
private String buildPrompt() {
|
||||
return currentUsername.isEmpty() ? "> " : currentUsername + "> ";
|
||||
}
|
||||
|
||||
@@ -270,7 +269,7 @@ public class ClientLauncherTUI {
|
||||
if (pos >= 0) controller.totemChoice(pos);
|
||||
}
|
||||
case "skip" -> controller.skipTurn();
|
||||
case "clear" -> handleRender(parts);
|
||||
case "clear" -> handleRender();
|
||||
case "help" -> gameReader.printAbove("Commands: slot, draw, totem, skip, clear, help, details, rematch, quit");
|
||||
case "details" -> {
|
||||
if (parts.length > 1 && parts[1].equalsIgnoreCase("buildings"))
|
||||
@@ -325,9 +324,8 @@ public class ClientLauncherTUI {
|
||||
/**
|
||||
* Handles the {@code clear} command by triggering a full board re-render.
|
||||
*
|
||||
* @param parts the tokenised command (only the command token is used).
|
||||
*/
|
||||
private void handleRender(String[] parts) {
|
||||
private void handleRender() {
|
||||
view.renderBoard();
|
||||
}
|
||||
/**
|
||||
|
||||
@@ -18,7 +18,7 @@ public class ClientController {
|
||||
private MiniModel miniModel;
|
||||
|
||||
/** View of the client. */
|
||||
private IView view;
|
||||
private final IView view;
|
||||
|
||||
/** Network client, either TCP or RMI. */
|
||||
private IClient client;
|
||||
|
||||
@@ -2,8 +2,6 @@ package it.polimi.ingsw.gc14;
|
||||
|
||||
/** Enumeration of error types that can be returned by server-side operations. */
|
||||
public enum ErrorType {
|
||||
/** The requested user does not exist. */
|
||||
USER_NOT_FOUND("User not found"),
|
||||
/** The chosen username is already taken by another connected player. */
|
||||
USERNAME_ALREADY_USED("Username is already in use"),
|
||||
/** The user is already connected to the server. */
|
||||
|
||||
@@ -101,13 +101,6 @@ public class LimitedMap<K, V> implements Map<K, V> {
|
||||
*/
|
||||
public void setLimit(int num) { this.limit = num; }
|
||||
|
||||
/**
|
||||
* Returns the current size limit of this map.
|
||||
*
|
||||
* @return the current limit.
|
||||
*/
|
||||
public int getLimit() { return limit; }
|
||||
|
||||
/**
|
||||
* Sets a new action to execute when the map size reaches or exceeds the limit.
|
||||
*
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package it.polimi.ingsw.gc14.Model.Cards.Building;
|
||||
|
||||
import it.polimi.ingsw.gc14.Model.Player;
|
||||
|
||||
/**
|
||||
* Defines the effect behavior of a building card.
|
||||
*
|
||||
@@ -10,10 +8,4 @@ import it.polimi.ingsw.gc14.Model.Player;
|
||||
*/
|
||||
public interface BuildingEffect {
|
||||
|
||||
/**
|
||||
* Applies the building effect to the specified player.
|
||||
*
|
||||
* @param player the player affected by the building effect.
|
||||
*/
|
||||
void applyEffect(Player player);
|
||||
}
|
||||
|
||||
@@ -127,7 +127,6 @@ public class Building0 extends BuildingCard {
|
||||
* @param player the player who owns the building.
|
||||
* @throws IllegalArgumentException if the specified player does not own this card.
|
||||
*/
|
||||
@Override
|
||||
public void applyEffect(Player player) throws IllegalArgumentException {
|
||||
if(!player.getBuildingCards().contains(this))
|
||||
throw new IllegalArgumentException();
|
||||
|
||||
@@ -13,7 +13,7 @@ public class Building1 extends BuildingCard {
|
||||
/**
|
||||
* Character type involved in the building effect.
|
||||
*/
|
||||
private CharacterType icon ;
|
||||
private final CharacterType icon ;
|
||||
|
||||
/**
|
||||
* Returns the character type associated with this building effect.
|
||||
|
||||
@@ -64,7 +64,6 @@ public class Building10 extends BuildingCard {
|
||||
* @param player the player to whom the effect is applied.
|
||||
* @throws IllegalArgumentException if the player does not own this building card.
|
||||
*/
|
||||
@Override
|
||||
public void applyEffect(Player player) throws IllegalArgumentException {
|
||||
if(!player.getBuildingCards().contains(this))
|
||||
throw new IllegalArgumentException();
|
||||
|
||||
@@ -17,7 +17,7 @@ public class Building11 extends BuildingCard {
|
||||
/**
|
||||
* The character type involved in this building effect.
|
||||
*/
|
||||
private CharacterType characterType;
|
||||
private final CharacterType characterType;
|
||||
|
||||
/**
|
||||
* Returns the CharacterType associated with this building card effect.
|
||||
@@ -29,7 +29,7 @@ public class Building11 extends BuildingCard {
|
||||
/**
|
||||
* The prestige multiplier applied per matching character card at end of game.
|
||||
*/
|
||||
private int prestigeMul;
|
||||
private final int prestigeMul;
|
||||
|
||||
/**
|
||||
* Returns the prestige multiplier associated with this building card effect.
|
||||
@@ -93,7 +93,6 @@ public class Building11 extends BuildingCard {
|
||||
* @param player the player to whom the effect is applied.
|
||||
* @throws IllegalArgumentException if the player does not own this building card.
|
||||
*/
|
||||
@Override
|
||||
public void applyEffect(Player player) throws IllegalArgumentException {
|
||||
if(!player.getBuildingCards().contains(this))
|
||||
throw new IllegalArgumentException();
|
||||
|
||||
@@ -57,7 +57,6 @@ public class Building13 extends BuildingCard{
|
||||
* @param player the player to whom the effect is applied.
|
||||
* @throws IllegalArgumentException if the player does not own this building card.
|
||||
*/
|
||||
@Override
|
||||
public void applyEffect(Player player) throws IllegalArgumentException {
|
||||
if(!player.getBuildingCards().contains(this))
|
||||
throw new IllegalArgumentException();
|
||||
|
||||
@@ -130,7 +130,6 @@ public class Building4 extends BuildingCard {
|
||||
* @param player The player who owns the building.
|
||||
* @throws IllegalArgumentException Thrown if the specified player does not own this card.
|
||||
*/
|
||||
@Override
|
||||
public void applyEffect(Player player) throws IllegalArgumentException {
|
||||
if(!player.getBuildingCards().contains(this))
|
||||
throw new IllegalArgumentException();
|
||||
|
||||
@@ -55,7 +55,6 @@ public class Building8 extends BuildingCard {
|
||||
* @param player The player who owns the building.
|
||||
* @throws IllegalArgumentException Thrown if the specified player does not own this building.
|
||||
*/
|
||||
@Override
|
||||
public void applyEffect(Player player) throws IllegalArgumentException {
|
||||
if(!player.getBuildingCards().contains(this))
|
||||
throw new IllegalArgumentException();
|
||||
|
||||
@@ -168,12 +168,8 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf
|
||||
|
||||
private static EffectType effectTypeFromId(int effectId) {
|
||||
switch (effectId) {
|
||||
case 2: return EffectType.ON_EVENT;
|
||||
case 2, 9, 7, 6, 5: 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();
|
||||
}
|
||||
@@ -225,7 +221,6 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf
|
||||
*
|
||||
* @param player the player to whom the effect may be applied.
|
||||
*/
|
||||
@Override
|
||||
public void applyEffect(Player player) {}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package it.polimi.ingsw.gc14.Model.Cards;
|
||||
|
||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Character;
|
||||
import it.polimi.ingsw.gc14.Model.PlayableCard;
|
||||
import java.io.Serializable;
|
||||
|
||||
@@ -15,7 +14,7 @@ public abstract class TribeCard extends PlayableCard implements Serializable {
|
||||
/**
|
||||
* Indicates whether this tribe card is an event card.
|
||||
*/
|
||||
private boolean isEventCard;
|
||||
private final boolean isEventCard;
|
||||
|
||||
/**
|
||||
* Returns whether this tribe card is an event card.
|
||||
|
||||
@@ -14,7 +14,7 @@ public abstract class Character extends TribeCard implements Cloneable {
|
||||
/**
|
||||
* The specific type of this character card.
|
||||
*/
|
||||
private CharacterType type;
|
||||
private final CharacterType type;
|
||||
|
||||
/**
|
||||
* Returns the type of this character card.
|
||||
|
||||
@@ -17,7 +17,7 @@ public class Hunter extends Character {
|
||||
* {@code Hunter} with an {@code Hunter Icon} is added to the tribe, 1 {@code Food token} is awarded for each Hunter in the tribe
|
||||
* (with or without an icon).
|
||||
*/
|
||||
private boolean icon;
|
||||
private final boolean icon;
|
||||
|
||||
/**
|
||||
* Returns whether this Hunter card has the icon.
|
||||
|
||||
@@ -18,7 +18,7 @@ public class Shaman extends Character {
|
||||
* having the minority, on the other hand, results in
|
||||
* losing Prestige Points.
|
||||
*/
|
||||
private int icon;
|
||||
private final int icon;
|
||||
|
||||
/**
|
||||
* Returns the icon value of this Shaman card.
|
||||
|
||||
@@ -15,7 +15,7 @@ public abstract class EventCard extends TribeCard {
|
||||
/**
|
||||
* The specific type of this event card.
|
||||
*/
|
||||
private EventType type;
|
||||
private final EventType type;
|
||||
|
||||
/**
|
||||
* Returns the type of this event card.
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
package it.polimi.ingsw.gc14.Model.Cards.TribeCards.Events;
|
||||
|
||||
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
|
||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCard;
|
||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Character;
|
||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;
|
||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.Artist;
|
||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.EventType;
|
||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.EventCard;
|
||||
import it.polimi.ingsw.gc14.Model.Player;
|
||||
@@ -21,17 +18,17 @@ public class CavePaintings extends EventCard {
|
||||
* The minimum number of Artist cards required to avoid the prestige penalty.
|
||||
* Also, the bottom number on the card.
|
||||
*/
|
||||
private int nLower;
|
||||
private final int nLower;
|
||||
|
||||
/**
|
||||
* The amount of Prestige removed if the player has fewer Artist cards than {@code nLower}.
|
||||
*/
|
||||
private int nPrestigeRem; // NPrestigeLower
|
||||
private final int nPrestigeRem; // NPrestigeLower
|
||||
|
||||
/**
|
||||
* The Prestige multiplier applied if the player has at least {@code nLower} Artist cards.
|
||||
*/
|
||||
private int nPrestigeMul; // NPrestigeUpper
|
||||
private final int nPrestigeMul; // NPrestigeUpper
|
||||
|
||||
/**
|
||||
* Creates a CavePaintings event card with the specified era and effect parameters.
|
||||
|
||||
@@ -17,7 +17,7 @@ public class Hunt extends EventCard {
|
||||
private static final int BASE_FOOD_PER_HUNTER = 1;
|
||||
|
||||
/** Prestige Points multiplier used during the event. */
|
||||
private int prestigeMultiplier;
|
||||
private final int prestigeMultiplier;
|
||||
|
||||
int getPrestigeMultiplier() { return prestigeMultiplier; }
|
||||
|
||||
|
||||
+5
-6
@@ -7,7 +7,6 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* When activated, rewards the player with the most shaman icons and penalizes the one with the fewest.
|
||||
@@ -19,7 +18,7 @@ public class ShamanicRitual extends EventCard {
|
||||
private static final int BUILDING5_BONUS_ICONS = 3;
|
||||
|
||||
/** Prestige points awarded to the player with the most shaman icons. */
|
||||
private int prestigeToAdd;
|
||||
private final int prestigeToAdd;
|
||||
|
||||
/**
|
||||
* Returns the prestige points awarded to the player with the most shaman icons.
|
||||
@@ -29,7 +28,7 @@ public class ShamanicRitual extends EventCard {
|
||||
int getPrestigeToAdd() { return prestigeToAdd; }
|
||||
|
||||
/** Prestige points removed from the player with the fewest shaman icons. */
|
||||
private int prestigeToRemove;
|
||||
private final int prestigeToRemove;
|
||||
|
||||
/**
|
||||
* Returns the prestige points removed from the player with the fewest shaman icons.
|
||||
@@ -98,8 +97,8 @@ public class ShamanicRitual extends EventCard {
|
||||
int maxIcon = playerMap.values().stream().mapToInt(Integer::intValue).max().orElse(0);
|
||||
int minIcon = playerMap.values().stream().mapToInt(Integer::intValue).min().orElse(0);
|
||||
|
||||
List<Player> maxIconsPlayer = playerMap.entrySet().stream().filter(e -> e.getValue() == maxIcon).map(Map.Entry::getKey).collect(Collectors.toList());
|
||||
List<Player> minIconsPlayer = playerMap.entrySet().stream().filter(e -> e.getValue() == minIcon).map(Map.Entry::getKey).collect(Collectors.toList());
|
||||
List<Player> maxIconsPlayer = playerMap.entrySet().stream().filter(e -> e.getValue() == maxIcon).map(Map.Entry::getKey).toList();
|
||||
List<Player> minIconsPlayer = playerMap.entrySet().stream().filter(e -> e.getValue() == minIcon).map(Map.Entry::getKey).toList();
|
||||
|
||||
|
||||
for (Player player : maxIconsPlayer) {
|
||||
@@ -111,7 +110,7 @@ public class ShamanicRitual extends EventCard {
|
||||
}
|
||||
|
||||
for (Player player : minIconsPlayer) {
|
||||
if (!(player.getBuildingCards().stream().anyMatch(b -> b.getEffectId() == 2))) {
|
||||
if (player.getBuildingCards().stream().noneMatch(b -> b.getEffectId() == 2)) {
|
||||
player.removePrestige(prestigeToRemove);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public class Sustenance extends EventCard {
|
||||
/**
|
||||
* The prestige penalty multiplier applied for each unpaid Food unit.
|
||||
*/
|
||||
private int prestigeDebt;
|
||||
private final int prestigeDebt;
|
||||
|
||||
/**
|
||||
* Returns the prestige penalty multiplier associated with this Sustenance event.
|
||||
|
||||
@@ -66,7 +66,7 @@ public class Game implements Serializable {
|
||||
/**
|
||||
* Queue containing the players who still have to choose their totem.
|
||||
*/
|
||||
private Queue<Player> totemChoiceQueue = new LinkedList<>();
|
||||
private final Queue<Player> totemChoiceQueue = new LinkedList<>();
|
||||
|
||||
/**
|
||||
* Assigns the selected totem to the specified player during the totem choice phase.
|
||||
@@ -122,7 +122,7 @@ 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.
|
||||
*/
|
||||
private Map<Player,Boolean> disconnectedPlayers = new HashMap<>();
|
||||
private final Map<Player,Boolean> disconnectedPlayers = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Returns an unmodifiable view of the disconnected-players map.
|
||||
|
||||
@@ -20,29 +20,29 @@ public class Board implements Serializable {
|
||||
* slotList contains the ordered list of slots (tiles). The slots changes based on the number of players.
|
||||
* Each slot (tile) has special action as drawing from the upper/lower row or taking food.
|
||||
*/
|
||||
private List<Slot> slotList;
|
||||
private final List<Slot> slotList;
|
||||
|
||||
/** tribeDeck is the deck from where you draw tribe cards as characters and events. */
|
||||
private Queue<TribeCard> tribeDeck;
|
||||
private final Queue<TribeCard> tribeDeck;
|
||||
|
||||
/**
|
||||
* The upper row of tribe cards. It contains a total of
|
||||
* {@code nTotem + 4} tribe cards, which may include both character and event cards.
|
||||
*/
|
||||
private List<TribeCard> upperListTribe;
|
||||
private final List<TribeCard> upperListTribe;
|
||||
|
||||
/**
|
||||
* The lower row of the tribe card. During the first round, there will be (num. of players + 1) character cards.
|
||||
* During the following rounds, lower row will be emptied and populated with upper row's cards.
|
||||
* When an Event card gets in the lower row, the event effect will be activated at the end of the round.
|
||||
*/
|
||||
private List<TribeCard> lowerListTribe;
|
||||
private final List<TribeCard> lowerListTribe;
|
||||
|
||||
/** Contains all the building cards of the upper list. When a new era starts, all its building cards are placed here. */
|
||||
private List<BuildingCard> upperListBuilding;
|
||||
private final List<BuildingCard> upperListBuilding;
|
||||
|
||||
/** Contains all the building cards of the lower list. When a new era starts, the old era's buildings are moved from the upper to the lower list. */
|
||||
private List<BuildingCard> lowerListBuilding;
|
||||
private final List<BuildingCard> lowerListBuilding;
|
||||
|
||||
/**
|
||||
* Returns the upper row of tribe cards.
|
||||
@@ -75,7 +75,7 @@ public class Board implements Serializable {
|
||||
/** All building card lists grouped by era; index 0 = era 1, index 1 = era 2, etc. */
|
||||
private final ArrayList<List<BuildingCard>> buildingCardsAllEras;
|
||||
/** Number of players */
|
||||
private int nTotem;
|
||||
private final int nTotem;
|
||||
|
||||
/** Current era of the game */
|
||||
private int era;
|
||||
|
||||
@@ -2,9 +2,7 @@ package it.polimi.ingsw.gc14.Model;
|
||||
|
||||
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
|
||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCard;
|
||||
import it.polimi.ingsw.gc14.Model.GamePackage.Board;
|
||||
import it.polimi.ingsw.gc14.Model.GamePackage.CurrentState;
|
||||
import it.polimi.ingsw.gc14.Network.EventType;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
|
||||
import java.io.Serializable;
|
||||
@@ -177,15 +175,6 @@ public class MiniModel implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds or updates a single player in the mini model.
|
||||
*
|
||||
* @param player the player to store.
|
||||
*/
|
||||
public void setPlayer(Player player) {
|
||||
players.put(player.getUserName(), player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the final standing of the players.
|
||||
*
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
package it.polimi.ingsw.gc14.Model;
|
||||
|
||||
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
|
||||
import it.polimi.ingsw.gc14.Model.Orders.OrderPlayer;
|
||||
import it.polimi.ingsw.gc14.View.TUI.AsciiTable;
|
||||
import it.polimi.ingsw.gc14.View.TUI.BorderStyle;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Abstract base class for all order logic cards.
|
||||
@@ -20,13 +16,13 @@ public abstract class OrderLogicCard implements Serializable {
|
||||
/**
|
||||
* The queue of {@link Player Players} associated with this order logic card.
|
||||
*/
|
||||
private Queue<Player> players;
|
||||
private final Queue<Player> players;
|
||||
|
||||
/**
|
||||
* The list of {@link OrderPlayer} entries tracking turn order and played status.
|
||||
* Protected so subclasses can read it for display purposes (e.g., {@link #toString()}).
|
||||
*/
|
||||
protected List<OrderPlayer> playerList;
|
||||
protected final List<OrderPlayer> playerList;
|
||||
|
||||
/**
|
||||
* Returns an unmodifiable view of the player order list.
|
||||
|
||||
@@ -6,7 +6,6 @@ import it.polimi.ingsw.gc14.View.TUI.AsciiTable;
|
||||
import it.polimi.ingsw.gc14.View.TUI.BorderStyle;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
/**
|
||||
* Represents the order logic card used in a two-player game.
|
||||
@@ -51,10 +50,8 @@ public class Order2 extends OrderLogicCard {
|
||||
buildingEffect(player);
|
||||
return;
|
||||
}
|
||||
if(index==1){
|
||||
if(!player.removeFood(1)){
|
||||
player.removePrestige(2);
|
||||
}
|
||||
if (!player.removeFood(1)) {
|
||||
player.removePrestige(2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ public abstract class PlayableCard implements Serializable {
|
||||
/**
|
||||
* The image identifier of the playable card.
|
||||
*/
|
||||
private String idIMG;
|
||||
private final String idIMG;
|
||||
|
||||
/**
|
||||
* Returns the image identifier of this playable card.
|
||||
|
||||
@@ -12,7 +12,7 @@ public class Slot implements Serializable {
|
||||
/**
|
||||
* The identifier of this slot.
|
||||
*/
|
||||
private char slotId;
|
||||
private final char slotId;
|
||||
|
||||
/**
|
||||
* Returns the identifier of this slot.
|
||||
@@ -171,7 +171,7 @@ public class Slot implements Serializable {
|
||||
StringBuilder s = new StringBuilder(" ");
|
||||
for(int i=0;i<this.getNUpper();i++) s.append("▲");
|
||||
for(int i=0;i<this.getNLower();i++) s.append("▼");
|
||||
if(getFood()!=0) s.append("+"+getFood()+" \uD83C\uDF56");
|
||||
if(getFood()!=0) s.append("+").append(getFood()).append(" \uD83C\uDF56");
|
||||
s.append(" ");
|
||||
return s.toString();
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public abstract class NetworkEvent implements Serializable {
|
||||
/**
|
||||
* Username of the player requesting the event.
|
||||
*/
|
||||
protected String username;
|
||||
protected final String username;
|
||||
|
||||
/**
|
||||
* Returns the username of the player requesting the event.
|
||||
@@ -52,7 +52,7 @@ public abstract class NetworkEvent implements Serializable {
|
||||
/**
|
||||
* Type of the network event.
|
||||
*/
|
||||
protected EventType eventType;
|
||||
protected final EventType eventType;
|
||||
|
||||
/**
|
||||
* Map associating each occupied slot with the corresponding player.
|
||||
|
||||
@@ -15,7 +15,7 @@ import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
*/
|
||||
public class AddPlayer extends NetworkEvent {
|
||||
/** Number of players proposed by this player; used only when creating a new game. */
|
||||
private int proposedNPlayer;
|
||||
private final int proposedNPlayer;
|
||||
|
||||
/**
|
||||
* @return the number of proposed players to add to the match
|
||||
|
||||
@@ -26,10 +26,10 @@ import java.util.Map;
|
||||
*/
|
||||
public class ApplyNextRound extends NetworkEvent {
|
||||
|
||||
private ArrayList<TribeCard> upperListTribeCards;
|
||||
private ArrayList<TribeCard> lowerListTribeCards;
|
||||
private ArrayList<BuildingCard> upperListBuildingCards;
|
||||
private ArrayList<BuildingCard> lowerListBuildingCards;
|
||||
private final ArrayList<TribeCard> upperListTribeCards;
|
||||
private final ArrayList<TribeCard> lowerListTribeCards;
|
||||
private final ArrayList<BuildingCard> upperListBuildingCards;
|
||||
private final ArrayList<BuildingCard> lowerListBuildingCards;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,7 +12,7 @@ import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
*/
|
||||
public class DrawLowerBuildingCard extends NetworkEvent{
|
||||
/** Index of the card to draw */
|
||||
private int pos;
|
||||
private final int pos;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
|
||||
@@ -13,7 +13,7 @@ import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
public class DrawLowerTribeCard extends NetworkEvent{
|
||||
|
||||
/** Index of the card to draw */
|
||||
private int pos;
|
||||
private final int pos;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
|
||||
@@ -13,7 +13,7 @@ import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
public class DrawUpperBuildingCard extends NetworkEvent{
|
||||
|
||||
/** Index of the card to draw */
|
||||
private int pos;
|
||||
private final int pos;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
|
||||
@@ -13,7 +13,7 @@ import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
public class DrawUpperTribeCard extends NetworkEvent{
|
||||
|
||||
/** Index of the card to draw */
|
||||
private int pos;
|
||||
private final int pos;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
|
||||
@@ -13,7 +13,7 @@ import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
public class SlotChoice extends NetworkEvent {
|
||||
|
||||
/** Index of the selected slot. */
|
||||
private int pos;
|
||||
private final int pos;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
|
||||
@@ -20,22 +20,13 @@ public class TotemChoice extends NetworkEvent implements Serializable {
|
||||
/**
|
||||
* Name of the totem selected by the player.
|
||||
*/
|
||||
private String totem;
|
||||
private final String totem;
|
||||
|
||||
/**
|
||||
* List of totems still available after the choice has been processed.
|
||||
*/
|
||||
private List<Totems> availableTotems;
|
||||
|
||||
/**
|
||||
* Sets the list of currently available totems.
|
||||
*
|
||||
* @param availableTotems the totems still available for selection.
|
||||
*/
|
||||
public void setAvailableTotems(List<Totems> availableTotems) {
|
||||
this.availableTotems = availableTotems;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a totem choice event for the specified player.
|
||||
*
|
||||
|
||||
@@ -4,7 +4,6 @@ import it.polimi.ingsw.gc14.Controller.ClientController;
|
||||
import it.polimi.ingsw.gc14.Model.MiniModel;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
import it.polimi.ingsw.gc14.Network.RMI.Common.IClientCallback;
|
||||
import javafx.application.Platform;
|
||||
|
||||
import java.rmi.RemoteException;
|
||||
import java.rmi.server.UnicastRemoteObject;
|
||||
|
||||
@@ -8,7 +8,6 @@ import it.polimi.ingsw.gc14.Controller.ClientController;
|
||||
import it.polimi.ingsw.gc14.ErrorType;
|
||||
import it.polimi.ingsw.gc14.Network.IClient;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkConfig;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvents.*;
|
||||
import it.polimi.ingsw.gc14.Network.RMI.Common.IGameServer;
|
||||
|
||||
/**
|
||||
@@ -19,8 +18,8 @@ public class RMIClient implements IClient {
|
||||
private final String host;
|
||||
private final int port;
|
||||
private IGameServer stub;
|
||||
private ClientController controller;
|
||||
private String myIp;
|
||||
private final ClientController controller;
|
||||
private final String myIp;
|
||||
private String username;
|
||||
|
||||
private volatile boolean running = false;
|
||||
|
||||
@@ -5,7 +5,6 @@ import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.rmi.*;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Callback interface used by the server to notify an RMI client about
|
||||
|
||||
@@ -21,7 +21,6 @@ import java.util.Map;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import java.rmi.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@@ -36,7 +35,6 @@ import java.util.stream.Collectors;
|
||||
public class RMIServer extends UnicastRemoteObject implements IGameServer {
|
||||
private final String host;
|
||||
private final GameController controller;
|
||||
private Registry registry;
|
||||
private final int nPort;
|
||||
|
||||
/** username → callback */
|
||||
@@ -304,7 +302,7 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer {
|
||||
public boolean start() {
|
||||
try {
|
||||
System.setProperty("java.rmi.server.hostname", host);
|
||||
registry = LocateRegistry.createRegistry(nPort);
|
||||
Registry registry = LocateRegistry.createRegistry(nPort);
|
||||
registry.rebind("RMIGameServer", this);
|
||||
System.out.println("RMI Server started on port: " + nPort);
|
||||
return true;
|
||||
@@ -314,29 +312,6 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the RMI server and removes its binding from the registry.
|
||||
*
|
||||
* <p>The remote server object is unexported, the registry entry associated
|
||||
* with {@code RMIGameServer} is removed, and the server shutdown is logged.
|
||||
*
|
||||
* @return {@code true} if the server is stopped successfully,
|
||||
* {@code false} otherwise.
|
||||
*/
|
||||
public boolean stop() {
|
||||
try {
|
||||
registry.unbind("RMIGameServer");
|
||||
UnicastRemoteObject.unexportObject(this, true);
|
||||
watchdogs.values().forEach(RMIHeartbeat::disconnect);
|
||||
watchdogs.clear();
|
||||
System.out.println("RMI Server stopped");
|
||||
return true;
|
||||
} catch (RemoteException | NotBoundException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates and starts an {@link RMIHeartbeat} for the specified player.
|
||||
|
||||
@@ -31,16 +31,16 @@ public class TCPClient implements IClient {
|
||||
private ObjectOutputStream socketSend;
|
||||
|
||||
/** Client game's controller */
|
||||
private ClientController controller;
|
||||
private final ClientController controller;
|
||||
|
||||
/** IP address of the server to connect to */
|
||||
private String hostname;
|
||||
private final String hostname;
|
||||
|
||||
private boolean running;
|
||||
/** TCP port */
|
||||
private int mainPort;
|
||||
private final int mainPort;
|
||||
|
||||
private int heartbeatPort;
|
||||
private final int heartbeatPort;
|
||||
private Socket heartbeatSocket;
|
||||
private OutputStream heartbeatOut;
|
||||
private InputStream heartbeatIn;
|
||||
@@ -134,7 +134,7 @@ public class TCPClient implements IClient {
|
||||
heartbeatSocket.setSoTimeout((int) NetworkConfig.SILENCE_THRESHOLD_MS);
|
||||
while (running) {
|
||||
int b = heartbeatIn.read();
|
||||
if (b == -1 || b != PONG) {
|
||||
if (b != PONG) {
|
||||
disconnect();
|
||||
controller.getView().showError(ErrorType.SERVER_CRASHED, ErrorType.SERVER_CRASHED.toString());
|
||||
break;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package it.polimi.ingsw.gc14.Network.TCP.Server;
|
||||
|
||||
import it.polimi.ingsw.gc14.LimitedMap;
|
||||
import it.polimi.ingsw.gc14.Model.Game;
|
||||
import it.polimi.ingsw.gc14.Model.MiniModel;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvents.DisconnectedPlayer;
|
||||
@@ -34,25 +33,25 @@ public class ClientHandler implements Runnable {
|
||||
return username;
|
||||
}
|
||||
/** The TCP socket */
|
||||
private Socket clientSocket;
|
||||
private final Socket clientSocket;
|
||||
|
||||
/** Input stream used to receive objects from the client */
|
||||
private ObjectInputStream in;
|
||||
private final ObjectInputStream in;
|
||||
|
||||
/** Output stream used to send objects to the client */
|
||||
private ObjectOutputStream out;
|
||||
private final ObjectOutputStream out;
|
||||
|
||||
/**
|
||||
* Shared list of all client handlers.
|
||||
* This handler removes itself from the list when disconnected.
|
||||
*/
|
||||
private List<ClientHandler> clientHandlers;
|
||||
private final List<ClientHandler> clientHandlers;
|
||||
|
||||
/** Maps each connected player's username to their connection state (true = connected). */
|
||||
private LimitedMap<String, Boolean> limitedMap;
|
||||
private final LimitedMap<String, Boolean> limitedMap;
|
||||
|
||||
/** Queue containing the events to be applied to the game model */
|
||||
private BlockingQueue<NetworkEvent> actionQueue;
|
||||
private final BlockingQueue<NetworkEvent> actionQueue;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -35,12 +35,12 @@ public class TCPServer {
|
||||
/**
|
||||
* Main TCP port used for standard client-server communication.
|
||||
*/
|
||||
private int port;
|
||||
private final int port;
|
||||
|
||||
/**
|
||||
* TCP port dedicated to heartbeat communication.
|
||||
*/
|
||||
private int heartbeatPort;
|
||||
private final int heartbeatPort;
|
||||
|
||||
/**
|
||||
* Main server socket used to accept client connections.
|
||||
@@ -60,17 +60,17 @@ public class TCPServer {
|
||||
/**
|
||||
* Queue containing network events received from clients.
|
||||
*/
|
||||
private BlockingQueue<NetworkEvent> actionQueue;
|
||||
private final BlockingQueue<NetworkEvent> actionQueue;
|
||||
|
||||
/**
|
||||
* Map storing the online/offline status of connected players.
|
||||
*/
|
||||
private LimitedMap<String, Boolean> playerList;
|
||||
private final LimitedMap<String, Boolean> playerList;
|
||||
|
||||
/**
|
||||
* List of active TCP client handlers.
|
||||
*/
|
||||
private CopyOnWriteArrayList<ClientHandler> clientHandlers;
|
||||
private final CopyOnWriteArrayList<ClientHandler> clientHandlers;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -21,8 +21,7 @@ import java.util.Random;
|
||||
* <li><b>dust</b> (type 2) — large, translucent brown drifting circles.</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>Call {@link #start()} after adding {@link #getPane()} to the scene graph,
|
||||
* and {@link #stop()} when the scene is hidden.
|
||||
* <p>Call {@link #start()} after adding {@link #getPane()} to the scene graph
|
||||
*/
|
||||
public class FireParticleSystem {
|
||||
|
||||
@@ -43,8 +42,6 @@ public class FireParticleSystem {
|
||||
private final List<Particle> particles = new ArrayList<>();
|
||||
/** Shared random source for particle initialisation and physics noise. */
|
||||
private final Random rnd = new Random();
|
||||
/** The JavaFX animation timer driving the particle loop. */
|
||||
private AnimationTimer timer;
|
||||
/** Timestamp (ns) of the last particle spawn batch. */
|
||||
private long lastSpawn = 0;
|
||||
/** Timestamp (ns) of the last rendered frame. */
|
||||
@@ -74,7 +71,7 @@ public class FireParticleSystem {
|
||||
|
||||
/** Starts the animation timer. */
|
||||
public void start() {
|
||||
timer = new AnimationTimer() {
|
||||
AnimationTimer timer = new AnimationTimer() {
|
||||
@Override
|
||||
public void handle(long now) {
|
||||
if (now - lastFrame < FRAME_INTERVAL_NS) return;
|
||||
@@ -85,11 +82,6 @@ public class FireParticleSystem {
|
||||
timer.start();
|
||||
}
|
||||
|
||||
/** Stops the animation timer. */
|
||||
public void stop() {
|
||||
if (timer != null) timer.stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Advances the simulation by one frame: pre-warms on first call, spawns new particles,
|
||||
* steps existing ones, removes dead ones, and updates their visual state.
|
||||
@@ -177,13 +169,13 @@ public class FireParticleSystem {
|
||||
/** Remaining life fraction (1.0 = full, 0.0 = dead); only decrements for sparks. */
|
||||
double life;
|
||||
/** Visual radius of the particle's core circle. */
|
||||
double size;
|
||||
final double size;
|
||||
/** Current phase of the sinusoidal wobble. */
|
||||
double wobblePhase;
|
||||
/** Angular speed of the wobble oscillation. */
|
||||
double wobbleSpeed;
|
||||
final double wobbleSpeed;
|
||||
/** Amplitude factor of the wobble displacement. */
|
||||
double wobbleAmp;
|
||||
final double wobbleAmp;
|
||||
/** Particle type: 0 = ember, 1 = spark, 2 = dust. */
|
||||
final int type;
|
||||
/** Shared random source used during physics updates. */
|
||||
|
||||
@@ -105,7 +105,7 @@ public class GUI extends Application implements IView {
|
||||
controllerLogin.updateLoginButton(true);
|
||||
controllerLogin.showError("");
|
||||
fadeToScene(loginScene);
|
||||
}, loginScene);
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import javafx.animation.ScaleTransition;
|
||||
import it.polimi.ingsw.gc14.Model.PlayableCard;
|
||||
import javafx.event.Event;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.ScrollPane;
|
||||
import javafx.stage.Popup;
|
||||
import javafx.geometry.Insets;
|
||||
@@ -24,7 +23,6 @@ import javafx.scene.paint.LinearGradient;
|
||||
import javafx.scene.paint.Stop;
|
||||
import javafx.scene.paint.CycleMethod;
|
||||
import javafx.scene.text.Font;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.stage.Window;
|
||||
import javafx.util.Duration;
|
||||
|
||||
@@ -49,8 +47,6 @@ public class LeaderboardFXMLController {
|
||||
private VBox popupContent;
|
||||
/** Shared image cache to avoid reloading resources multiple times. */
|
||||
private static final Map<String, Image> imageCache = new HashMap<>();
|
||||
/** The login scene shown when the player starts a new game. */
|
||||
private Scene loginScene;
|
||||
/** Action run when the player returns to the login screen (disconnect + scene switch). */
|
||||
private Runnable action;
|
||||
|
||||
@@ -66,11 +62,9 @@ public class LeaderboardFXMLController {
|
||||
*
|
||||
* @param controller the client controller.
|
||||
* @param action the action to run when the player returns to the login screen.
|
||||
* @param loginScene the login scene to show on exit.
|
||||
*/
|
||||
public void setController(ClientController controller, Runnable action, Scene loginScene) {
|
||||
public void setController(ClientController controller, Runnable action) {
|
||||
this.controller = controller;
|
||||
this.loginScene = loginScene;
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,9 +20,6 @@ import javafx.scene.paint.Color;
|
||||
import javafx.stage.Screen;
|
||||
import javafx.util.Duration;
|
||||
|
||||
import java.net.*;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
* FXML controller for the login scene.
|
||||
*
|
||||
|
||||
@@ -6,21 +6,14 @@ import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
|
||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCard;
|
||||
import it.polimi.ingsw.gc14.Model.Orders.OrderPlayer;
|
||||
import it.polimi.ingsw.gc14.Network.EventType;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
import javafx.animation.ScaleTransition;
|
||||
import javafx.animation.TranslateTransition;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.event.Event;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.geometry.Bounds;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.geometry.Rectangle2D;
|
||||
import javafx.scene.Cursor;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ScrollPane;
|
||||
@@ -33,7 +26,6 @@ import javafx.scene.paint.Color;
|
||||
import javafx.scene.shape.*;
|
||||
import javafx.scene.text.Font;
|
||||
import javafx.stage.Popup;
|
||||
import javafx.stage.Screen;
|
||||
import javafx.stage.Window;
|
||||
import javafx.util.Duration;
|
||||
|
||||
@@ -46,14 +38,10 @@ import java.util.*;
|
||||
* the player's hand, and action buttons (skip, details).
|
||||
*/
|
||||
public class MainFXMLController {
|
||||
/** Left column grid used for the board slots layout. */
|
||||
@FXML private GridPane leftGrid;
|
||||
/** Scrollable container holding all player side-panel cards. */
|
||||
@FXML private ScrollPane playerSide;
|
||||
/** Root HBox containing all main scene elements. */
|
||||
@FXML private HBox mainHBox;
|
||||
/** Background image view for the main scene. */
|
||||
@FXML private ImageView backgroundImage;
|
||||
/** HBox holding the board slot and order cards. */
|
||||
@FXML private HBox board;
|
||||
/** HBox holding the upper tribe card row (and upper building stack). */
|
||||
@@ -594,7 +582,6 @@ public class MainFXMLController {
|
||||
/** Adds the era-specific deck back image to the board. */
|
||||
private void renderDeck() {
|
||||
String path = switch (controller.getMiniModel().currentState.getEra()) {
|
||||
case 1 -> "/GUIImages/Backs/back-001.png";
|
||||
case 2 -> "/GUIImages/Backs/back-030.png";
|
||||
case 3 -> "/GUIImages/Backs/back-058.png";
|
||||
default -> "/GUIImages/Backs/back-001.png";
|
||||
|
||||
@@ -103,11 +103,6 @@ public class TUI implements IView {
|
||||
display(buildBoardContent());
|
||||
}
|
||||
|
||||
/** Renders the totem-choice panel. */
|
||||
public void renderTotems() {
|
||||
display(buildTotemsContent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows an error message combined with the current board in one display call,
|
||||
* so only one {@code printAbove} is issued and the prompt is redrawn correctly.
|
||||
|
||||
Reference in New Issue
Block a user