Merge pull request #59 from rubenpirreram/javadoc-fixes

Javadoc fixes
This commit is contained in:
rubenpirreram
2026-04-30 20:11:20 +02:00
committed by GitHub
39 changed files with 352 additions and 37 deletions
@@ -8,6 +8,7 @@ import it.polimi.ingsw.gc14.View.TUI.TUI;
import java.util.Scanner; import java.util.Scanner;
public class ClientLauncherTUI { public class ClientLauncherTUI {
//TODO Javadoc
public void main() throws InterruptedException { public void main() throws InterruptedException {
TUI view=new TUI(null); TUI view=new TUI(null);
ClientController controller = new ClientController(view); ClientController controller = new ClientController(view);
@@ -7,9 +7,12 @@ import it.polimi.ingsw.gc14.Network.NetworkEvents.*;
import it.polimi.ingsw.gc14.Network.Observer; import it.polimi.ingsw.gc14.Network.Observer;
import it.polimi.ingsw.gc14.View.IView; import it.polimi.ingsw.gc14.View.IView;
//TODO Javadoc
public class ClientController { public class ClientController {
public GameController localController; public GameController localController;
//TODO Javadoc
public IView view=null; public IView view=null;
private IClient client; private IClient client;
@@ -2,15 +2,21 @@ package it.polimi.ingsw.gc14;
import java.util.ArrayList; import java.util.ArrayList;
//TODO Javadoc
public class LimitedList<T> extends ArrayList<T> { public class LimitedList<T> extends ArrayList<T> {
//TODO Javadoc
private int limit; private int limit;
//TODO Javadoc
private Runnable action; private Runnable action;
//TODO Javadoc
public LimitedList(int limit, Runnable action) { public LimitedList(int limit, Runnable action) {
this.limit = limit; this.limit = limit;
this.action = action; this.action = action;
} }
//TODO Javadoc
@Override @Override
public boolean add(T element) { public boolean add(T element) {
boolean result = super.add(element); boolean result = super.add(element);
@@ -20,12 +26,15 @@ public class LimitedList<T> extends ArrayList<T> {
return result; return result;
} }
//TODO Javadoc
public void setLimit(int num) { public void setLimit(int num) {
this.limit=num; this.limit=num;
} }
//TODO Javadoc
public int getLimit(){return limit;} public int getLimit(){return limit;}
//TODO Javadoc
public void setAction(Runnable action) { public void setAction(Runnable action) {
this.action=action; this.action=action;
} }
@@ -4,7 +4,6 @@ import it.polimi.ingsw.gc14.Model.Cards.Building.EffectType;
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard; import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType; import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;
/** /**
* During the Sustenance Event, you have a discount of 1 food token on the total you * During the Sustenance Event, you have a discount of 1 food token on the total you
* would have to pay, for each of the indicated characters in your tribe. * would have to pay, for each of the indicated characters in your tribe.
@@ -44,6 +43,16 @@ public class Building1 extends BuildingCard {
return new Building1(getEra(),getPrice(),getPrestigeValue(),getIcon()); return new Building1(getEra(),getPrice(),getPrestigeValue(),getIcon());
} }
/**
* Prints a string representation of this {@code Building1}. This specific variation is used in the {@code Game}'s
* toString to print a more detailed version.
* <p>includes:
* <li>{@link #icon Icon}
* </p>
* @return {@code String} - a string representation of this {@code Building1}.
* @see it.polimi.ingsw.gc14.Model.Game Game
* @see it.polimi.ingsw.gc14.Model.GamePackage.Board Board
*/
@Override @Override
public String toString() { public String toString() {
return super.toString() + " Icon: " + this.icon.toString().charAt(0); return super.toString() + " Icon: " + this.icon.toString().charAt(0);
@@ -7,6 +7,9 @@ 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.
*/
private CharacterType icon ; private CharacterType icon ;
/** /**
@@ -68,6 +71,17 @@ public class Building11 extends BuildingCard {
player.addPrestige(player.getNType(getIcon()) * this.getPrestigeMul()); player.addPrestige(player.getNType(getIcon()) * this.getPrestigeMul());
} }
/**
* Prints a string representation of this {@code Building1}. This specific variation is used in the {@code Game}'s
* toString to print a more detailed version.
* <p>includes:
* <li>{@link #icon Icon}
* <li>{@link #PrestigeMul Prestige Multiplier}
* </p>
* @return {@code String} - a string representation of this {@code Building1}.
* @see it.polimi.ingsw.gc14.Model.Game Game
* @see it.polimi.ingsw.gc14.Model.GamePackage.Board Board
*/
@Override @Override
public String toString() { public String toString() {
return super.toString() + " Icon: " + this.icon.toString().charAt(0) + " MP: " + this.PrestigeMul; return super.toString() + " Icon: " + this.icon.toString().charAt(0) + " MP: " + this.PrestigeMul;
@@ -5,7 +5,6 @@ import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
import it.polimi.ingsw.gc14.Model.Player; import it.polimi.ingsw.gc14.Model.Player;
public class Building13 extends BuildingCard{ public class Building13 extends BuildingCard{
/** /**
* Creates a Building13 card with the specified era, price, and prestige value. * Creates a Building13 card with the specified era, price, and prestige value.
* *
@@ -60,6 +60,17 @@ public abstract class Character extends TribeCard implements Cloneable {
return super.toString(); return super.toString();
} }
/**
* Prints a string representation of this {@code Character}. This specific variation is used in the {@code Game}'s
* toString to print a more detailed version.
* <p>Includes:
* <li>{@link it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType Type}
* </p>
* @return {@code String} - a string representation of this {@code Character}.
* @see it.polimi.ingsw.gc14.Model.Game Game
* @see it.polimi.ingsw.gc14.Model.GamePackage.Board Board
*/
@Override @Override
public String toStringBoard() public String toStringBoard()
{ {
@@ -4,9 +4,7 @@ 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.CharacterType;
import it.polimi.ingsw.gc14.Model.Player; import it.polimi.ingsw.gc14.Model.Player;
public class Builder extends Character public class Builder extends Character {
{
/** /**
* The reduction value provided by this Builder card. * The reduction value provided by this Builder card.
*/ */
@@ -89,6 +87,19 @@ public class Builder extends Character
public String toString() { public String toString() {
return super.toString() + " RV:" + String.valueOf(reductionValue) + " PV:" + String.valueOf(prestigeValue); return super.toString() + " RV:" + String.valueOf(reductionValue) + " PV:" + String.valueOf(prestigeValue);
} }
/**
* Prints a string representation of this {@code TribeCard}. This specific variation is used in the {@code Game}'s
* toString to print a more detailed version.
* <p>Includes:
* <li>{@link #reductionValue Reduction Value}
* <li>{@link #prestigeValue Prestige Value}
* </p>
* @return {@code String} - a string representation of this {@code TribeCard}.
* @see it.polimi.ingsw.gc14.Model.Cards.TribeCard TribeCard
* @see it.polimi.ingsw.gc14.Model.Game Game
* @see it.polimi.ingsw.gc14.Model.GamePackage.Board Board
*/
@Override @Override
public String toStringBoard() public String toStringBoard()
{ {
@@ -5,7 +5,6 @@ import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;
import it.polimi.ingsw.gc14.Model.Player; import it.polimi.ingsw.gc14.Model.Player;
public class Gatherer extends Character { public class Gatherer extends Character {
/** /**
* Creates a Gatherer character card with the specified era. * Creates a Gatherer character card with the specified era.
* *
@@ -5,6 +5,12 @@ import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;
import it.polimi.ingsw.gc14.Model.Player; import it.polimi.ingsw.gc14.Model.Player;
public class Hunter extends Character { public class Hunter extends Character {
/**
* Describes whether the {@code Hunter Icon} is present or not. Whenever an
* {@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 boolean icon;
/** /**
@@ -53,6 +59,18 @@ public class Hunter extends Character {
} }
return toPrint; return toPrint;
} }
/**
* Prints a string representation of this {@code TribeCard}. This specific variation is used in the {@code Game}'s
* toString to print a more detailed version.
* <p>Potentially includes:
* <li>{@link #icon Icon}
* </p>
* @return {@code String} - a string representation of this {@code TribeCard}.
* @see it.polimi.ingsw.gc14.Model.Cards.TribeCard TribeCard
* @see it.polimi.ingsw.gc14.Model.Game Game
* @see it.polimi.ingsw.gc14.Model.GamePackage.Board Board
*/
@Override @Override
public String toStringBoard() { public String toStringBoard() {
String toPrint = super.toStringBoard(); String toPrint = super.toStringBoard();
@@ -62,7 +80,6 @@ public class Hunter extends Character {
return toPrint; return toPrint;
} }
/** /**
* Creates and returns a copy of this Hunter card. * Creates and returns a copy of this Hunter card.
* *
@@ -4,6 +4,9 @@ import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;
import it.polimi.ingsw.gc14.Model.Player; import it.polimi.ingsw.gc14.Model.Player;
public class Inventor extends Character { public class Inventor extends Character {
/**
* The {@code Icons}'s ID. There are a total of 10 different Icons.
*/
private int icon; private int icon;
/** /**
@@ -54,6 +57,18 @@ public class Inventor extends Character {
public String toString() { public String toString() {
return super.toString() + " I_ID:" + String.valueOf(icon); return super.toString() + " I_ID:" + String.valueOf(icon);
} }
/**
* Prints a string representation of this {@code TribeCard}. This specific variation is used in the {@code Game}'s
* toString to print a more detailed version.
* <p>Includes:
* <li>{@link #icon Icons's ID}
* </p>
* @return {@code String} - a string representation of this {@code TribeCard}.
* @see it.polimi.ingsw.gc14.Model.Cards.TribeCard TribeCard
* @see it.polimi.ingsw.gc14.Model.Game Game
* @see it.polimi.ingsw.gc14.Model.GamePackage.Board Board
*/
@Override @Override
public String toStringBoard() { public String toStringBoard() {
return super.toStringBoard() + " I_ID:" + String.valueOf(icon); return super.toStringBoard() + " I_ID:" + String.valueOf(icon);
@@ -6,7 +6,13 @@ import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;
import it.polimi.ingsw.gc14.Model.Player; import it.polimi.ingsw.gc14.Model.Player;
public class Shaman extends Character { public class Shaman extends Character {
/**
* The number of star {@code Icons} the card possesses.
* During the {@link it.polimi.ingsw.gc14.Model.Cards.TribeCards.Events.ShamanicRitual Shamanic Ritual Event}, having the
* majority of these icons provides Prestige Points;
* having the minority, on the other hand, results in
* losing Prestige Points.
*/
private int icon; private int icon;
/** /**
@@ -51,12 +57,23 @@ public class Shaman extends Character {
public String toString() { public String toString() {
return super.toString() + " *:" + String.valueOf(icon); return super.toString() + " *:" + String.valueOf(icon);
} }
/**
* Prints a string representation of this {@code TribeCard}. This specific variation is used in the {@code Game}'s
* toString to print a more detailed version.
* <p>Includes:
* <li>{@link #icon Number of stars}
* </p>
* @return {@code String} - a string representation of this {@code TribeCard}.
* @see it.polimi.ingsw.gc14.Model.Cards.TribeCard TribeCard
* @see it.polimi.ingsw.gc14.Model.Game Game
* @see it.polimi.ingsw.gc14.Model.GamePackage.Board Board
*/
@Override @Override
public String toStringBoard() { public String toStringBoard() {
return super.toStringBoard() + " *:" + String.valueOf(icon); return super.toStringBoard() + " *:" + String.valueOf(icon);
} }
/** /**
* Creates and returns a copy of this Shaman card. * Creates and returns a copy of this Shaman card.
* *
@@ -64,6 +64,17 @@ public abstract class EventCard extends TribeCard {
public String toString() { public String toString() {
return super.toString()+" "+type.toString(); return super.toString()+" "+type.toString();
} }
/**
* Prints a string representation of this {@code EventCard}. This specific variation is used in the {@code Game}'s
* toString to print a more detailed version.
* <p>Includes:
* <li>{@link #type Type}
* </p>
* @return {@code String} - a string representation of this {@code EventCard}.
* @see it.polimi.ingsw.gc14.Model.Game Game
* @see it.polimi.ingsw.gc14.Model.GamePackage.Board Board
*/
@Override @Override
public String toStringBoard() { public String toStringBoard() {
return super.toString()+" "+type.toString(); return super.toString()+" "+type.toString();
@@ -86,6 +86,24 @@ public class CavePaintings extends EventCard {
return new CavePaintings(getEra(), NLower, NPrestigeRem, NPrestigeMul) ; return new CavePaintings(getEra(), NLower, NPrestigeRem, NPrestigeMul) ;
} }
/**
* Prints a string representation of this {@code TribeCard}. This specific variation is used in the {@code Game}'s
* toString to print a more detailed version.
* <p>NOTE: {@code NUpper} is not a real attribute used in calculations (only {@code NLower} is needed),
* however it's a parameter on the cards' design.
* </p>
* <p>Includes:
* <li>{@link #NLower}
* <li>{@code NUpper}
* <li>{@link #NPrestigeRem}
* <li>{@link #NPrestigeMul}
* </p>
* @return {@code String} - a string representation of this {@code TribeCard}.
* @see it.polimi.ingsw.gc14.Model.Cards.TribeCard TribeCard
* @see it.polimi.ingsw.gc14.Model.Game Game
* @see it.polimi.ingsw.gc14.Model.GamePackage.Board Board
*/
@Override @Override
public String toStringBoard() { public String toStringBoard() {
return super.toString()+" 0-"+(NLower-1)+":"+NPrestigeRem+" "+NLower+"+:"+NPrestigeMul; return super.toString()+" 0-"+(NLower-1)+":"+NPrestigeRem+" "+NLower+"+:"+NPrestigeMul;
@@ -70,6 +70,18 @@ public class Hunt extends EventCard {
public EventCard clone() { public EventCard clone() {
return new Hunt(getEra(), prestigeMultiplier); return new Hunt(getEra(), prestigeMultiplier);
} }
/**
* Prints a string representation of this {@code TribeCard}. This specific variation is used in the {@code Game}'s
* toString to print a more detailed version.
* <p>includes:
* <li>{@link #prestigeMultiplier}
* </p>
* @return {@code String} - a string representation of this {@code TribeCard}.
* @see it.polimi.ingsw.gc14.Model.Cards.TribeCard TribeCard
* @see it.polimi.ingsw.gc14.Model.Game Game
* @see it.polimi.ingsw.gc14.Model.GamePackage.Board Board
*/
@Override @Override
public String toStringBoard() { public String toStringBoard() {
return super.toString()+" 1F+"+prestigeMultiplier+"PP"+" X N Hunter"; return super.toString()+" 1F+"+prestigeMultiplier+"PP"+" X N Hunter";
@@ -96,6 +96,19 @@ public class ShamanicRitual extends EventCard {
public EventCard clone() { public EventCard clone() {
return new ShamanicRitual(getEra(), prestigeToAdd, prestigeToRemove); return new ShamanicRitual(getEra(), prestigeToAdd, prestigeToRemove);
} }
/**
* Prints a string representation of this {@code TribeCard}. This specific variation is used in the {@code Game}'s
* toString to print a more detailed version.
* <p>Includes:
* <li>{@link #prestigeToAdd}
* <li>{@link #prestigeToRemove}
* </p>
* @return {@code String} - a string representation of this {@code TribeCard}.
* @see it.polimi.ingsw.gc14.Model.Cards.TribeCard TribeCard
* @see it.polimi.ingsw.gc14.Model.Game Game
* @see it.polimi.ingsw.gc14.Model.GamePackage.Board Board
*/
@Override @Override
public String toStringBoard() { public String toStringBoard() {
return super.toString()+" *>:"+prestigeToAdd+" *<:"+prestigeToRemove; return super.toString()+" *>:"+prestigeToAdd+" *<:"+prestigeToRemove;
@@ -90,6 +90,17 @@ public class Sustenance extends EventCard {
return new Sustenance(getEra(), PrestigeDebt); return new Sustenance(getEra(), PrestigeDebt);
} }
/**
* Prints a string representation of this {@code TribeCard}. This specific variation is used in the {@code Game}'s
* toString to print a more detailed version.
* <p>Includes:
* <li>{@link #PrestigeDebt}
* </p>
* @return {@code String} - a string representation of this {@code TribeCard}.
* @see it.polimi.ingsw.gc14.Model.Cards.TribeCard TribeCard
* @see it.polimi.ingsw.gc14.Model.Game Game
* @see it.polimi.ingsw.gc14.Model.GamePackage.Board Board
*/
@Override @Override
public String toStringBoard() { public String toStringBoard() {
return super.toString()+" -1F/-"+PrestigeDebt+"PP"; return super.toString()+" -1F/-"+PrestigeDebt+"PP";
@@ -1,7 +1,6 @@
package it.polimi.ingsw.gc14.Model; package it.polimi.ingsw.gc14.Model;
import com.google.gson.*; import com.google.gson.*;
import it.polimi.ingsw.gc14.Model.Cards.Building.EffectType;
import it.polimi.ingsw.gc14.Model.Cards.Building.Effects.*; import it.polimi.ingsw.gc14.Model.Cards.Building.Effects.*;
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard; import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType; import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;
@@ -16,9 +15,10 @@ import java.io.*;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.*; import java.util.*;
//TODO javadoc
public class DecksCreator { public class DecksCreator {
//TODO javadoc
public static List<TribeCard> loadTribeDeckByEra(int era) throws IllegalArgumentException public static List<TribeCard> loadTribeDeckByEra(int era) throws IllegalArgumentException
{ {
return switch (era) { return switch (era) {
@@ -28,6 +28,8 @@ public class DecksCreator {
default -> throw new IllegalArgumentException(); default -> throw new IllegalArgumentException();
}; };
} }
//TODO javadoc
public static List<TribeCard> loadTribeDeck(String resourcePath) { public static List<TribeCard> loadTribeDeck(String resourcePath) {
Gson gson = new Gson(); Gson gson = new Gson();
Type listType = new com.google.gson.reflect.TypeToken<List<TribeCardDefinition>>(){}.getType(); Type listType = new com.google.gson.reflect.TypeToken<List<TribeCardDefinition>>(){}.getType();
@@ -48,11 +50,15 @@ public class DecksCreator {
throw new RuntimeException("Errore caricamento mazzo: " + resourcePath, e); throw new RuntimeException("Errore caricamento mazzo: " + resourcePath, e);
} }
} }
//TODO javadoc
public static List<BuildingCard> loadBuildingDeckByEra(int era) throws IllegalArgumentException public static List<BuildingCard> loadBuildingDeckByEra(int era) throws IllegalArgumentException
{ {
if(era<=0 || era>3) throw new IllegalArgumentException(); if(era<=0 || era>3) throw new IllegalArgumentException();
return loadBuildingDeck("/Cards/buildingCards.json").stream().filter(x->x.getEra()==era).toList(); return loadBuildingDeck("/Cards/buildingCards.json").stream().filter(x->x.getEra()==era).toList();
} }
//TODO javadoc
public static List<BuildingCard> loadBuildingDeck(String resourcePath) { public static List<BuildingCard> loadBuildingDeck(String resourcePath) {
Gson gson = new Gson(); Gson gson = new Gson();
Type listType = new com.google.gson.reflect.TypeToken<List<BuildingCardDefinition>>(){}.getType(); Type listType = new com.google.gson.reflect.TypeToken<List<BuildingCardDefinition>>(){}.getType();
@@ -74,6 +80,7 @@ public class DecksCreator {
} }
} }
//TODO javadoc
public static List<Slot> loadSlotDeck() public static List<Slot> loadSlotDeck()
{ {
List<Slot> slots = new ArrayList<>(); List<Slot> slots = new ArrayList<>();
@@ -82,6 +89,8 @@ public class DecksCreator {
slots.add(new Slot(c)); slots.add(new Slot(c));
return slots; return slots;
} }
//TODO javadoc
private static TribeCard createCard(TribeCardDefinition def) { private static TribeCard createCard(TribeCardDefinition def) {
int era = def.era; int era = def.era;
@@ -129,6 +138,7 @@ public class DecksCreator {
}; };
} }
//TODO javadoc
private static BuildingCard createCard(BuildingCardDefinition def) { private static BuildingCard createCard(BuildingCardDefinition def) {
return switch (def.effectId) { return switch (def.effectId) {
case 0 -> new Building0(def.era, def.price, def.prestigeValue); case 0 -> new Building0(def.era, def.price, def.prestigeValue);
@@ -143,7 +153,7 @@ public class DecksCreator {
} }
//TODO javadoc
private static class TribeCardDefinition { private static class TribeCardDefinition {
String type; String type;
int era; int era;
@@ -152,6 +162,7 @@ public class DecksCreator {
List<Object> params; // Object per gestire boolean e int misti List<Object> params; // Object per gestire boolean e int misti
} }
//TODO javadoc
private static class BuildingCardDefinition { private static class BuildingCardDefinition {
int effectId; int effectId;
int era; int era;
@@ -758,6 +758,16 @@ public class Game implements Serializable {
return true; return true;
} }
/**
* Prints a string representation of the {@code Game}. Used in the TUI implementation to draw:
* <li>{@link it.polimi.ingsw.gc14.Model.GamePackage.Board Board}
* <li>{@link it.polimi.ingsw.gc14.Model.Player Players}
* <li>{@link #getUpperListTribeCards() Upper TribeCard List} <li>{@link #getUpperListBuilding() Upper Building List}
* <li>{@link #getLowerListTribeCards() Lower TribeCard List} <li>{@link #getLowerListBuilding() Lower Building List}
* <li>{@link it.polimi.ingsw.gc14.Model.OrderLogicCard Offer Track}
*
* @return {@code String} - a string representation of the {@code Game}.
*/
@Override @Override
public String toString() { public String toString() {
return PlayersStamp()+"\n"+BoardStamp()+"\n"; return PlayersStamp()+"\n"+BoardStamp()+"\n";
@@ -12,9 +12,13 @@ import java.util.stream.Collectors;
public abstract class OrderLogicCard implements Serializable { public abstract class OrderLogicCard implements Serializable {
/** /**
* The queue of players associated with this order logic card. * The queue of {@link Player Players} associated with this order logic card.
*/ */
protected Queue<Player> players; protected Queue<Player> players;
/**
* The list of {@link Player Players} associated with this order logic card.
*/
protected List<OrderPlayer> playerList; protected List<OrderPlayer> playerList;
@@ -98,6 +102,12 @@ public abstract class OrderLogicCard implements Serializable {
player.addFood(1); player.addFood(1);
} }
/**
* Returns the {@code Player}'s position based on it's {@code Username}.
* @param username The desired {@code Player}'s username.
* @return {@code int} - the {@code Player}'s position.
* @see Player
*/
protected int getPosition(String username) protected int getPosition(String username)
{ {
int pos = 0; int pos = 0;
@@ -26,7 +26,7 @@ public class Order2 extends OrderLogicCard {
/** /**
* Applies the effect associated with the specified position index for the given player. * Applies the effect associated with the specified position index for the given player.
* <p>If {@code index == 0}, the player gains 1 Food and the building effect is applied. * <p>If {@code index == 0}, the player gains 1 Food and the building effect is applied.
* <p>If {@code index == 1}, the player tries to remove 1 Food; if the player cannot remove it, * <p>If {@code index == 1}, the player tries to remove 1 Food; if the player pay it,
* the player loses 2 Prestige. * the player loses 2 Prestige.
* *
* @param player the player to whom the effect is applied. * @param player the player to whom the effect is applied.
@@ -27,7 +27,8 @@ public class Order3 extends OrderLogicCard {
* Applies the effect associated with the specified position index for the given player. * Applies the effect associated with the specified position index for the given player.
* <p>If {@code index == 0}, the player gains 2 Food and the building effect is applied. * <p>If {@code index == 0}, the player gains 2 Food and the building effect is applied.
* <p>If {@code index == 1}, no effect is applied. * <p>If {@code index == 1}, no effect is applied.
* <p>If {@code index == 2}, if the player can remove 1 Food, the player loses 2 Prestige. * <p>If {@code index == 2}, the player tries to remove 1 Food; if the player pay it,
* the player loses 2 Prestige.
* *
* @param player the player to whom the effect is applied. * @param player the player to whom the effect is applied.
* @param index the position index of the effect to apply. * @param index the position index of the effect to apply.
@@ -28,7 +28,7 @@ public class Order4 extends OrderLogicCard {
* <p>If {@code index == 0}, the player gains 2 Food and the building effect is applied. * <p>If {@code index == 0}, the player gains 2 Food and the building effect is applied.
* <p>If {@code index == 1}, the player gains 1 Food and the building effect is applied. * <p>If {@code index == 1}, the player gains 1 Food and the building effect is applied.
* <p>If {@code index == 2}, no effect is applied. * <p>If {@code index == 2}, no effect is applied.
* <p>If {@code index == 3}, the player tries to remove 1 Food; if the removal succeeds, * <p>If {@code index == 3}, the player tries to remove 1 Food; if the player pay it,
* the player loses 2 Prestige. * the player loses 2 Prestige.
* *
* @param player the player to whom the effect is applied. * @param player the player to whom the effect is applied.
@@ -29,7 +29,7 @@ public class Order5 extends OrderLogicCard {
* <p>If {@code index == 1}, the player gains 1 Food and the building effect is applied. * <p>If {@code index == 1}, the player gains 1 Food and the building effect is applied.
* <p>If {@code index == 2}, no effect is applied. * <p>If {@code index == 2}, no effect is applied.
* <p>If {@code index == 3}, no effect is applied. * <p>If {@code index == 3}, no effect is applied.
* <p>If {@code index == 4}, the player tries to remove 1 Food; if the removal succeeds, * <p>If {@code index == 4}, the player tries to remove 1 Food; if the player pay it,
* the player loses 2 Prestige. * the player loses 2 Prestige.
* *
* @param player the player to whom the effect is applied. * @param player the player to whom the effect is applied.
@@ -5,9 +5,10 @@ import it.polimi.ingsw.gc14.Model.Player;
import java.io.Serializable; import java.io.Serializable;
/** /**
* Abstract base class for all order logic cards. * Abstract base class for all order {@code logic cards}.
* An OrderLogicCard manages a queue of players and defines the effects * An {@code OrderLogicCard} manages a queue of {@code players} and defines the effects
* applied when players are pushed back into the queue. * applied when they are pushed back into the queue.
* @see it.polimi.ingsw.gc14.Model.Player Player
*/ */
public class OrderPlayer implements Serializable { public class OrderPlayer implements Serializable {
public Player player; public Player player;
@@ -45,6 +45,14 @@ public abstract class PlayableCard implements Serializable {
public String toString() { public String toString() {
return "⎕:"; return "⎕:";
} }
/**
* Prints a string representation of this {@code PlayableCard}. This specific variation is used in the {@code Game}'s
* toString to print a more detailed version (in this specific case the two methods are equal).
* @return {@code String} - a string representation of this {@code PlayableCard}.
* @see it.polimi.ingsw.gc14.Model.Game Game
* @see it.polimi.ingsw.gc14.Model.GamePackage.Board Board
*/
public String toStringBoard() public String toStringBoard()
{ {
return "⎕:"; return "⎕:";
@@ -8,7 +8,6 @@ import it.polimi.ingsw.gc14.View.TUI.AsciiTable;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import static it.polimi.ingsw.gc14.View.TUI.BorderStyle.*; import static it.polimi.ingsw.gc14.View.TUI.BorderStyle.*;
@@ -125,13 +124,6 @@ public class Player implements Serializable {
public int getPrestigeValue() { public int getPrestigeValue() {
return PrestigeValue; return PrestigeValue;
} }
/* TODO
* private Game game;
* public Game getGame(){
* return Game;
* }
*/
// endregion getters // endregion getters
// region Setters // region Setters
@@ -228,17 +220,34 @@ public class Player implements Serializable {
// endregion constructors // endregion constructors
// region Functions // region Functions
/**
* Prints the {@code Player}'s attributes for the {@code Board}'s representation.
* Uses the {@code UNICODE} border style.
* <p><b>Includes:</b>
* <li>{@link #FoodValue Food}
* <li>{@link #PrestigeValue Prestige}
* <li>{@link #artists Artists}
* <li>{@link #builders Builders}
* <li>{@link #gatherers Gatherers}
* <li>{@link #shamans Shamans}
* <li>{@link #inventors Inventors}
* <li>{@link #hunters Hunters}
* <li>{@link #buildingCards Buildings}
* </p>
* @return {@code String} - A string representation of the {@code Player}'s attributes.
* @see it.polimi.ingsw.gc14.View.TUI.BorderStyle BorderStyle
*/
@Override @Override
public String toString() { public String toString() {
int Last = 6; int Last = -1;
var table = new AsciiTable(UNICODE, 1); var table = new AsciiTable(UNICODE, 1);
table.addHeader(this.getUserName()); table.addHeader(this.getUserName());
table.addRow("RESOURCES:"); table.addRow("RESOURCES:");
table.addRow("Food: " + this.getFoodValue()); table.addRow("Food: " + this.getFoodValue());
table.addSeparator();
table.addRow("Prestige: " + this.getPrestigeValue()); table.addRow("Prestige: " + this.getPrestigeValue());
table.addSeparator();
if(!this.hunters.isEmpty()){ if(!this.hunters.isEmpty()){
Last = 6; Last = 6;
@@ -267,44 +276,44 @@ public class Player implements Serializable {
} }
table.addRow("CHARACTERS:"); table.addRow("CHARACTERS:");
if(!this.artists.isEmpty()){ if(!this.artists.isEmpty()){
table.addRow("Artists: " + this.artists.toString());
if(Last == 1){ if(Last == 1){
table.addSeparator(); table.addSeparator();
} }
table.addRow("Artists: " + this.artists.toString());
} }
if(!this.builders.isEmpty()){ if(!this.builders.isEmpty()){
table.addRow("Builders: " + this.builders.toString());
if(Last == 2){ if(Last == 2){
table.addSeparator(); table.addSeparator();
} }
table.addRow("Builders: " + this.builders.toString());
} }
if(!this.gatherers.isEmpty()){ if(!this.gatherers.isEmpty()){
table.addRow("Gatherers: " + this.gatherers.toString());
if(Last == 3){ if(Last == 3){
table.addSeparator(); table.addSeparator();
} }
table.addRow("Gatherers: " + this.gatherers.toString());
} }
if(!this.shamans.isEmpty()){ if(!this.shamans.isEmpty()){
table.addRow("Shamans: " + this.shamans.toString());
if(Last == 4){ if(Last == 4){
table.addSeparator(); table.addSeparator();
} }
table.addRow("Shamans: " + this.shamans.toString());
} }
if(!this.inventors.isEmpty()){ if(!this.inventors.isEmpty()){
table.addRow("Inventors: " + this.inventors.toString());
if(Last == 5){ if(Last == 5){
table.addSeparator(); table.addSeparator();
} }
table.addRow("Inventors: " + this.inventors.toString());
} }
if(!this.hunters.isEmpty()){ if(!this.hunters.isEmpty()){
table.addSeparator();
table.addRow("Hunters: " + this.hunters.toString()); table.addRow("Hunters: " + this.hunters.toString());
table.addSeparator();
} }
table.addRow("BUILDING CARDS:"); table.addRow("BUILDING CARDS:");
@@ -156,6 +156,19 @@ public class Slot implements Serializable {
} }
/**
* Prints a string representation of this {@code Slot}. This specific variation is used in the {@code Game}'s
* toString to print a more detailed version for the TUI implementation.
* <p>includes:
* <li>{@link #slotId SlotId}
* <li>{@link #NUpper NUpper}
* <li>{@link #NLower NLower}
* <li>{@link #Food Food}
* </p>
* @return {@code String} - a string representation of this {@code Slot}.
* @see it.polimi.ingsw.gc14.Model.Game Game
* @see it.polimi.ingsw.gc14.Model.GamePackage.Board Board
*/
public String toStringTUI() public String toStringTUI()
{ {
StringBuilder s = new StringBuilder(); StringBuilder s = new StringBuilder();
@@ -4,23 +4,39 @@ import it.polimi.ingsw.gc14.Controller.GameController;
import java.io.Serializable; import java.io.Serializable;
//TODO javadoc
public abstract class NetworkEvent implements Serializable { public abstract class NetworkEvent implements Serializable {
//TODO javadoc
protected String username; protected String username;
//TODO javadoc
public String getUsername() { public String getUsername() {
return username; return username;
} }
//TODO javadoc
protected EventType eventType; protected EventType eventType;
//TODO javadoc
public EventType getEventType() {return eventType;} public EventType getEventType() {return eventType;}
//TODO javadoc
protected boolean isError; protected boolean isError;
//TODO javadoc
public boolean getIsError() {return isError;} public boolean getIsError() {return isError;}
//TODO javadoc
public void setIsError(boolean isError) {this.isError = isError;} public void setIsError(boolean isError) {this.isError = isError;}
//TODO javadoc
protected NetworkEvent(String username, EventType eventType, boolean isError) { protected NetworkEvent(String username, EventType eventType, boolean isError) {
this.username = username; this.username = username;
this.eventType = eventType; this.eventType = eventType;
this.isError = isError; this.isError = isError;
} }
//TODO javadoc
@Override @Override
public String toString() { public String toString() {
if(isError) { if(isError) {
@@ -30,5 +46,6 @@ public abstract class NetworkEvent implements Serializable {
} }
} }
//TODO javadoc
public abstract boolean apply(GameController gameController); public abstract boolean apply(GameController gameController);
} }
@@ -7,15 +7,23 @@ import it.polimi.ingsw.gc14.View.IView;
import java.io.Serializable; import java.io.Serializable;
//TODO javadoc
public class AddPlayer extends NetworkEvent implements Serializable { public class AddPlayer extends NetworkEvent implements Serializable {
//TODO javadoc
private int proposedNPlayer; private int proposedNPlayer;
//TODO javadoc
public int getProposedNPlayer() { public int getProposedNPlayer() {
return proposedNPlayer; return proposedNPlayer;
} }
//TODO javadoc
public AddPlayer(String username, int proposedNPlayer) { public AddPlayer(String username, int proposedNPlayer) {
super(username, EventType.ADD_PLAYER, false); super(username, EventType.ADD_PLAYER, false);
this.proposedNPlayer = proposedNPlayer; this.proposedNPlayer = proposedNPlayer;
} }
//TODO javadoc
@Override @Override
public boolean apply(GameController gameController) public boolean apply(GameController gameController)
{ {
@@ -7,19 +7,24 @@ import it.polimi.ingsw.gc14.View.IView;
import java.io.Serializable; import java.io.Serializable;
//TODO javadoc
public class DrawLowerBuildingCard extends NetworkEvent implements Serializable{ public class DrawLowerBuildingCard extends NetworkEvent implements Serializable{
//TODO javadoc
private int pos; private int pos;
//TODO javadoc
public DrawLowerBuildingCard(String username, int pos){ public DrawLowerBuildingCard(String username, int pos){
super(username, EventType.DRAW_LOWER_BUILD, false); super(username, EventType.DRAW_LOWER_BUILD, false);
this.pos = pos; this.pos = pos;
} }
//TODO javadoc
@Override @Override
public boolean apply(GameController gameController){ public boolean apply(GameController gameController){
return gameController.drawLowerBuildingCard(username, pos); return gameController.drawLowerBuildingCard(username, pos);
} }
//TODO javadoc
public String apply(IView gameController){ public String apply(IView gameController){
return gameController.toString(); return gameController.toString();
} }
@@ -8,18 +8,22 @@ import it.polimi.ingsw.gc14.View.IView;
import java.io.Serializable; import java.io.Serializable;
public class DrawLowerTribeCard extends NetworkEvent implements Serializable{ public class DrawLowerTribeCard extends NetworkEvent implements Serializable{
//TODO javadoc
private int pos; private int pos;
//TODO javadoc
public DrawLowerTribeCard(String username, int pos){ public DrawLowerTribeCard(String username, int pos){
super(username, EventType.DRAW_LOWER_TRIBE, false); super(username, EventType.DRAW_LOWER_TRIBE, false);
this.pos = pos; this.pos = pos;
} }
//TODO javadoc
@Override @Override
public boolean apply(GameController gameController){ public boolean apply(GameController gameController){
return gameController.drawLowerTribeCard(username, pos); return gameController.drawLowerTribeCard(username, pos);
} }
//TODO javadoc
public String apply(IView gameController){ public String apply(IView gameController){
return gameController.toString(); return gameController.toString();
} }
@@ -7,19 +7,24 @@ import it.polimi.ingsw.gc14.View.IView;
import java.io.Serializable; import java.io.Serializable;
//TODO javadoc
public class DrawUpperBuildingCard extends NetworkEvent implements Serializable{ public class DrawUpperBuildingCard extends NetworkEvent implements Serializable{
//TODO javadoc
private int pos; private int pos;
//TODO javadoc
public DrawUpperBuildingCard(String username, int pos){ public DrawUpperBuildingCard(String username, int pos){
super(username, EventType.DRAW_UPPER_BUILD, false); super(username, EventType.DRAW_UPPER_BUILD, false);
this.pos = pos; this.pos = pos;
} }
//TODO javadoc
@Override @Override
public boolean apply(GameController gameController){ public boolean apply(GameController gameController){
return gameController.drawUpperBuildingCard(username, pos); return gameController.drawUpperBuildingCard(username, pos);
} }
//TODO javadoc
public String apply(IView gameController){ public String apply(IView gameController){
return gameController.toString(); return gameController.toString();
} }
@@ -7,19 +7,24 @@ import it.polimi.ingsw.gc14.View.IView;
import java.io.Serializable; import java.io.Serializable;
//TODO javadoc
public class DrawUpperTribeCard extends NetworkEvent implements Serializable{ public class DrawUpperTribeCard extends NetworkEvent implements Serializable{
//TODO javadoc
private int pos; private int pos;
//TODO javadoc
public DrawUpperTribeCard(String username, int pos){ public DrawUpperTribeCard(String username, int pos){
super(username, EventType.DRAW_UPPER_TRIBE, false); super(username, EventType.DRAW_UPPER_TRIBE, false);
this.pos = pos; this.pos = pos;
} }
//TODO javadoc
@Override @Override
public boolean apply(GameController gameController){ public boolean apply(GameController gameController){
return gameController.drawUpperTribeCard(username, pos); return gameController.drawUpperTribeCard(username, pos);
} }
//TODO javadoc
public String apply(IView gameController){ public String apply(IView gameController){
return gameController.toString(); return gameController.toString();
} }
@@ -7,19 +7,24 @@ import it.polimi.ingsw.gc14.View.IView;
import java.io.Serializable; import java.io.Serializable;
//TODO javadoc
public class PickOptionalBuildingCard extends NetworkEvent implements Serializable{ public class PickOptionalBuildingCard extends NetworkEvent implements Serializable{
//TODO javadoc
private int pos; private int pos;
//TODO javadoc
public PickOptionalBuildingCard(String username, int pos){ public PickOptionalBuildingCard(String username, int pos){
super(username, EventType.PICK_OPTIONAL_BUILD, false); super(username, EventType.PICK_OPTIONAL_BUILD, false);
this.pos = pos; this.pos = pos;
} }
//TODO javadoc
@Override @Override
public boolean apply(GameController gameController){ public boolean apply(GameController gameController){
return gameController.pickOptionalBuildingCard(username, pos); return gameController.pickOptionalBuildingCard(username, pos);
} }
//TODO javadoc
public String apply(IView gameController){ public String apply(IView gameController){
return gameController.toString(); return gameController.toString();
} }
@@ -7,19 +7,25 @@ import it.polimi.ingsw.gc14.View.IView;
import java.io.Serializable; import java.io.Serializable;
//TODO javadoc
public class PickOptionalTribeCard extends NetworkEvent implements Serializable{ public class PickOptionalTribeCard extends NetworkEvent implements Serializable{
//TODO javadoc
private int pos; private int pos;
//TODO javadoc
public PickOptionalTribeCard(String username, int pos){ public PickOptionalTribeCard(String username, int pos){
super(username, EventType.PICK_OPTIONAL_TRIBE, false); super(username, EventType.PICK_OPTIONAL_TRIBE, false);
this.pos = pos; this.pos = pos;
} }
//TODO javadoc
@Override @Override
public boolean apply(GameController gameController){ public boolean apply(GameController gameController){
return gameController.pickOptionalTribeCard(username, pos); return gameController.pickOptionalTribeCard(username, pos);
} }
//TODO javadoc
public String apply(IView gameController){ public String apply(IView gameController){
return gameController.toString(); return gameController.toString();
} }
@@ -7,19 +7,24 @@ import it.polimi.ingsw.gc14.View.IView;
import java.io.Serializable; import java.io.Serializable;
//TODO javadoc
public class SlotChoice extends NetworkEvent implements Serializable { public class SlotChoice extends NetworkEvent implements Serializable {
//TODO javadoc
private int pos; private int pos;
//TODO javadoc
public SlotChoice(String username, int pos) { public SlotChoice(String username, int pos) {
super(username, EventType.SLOT_CHOICE, false); super(username, EventType.SLOT_CHOICE, false);
this.pos = pos; this.pos = pos;
} }
//TODO javadoc
@Override @Override
public boolean apply(GameController gameController) { public boolean apply(GameController gameController) {
return gameController.slotChoice(username, pos); return gameController.slotChoice(username, pos);
} }
//TODO javadoc
public String apply(IView gameController) { public String apply(IView gameController) {
return gameController.toString(); return gameController.toString();
} }
@@ -39,7 +39,7 @@ public class RMIClient implements IClient {
this.port = port; this.port = port;
} }
//TODO Javadoc fix
/** /**
* Connects to the RMI server and attempts to join the game. * Connects to the RMI server and attempts to join the game.
* Looks up the RMI registry to retrieve the {@link IGameServer} stub. * Looks up the RMI registry to retrieve the {@link IGameServer} stub.
@@ -1,22 +1,40 @@
package it.polimi.ingsw.gc14.View.TUI; package it.polimi.ingsw.gc14.View.TUI;
import java.util.*; import java.util.*;
//TODO javadoc
// Helper generale per costruire tabelle ASCII // Helper generale per costruire tabelle ASCII
public class AsciiTable { public class AsciiTable {
//TODO javadoc
private final BorderStyle s; private final BorderStyle s;
//TODO javadoc
private final int cols; private final int cols;
//TODO javadoc
private final List<List<String>> rows = new ArrayList<>(); private final List<List<String>> rows = new ArrayList<>();
//TODO javadoc
private final List<Integer> separators = new ArrayList<>(); private final List<Integer> separators = new ArrayList<>();
//TODO javadoc
public AsciiTable(BorderStyle s, int cols) { public AsciiTable(BorderStyle s, int cols) {
this.s = s; this.cols = cols; this.s = s; this.cols = cols;
} }
//TODO javadoc
public void addRow(String... cells) { rows.add(Arrays.asList(cells)); } public void addRow(String... cells) { rows.add(Arrays.asList(cells)); }
//TODO javadoc
public void addRow(List<String> cells) { rows.add(cells); } public void addRow(List<String> cells) { rows.add(cells); }
//TODO javadoc
public void addHeader(String... cells) { rows.add(0, Arrays.asList(cells)); separators.add(0); } public void addHeader(String... cells) { rows.add(0, Arrays.asList(cells)); separators.add(0); }
public void addSeparator() { separators.add(rows.size()-1); } public void addSeparator() { separators.add(rows.size()-1); }
//TODO javadoc
public void addSeparator() { separators.add(rows.size()-1); }
//TODO javadoc
public String build() { public String build() {
var sb = new StringBuilder(); var sb = new StringBuilder();
int maxWidth = rows.stream().mapToInt(x->x.stream().mapToInt(y->y.length()).max().getAsInt()).max().getAsInt()+1; int maxWidth = rows.stream().mapToInt(x->x.stream().mapToInt(y->y.length()).max().getAsInt()).max().getAsInt()+1;
@@ -34,6 +52,7 @@ public class AsciiTable {
return sb.toString(); return sb.toString();
} }
//TODO javadoc
private String hline(String l, String m, String r,int maxWidth) { private String hline(String l, String m, String r,int maxWidth) {
var sb = new StringBuilder(l); var sb = new StringBuilder(l);
for (int i = 0; i < cols; i++) { for (int i = 0; i < cols; i++) {
@@ -43,10 +62,13 @@ public class AsciiTable {
return sb.append(r).toString(); return sb.append(r).toString();
} }
//TODO javadoc
private static String rpad(String s, int w) { private static String rpad(String s, int w) {
if (s.length() >= w) return s.substring(0, w); if (s.length() >= w) return s.substring(0, w);
return s + " ".repeat(w - s.length()); return s + " ".repeat(w - s.length());
} }
//TODO javadoc
public static String sideBySide(List<String> left, List<String> right, int gap) { public static String sideBySide(List<String> left, List<String> right, int gap) {
int leftWidth = left.stream().mapToInt(String::length).max().orElse(0); int leftWidth = left.stream().mapToInt(String::length).max().orElse(0);
int maxHeight = Math.max(left.size(), right.size()); int maxHeight = Math.max(left.size(), right.size());