Initial problem solving (identified by Intellij)

This commit is contained in:
2026-06-14 21:01:43 +02:00
parent e27a2e1b0c
commit bac4a6b7f5
69 changed files with 175 additions and 368 deletions
@@ -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; }
@@ -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.
+2 -2
View File
@@ -10,7 +10,7 @@
stylesheets="@styles.css">
<ImageView fx:id="backgroundImage" fitWidth="1920" fitHeight="1080" preserveRatio="false"/>
<ImageView fx:id="backgroundImage" fitWidth="1920" fitHeight="1080"/>
<!-- Corner decorations -->
<Region prefWidth="52" prefHeight="52"
@@ -35,7 +35,7 @@
</Region>
<!-- Central panel -->
<VBox fx:id="formPanel" alignment="CENTER" spacing="0" maxWidth="420" maxHeight="600"
<VBox fx:id="formPanel" alignment="CENTER" maxWidth="420" maxHeight="600"
StackPane.alignment="CENTER"
style="-fx-background-color: rgba(9,6,3,0.72);
-fx-border-color: rgba(200,120,20,0.40);
+61 -67
View File
@@ -13,78 +13,72 @@
fx:controller="it.polimi.ingsw.gc14.View.GUI.MainFXMLController"
stylesheets="@styles.css">
<children>
<!-- VBox sinistra: si espande per riempire tutto lo spazio disponibile -->
<VBox alignment="CENTER"
fillWidth="false"
maxHeight="Infinity"
maxWidth="Infinity"
HBox.hgrow="ALWAYS">
<HBox.margin>
<Insets top="5" right="5" bottom="5" left="5" />
</HBox.margin>
<children>
<HBox fx:id="upperList" styleClass="card-list" VBox.vgrow="ALWAYS">
<VBox.margin>
<Insets top="5" right="5" bottom="5" left="5" />
</VBox.margin>
</HBox>
<!-- VBox sinistra: si espande per riempire tutto lo spazio disponibile -->
<VBox alignment="CENTER"
fillWidth="false"
maxHeight="Infinity"
maxWidth="Infinity"
HBox.hgrow="ALWAYS">
<HBox.margin>
<Insets top="5" right="5" bottom="5" left="5"/>
</HBox.margin>
<HBox fx:id="upperList" styleClass="card-list" VBox.vgrow="ALWAYS">
<VBox.margin>
<Insets top="5" right="5" bottom="5" left="5"/>
</VBox.margin>
</HBox>
<HBox fx:id="board" styleClass="card-list" VBox.vgrow="NEVER">
<VBox.margin>
<Insets top="5" right="5" bottom="5" left="5" />
</VBox.margin>
</HBox>
<HBox fx:id="board" styleClass="card-list" VBox.vgrow="NEVER">
<VBox.margin>
<Insets top="5" right="5" bottom="5" left="5"/>
</VBox.margin>
</HBox>
<HBox fx:id="lowerList" styleClass="card-list" VBox.vgrow="ALWAYS">
<VBox.margin>
<Insets top="5" right="5" bottom="5" left="5" />
</VBox.margin>
</HBox>
<HBox fx:id="lowerList" styleClass="card-list" VBox.vgrow="ALWAYS">
<VBox.margin>
<Insets top="5" right="5" bottom="5" left="5"/>
</VBox.margin>
</HBox>
<HBox fx:id="myHand" styleClass="card-list" VBox.vgrow="ALWAYS">
<VBox.margin>
<Insets top="5" right="5" bottom="5" left="5" />
</VBox.margin>
</HBox>
</children>
</VBox>
<!-- VBox destra: dimensione fissa, non si espande -->
<VBox fx:id="sidePanel"
prefWidth="250.0"
maxWidth="250.0"
minWidth="250.0"
HBox.hgrow="NEVER"
styleClass="side-panel">
<HBox.margin>
<Insets bottom="10" left="10" right="10" top="10" />
</HBox.margin>
<children>
<HBox fx:id="info" prefHeight="80.0" prefWidth="483.0" styleClass="frame" alignment="CENTER">
<Label fx:id="infoText" styleClass="label-medium" text="VALORE" />
</HBox>
<ScrollPane fx:id="playerSide" fitToWidth="true"
style="-fx-background: transparent; -fx-background-color: transparent;" hbarPolicy="NEVER"
vbarPolicy="AS_NEEDED" VBox.vgrow="ALWAYS">
<VBox.margin>
<Insets top="5"/>
</VBox.margin>
</ScrollPane>
<Pane HBox.hgrow="ALWAYS"/>
<HBox alignment="CENTER" fx:id="buttonRow" >
<HBox spacing="10">
<Button fx:id="skipBtn" styleClass="action-button" text="Skip Turn"/>
<Button fx:id="detailsBtn" styleClass="action-button" text="Ending Details"/>
</HBox>
<VBox.margin>
<Insets top="5" right="5" bottom="5" left="5"/>
</VBox.margin>
<HBox fx:id="myHand" styleClass="card-list" VBox.vgrow="ALWAYS">
<VBox.margin>
<Insets top="5" right="5" bottom="5" left="5"/>
</VBox.margin>
</HBox>
</VBox>
<!-- VBox destra: dimensione fissa, non si espande -->
<VBox fx:id="sidePanel"
prefWidth="250.0"
maxWidth="250.0"
minWidth="250.0"
HBox.hgrow="NEVER"
styleClass="side-panel">
<HBox.margin>
<Insets bottom="10" left="10" right="10" top="10"/>
</HBox.margin>
<HBox fx:id="info" prefHeight="80.0" prefWidth="483.0" styleClass="frame" alignment="CENTER">
<Label fx:id="infoText" styleClass="label-medium" text="VALORE"/>
</HBox>
<ScrollPane fx:id="playerSide" fitToWidth="true"
style="-fx-background: transparent; -fx-background-color: transparent;" hbarPolicy="NEVER"
VBox.vgrow="ALWAYS">
<VBox.margin>
<Insets top="5"/>
</VBox.margin>
</ScrollPane>
<Pane HBox.hgrow="ALWAYS"/>
<HBox alignment="CENTER" fx:id="buttonRow">
<HBox spacing="10">
<Button fx:id="skipBtn" styleClass="action-button" text="Skip Turn"/>
<Button fx:id="detailsBtn" styleClass="action-button" text="Ending Details"/>
</HBox>
<VBox.margin>
<Insets top="5" right="5" bottom="5" left="5"/>
</VBox.margin>
</HBox>
</HBox>
</children>
</VBox>
</VBox>
</children>
</HBox>
@@ -16,7 +16,6 @@
<ScrollPane fitToWidth="true"
hbarPolicy="NEVER"
vbarPolicy="AS_NEEDED"
style="-fx-background: transparent; -fx-background-color: transparent;"
VBox.vgrow="ALWAYS">
<VBox fx:id="rankingList" alignment="CENTER" spacing="16">
+6 -7
View File
@@ -1,16 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.text.*?>
<?import javafx.geometry.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.layout.*?>
<StackPane xmlns="http://javafx.com/javafx/26"
xmlns:fx="http://javafx.com/fxml/1"
fx:controller="it.polimi.ingsw.gc14.View.GUI.TotemFXMLController"
style="-fx-background-color: #09060300;">
<ImageView fx:id="backgroundImage" fitWidth="1920" fitHeight="1080" preserveRatio="false">
<ImageView fx:id="backgroundImage" fitWidth="1920" fitHeight="1080">
</ImageView>
<Region fx:id="cornerTL" prefWidth="52" prefHeight="52"
@@ -34,7 +33,7 @@
<StackPane.margin><Insets bottom="18" right="18"/></StackPane.margin>
</Region>
<VBox alignment="CENTER" spacing="0" StackPane.alignment="CENTER">
<VBox alignment="CENTER" StackPane.alignment="CENTER">
<padding><Insets top="40" bottom="40" left="40" right="40"/></padding>
<!-- Banner turno -->
@@ -64,7 +64,7 @@ class Building1Test {
BuildingCard bClone = b0.clone();
assertTrue(bClone instanceof Building1);
assertInstanceOf(Building1.class, bClone);
Building1 clonedBuilding = (Building1) bClone;
@@ -1,7 +1,6 @@
package it.polimi.ingsw.gc14.Model.Cards;
import it.polimi.ingsw.gc14.Model.Cards.Building.EffectType;
import it.polimi.ingsw.gc14.Model.Cards.Building.Effects.Building13;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.Builder;
import it.polimi.ingsw.gc14.Model.Player;
import org.junit.jupiter.api.DisplayName;
@@ -9,22 +9,12 @@ import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
class CavePaintingsTest {
@Test
@DisplayName("Testing constructor")
void testConstructor() {
// Gli attributi di CavePainting era e EventType vengono testati in EventCardTest.
// Gli attributi NLower, NPrestigeRem e NPrestigeMul non possono essere testati singolarmente in quanto non hanno metodi getter
// Ne viene testato il corretto funzionamento indirettamente attraverso applyEffect.
// Come conseguenza finale, non può essere testato il costruttore di CavePainting
}
@Test
@DisplayName("No edge case test")
void activateEvent() {
@@ -46,7 +36,7 @@ class CavePaintingsTest {
@DisplayName("Multiple activations test")
void activateEvent1() {
Player p1 = new Player("Marco");
ArrayList<Player> players = new ArrayList<>(Arrays.asList(p1));
ArrayList<Player> players = new ArrayList<>(List.of(p1));
CavePaintings cp1 = new CavePaintings(1, 1, 3, 2);
CavePaintings cp2 = new CavePaintings(1, 1, 3, 4);
CavePaintings cp3 = new CavePaintings(1, 1, 10, 2);
@@ -71,7 +61,7 @@ class CavePaintingsTest {
@DisplayName("Building 9 test")
void activateEvent2() {
Player p1 = new Player("Marco");
ArrayList<Player> players = new ArrayList<>(Arrays.asList(p1));
ArrayList<Player> players = new ArrayList<>(List.of(p1));
CavePaintings cp1 = new CavePaintings(1, 1, 3, 2);
BuildingCard bc1 = new BuildingCard(9,1,5,5);
p1.addFood(5);
@@ -98,7 +88,7 @@ class CavePaintingsTest {
@DisplayName("Not Building 9 test")
void activateEvent3() {
Player p1 = new Player("Marco");
ArrayList<Player> players = new ArrayList<>(Arrays.asList(p1));
ArrayList<Player> players = new ArrayList<>(List.of(p1));
CavePaintings cp1 = new CavePaintings(1, 1, 3, 2);
BuildingCard bc1 = new BuildingCard(9,1,5,5);
p1.addFood(5);
@@ -1,10 +1,7 @@
package it.polimi.ingsw.gc14.Model.Cards.TribeCards.Events;
import it.polimi.ingsw.gc14.Model.Cards.Building.EffectType;
import it.polimi.ingsw.gc14.Model.Cards.Building.Effects.Building0;
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.Hunter;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.EventCard;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.EventType;
import it.polimi.ingsw.gc14.Model.Player;
import org.junit.jupiter.api.DisplayName;
@@ -16,16 +13,6 @@ import java.util.Arrays;
import static org.junit.jupiter.api.Assertions.*;
class HuntTest {
@Test
@DisplayName("Testing constructor")
void testConstructor() {
// Gli attributi di Hunt era e EventType vengono testati in EventCardTest.
// Gli attributi foodMultiplier e prestigeMultiplier non possono essere testati singolarmente in quanto non hanno metodi getter
// Ne viene testato il corretto funzionamento indirettamente attraverso applyEffect.
// Come conseguenza finale, non può essere testato il costruttore di Hunt
}
@Test
@DisplayName("No edge case test")
@@ -139,7 +126,6 @@ class HuntTest {
Hunt h1 = new Hunt(era, prestigeMultiplier);
Hunt h2 = (Hunt) h1.clone();
assertEquals(1, 1); // foodMultiplier is now a constant BASE_FOOD_PER_HUNTER=1
assertEquals(3, h2.getPrestigeMultiplier());
assertEquals(1, h2.getEra());
assertEquals(EventType.HUNT, h2.getType());
@@ -1,15 +1,10 @@
package it.polimi.ingsw.gc14.Model.Cards.TribeCards.Events;
import it.polimi.ingsw.gc14.Model.Cards.Building.EffectType;
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.Shaman;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.EventType;
import it.polimi.ingsw.gc14.Model.Player;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Arrays;
import static org.junit.jupiter.api.Assertions.*;
@@ -18,21 +13,8 @@ import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Arrays;
import static org.junit.jupiter.api.Assertions.assertEquals;
class ShamanicRitualTest {
@Test
@DisplayName("Testing constructor")
void testConstructor() {
// Gli attributi di ShamanicRitual era e EventType vengono testati in EventCardTest.
// Gli attributi prestigeToAdd e prestigeToRemove non possono essere testati singolarmente in quanto non hanno metodi getter
// Ne viene testato il corretto funzionamento indirettamente attraverso applyEffect.
// Come conseguenza finale, non può essere testato il costruttore di ShamanicRitual
}
@Test
@DisplayName("No edge case test")
void applyEvent() {
@@ -12,7 +12,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertThrows;
class SustenanceTest {
@@ -3,14 +3,10 @@ package it.polimi.ingsw.gc14.Model.GamePackage;
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
import it.polimi.ingsw.gc14.Model.Cards.TribeCard;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.EventCard;
import it.polimi.ingsw.gc14.Model.DecksCreator;
import it.polimi.ingsw.gc14.Model.Player;
import it.polimi.ingsw.gc14.Model.Slot;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.util.*;
import java.util.stream.Collectors;
import static org.junit.jupiter.api.Assertions.*;
@@ -188,7 +184,7 @@ class BoardTest {
void nextRound() {
int numPlayer = 3;
Board bd = new Board(numPlayer);
assertTrue(!bd.getLowerListTribe().isEmpty());
assertFalse(bd.getLowerListTribe().isEmpty());
List<TribeCard> upperListBefore = new ArrayList<>(bd.getUpperListTribe());
bd.nextRound();
@@ -5,7 +5,6 @@ import it.polimi.ingsw.gc14.Model.Player;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.lang.reflect.Field;
import java.util.*;
import static org.junit.jupiter.api.Assertions.*;
@@ -32,7 +31,7 @@ class Order2Test {
Order2 order = new Order2(players);
Player firstToAct = order.pull();
Player secondToAct = order.pull();
order.pull();
int initialFood = firstToAct.getFoodValue();
order.push(firstToAct);
@@ -193,7 +192,7 @@ class Order2Test {
assertTrue(order.toString().contains("+1🍖"));
assertTrue(order.toString().contains("-1🍖/-2🏅"));
Player extraPlayer = new Player("px");
new Player("px");
//TODO testare IndexOutOfBoundsException
// assertThrows(IndexOutOfBoundsException.class, () -> {
// Order2 ox = new Order2(new ArrayList<>(Arrays.asList(p1, p2)));;
@@ -5,7 +5,6 @@ import it.polimi.ingsw.gc14.Model.Player;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.lang.reflect.Field;
import java.util.*;
import static org.junit.jupiter.api.Assertions.*;
@@ -5,7 +5,6 @@ import it.polimi.ingsw.gc14.Model.Player;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.lang.reflect.Field;
import java.util.*;
import static org.junit.jupiter.api.Assertions.*;
@@ -3,17 +3,10 @@ package it.polimi.ingsw.gc14.Model.Orders;
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
import it.polimi.ingsw.gc14.Model.Player;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.lang.reflect.Field;
import java.util.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.NoSuchElementException;
import static org.junit.jupiter.api.Assertions.*;
@@ -344,7 +337,7 @@ class Order5Test {
assertNotEquals(thirdOut, fifthOut);
assertNotEquals(fourthOut, fifthOut);
assertEquals(null, order.pull());
assertNull(order.pull());
}
@Test
@@ -355,11 +348,11 @@ class Order5Test {
Player p4 = new Player("p4");
Player p5 = new Player("p5");
Order5 order = new Order5(new ArrayList<>(Arrays.asList(p1,p2,p3,p4,p5)));
Player firstOut = order.pull();
Player secondOut = order.pull();
Player thirdOut = order.pull();
Player fourthOut = order.pull();
Player fifthOut = order.pull();
order.pull();
order.pull();
order.pull();
order.pull();
order.pull();
assertNull(order.getFirst());
order.push(p1);
@@ -1,7 +1,6 @@
package it.polimi.ingsw.gc14.Model;
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
import it.polimi.ingsw.gc14.Model.Cards.TribeCard;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
@@ -125,9 +125,9 @@ class PlayerTest {
@Test
void removeFood() {
Player p = new Player("test");
assertEquals(true, p.removeFood(0));
assertEquals(false, p.removeFood(1));
assertEquals(true, p.removeFood(-1));
assertTrue(p.removeFood(0));
assertFalse(p.removeFood(1));
assertTrue(p.removeFood(-1));
}
@Test
@@ -183,7 +183,7 @@ class PlayerTest {
@DisplayName("Exception Test Max Length")
void test_max() {
assertThrows(IllegalArgumentException.class, () -> {
Player p = new Player("abcdabcdabcdabcdabcdabcdabcdabcdZ");
new Player("abcdabcdabcdabcdabcdabcdabcdabcdZ");
});
}
@@ -191,7 +191,7 @@ class PlayerTest {
@DisplayName("Exception Test Min Length")
void test_min() {
assertThrows(IllegalArgumentException.class, () -> {
Player p = new Player("");
new Player("");
});
}
@@ -9,29 +9,29 @@ class SlotTest {
@Test
void SlotWrongArgument() {
assertDoesNotThrow(() -> {
Slot sl1 = new Slot('A');
new Slot('A');
});
assertDoesNotThrow(() -> {
Slot sl1 = new Slot('B');
new Slot('B');
});
assertDoesNotThrow(() -> {
Slot sl1 = new Slot('C');
new Slot('C');
});
assertDoesNotThrow(() -> {
Slot sl1 = new Slot('D');
new Slot('D');
});
assertDoesNotThrow(() -> {
Slot sl1 = new Slot('E');
new Slot('E');
});
assertDoesNotThrow(() -> {
Slot sl1 = new Slot('F');
new Slot('F');
});
assertDoesNotThrow(() -> {
Slot sl1 = new Slot('G');
new Slot('G');
});
assertThrows(IllegalArgumentException.class, () -> {
Slot sl1 = new Slot('H');
new Slot('H');
});
}