Merge pull request #32
Javadoc-Slot-PlayableCard-OrderLogicCard-CurrentState
This commit is contained in:
@@ -4,39 +4,108 @@ import it.polimi.ingsw.gc14.Model.Player;
|
|||||||
import it.polimi.ingsw.gc14.Model.Slot;
|
import it.polimi.ingsw.gc14.Model.Slot;
|
||||||
import it.polimi.ingsw.gc14.Model.GamePackage.GameStages;
|
import it.polimi.ingsw.gc14.Model.GamePackage.GameStages;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents the current state of the game.
|
||||||
|
* A CurrentState object stores the current player, slot, era, round,
|
||||||
|
* remaining upper and lower cards, and the current game stage.
|
||||||
|
*/
|
||||||
public class CurrentState {
|
public class CurrentState {
|
||||||
// region Getters
|
// region Getters
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current player associated with the game state.
|
||||||
|
*/
|
||||||
private Player player;
|
private Player player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current player.
|
||||||
|
*
|
||||||
|
* @return the current player.
|
||||||
|
*/
|
||||||
public Player getCurrentPlayer(){
|
public Player getCurrentPlayer(){
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current slot associated with the game state.
|
||||||
|
*/
|
||||||
private Slot slot;
|
private Slot slot;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current slot.
|
||||||
|
*
|
||||||
|
* @return the current slot.
|
||||||
|
*/
|
||||||
public Slot getSlot(){
|
public Slot getSlot(){
|
||||||
return slot;
|
return slot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current era of the game.
|
||||||
|
*/
|
||||||
private int Era;
|
private int Era;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current era of the game.
|
||||||
|
*
|
||||||
|
* @return the current era of the game.
|
||||||
|
*/
|
||||||
public int getEra(){
|
public int getEra(){
|
||||||
return Era;
|
return Era;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current round of the game.
|
||||||
|
*/
|
||||||
private int round;
|
private int round;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current round of the game.
|
||||||
|
*
|
||||||
|
* @return the current round of the game.
|
||||||
|
*/
|
||||||
public int getRound(){
|
public int getRound(){
|
||||||
return round;
|
return round;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The number of upper cards currently available.
|
||||||
|
*/
|
||||||
private int NUpper;
|
private int NUpper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of upper cards currently available.
|
||||||
|
*
|
||||||
|
* @return the number of upper cards currently available.
|
||||||
|
*/
|
||||||
public int getNUpper(){
|
public int getNUpper(){
|
||||||
return NUpper;
|
return NUpper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The number of lower cards currently available.
|
||||||
|
*/
|
||||||
private int NLower;
|
private int NLower;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of lower cards currently available.
|
||||||
|
*
|
||||||
|
* @return the number of lower cards currently available.
|
||||||
|
*/
|
||||||
public int getNLower(){
|
public int getNLower(){
|
||||||
return NLower;
|
return NLower;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current stage of the game.
|
||||||
|
*/
|
||||||
private GameStages GameStage;
|
private GameStages GameStage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current stage of the game.
|
||||||
|
*
|
||||||
|
* @return the current stage of the game.
|
||||||
|
*/
|
||||||
public GameStages getGameStage(){
|
public GameStages getGameStage(){
|
||||||
return GameStage;
|
return GameStage;
|
||||||
}
|
}
|
||||||
@@ -44,28 +113,52 @@ public class CurrentState {
|
|||||||
// endregion getters
|
// endregion getters
|
||||||
|
|
||||||
// region Setters
|
// region Setters
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Increments the current era by 1.
|
||||||
|
*/
|
||||||
public void EraUpdate(){
|
public void EraUpdate(){
|
||||||
Era++;
|
Era++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Increments the current round by 1.
|
||||||
|
*/
|
||||||
public void RoundUpdate(){
|
public void RoundUpdate(){
|
||||||
round++;
|
round++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decrements the number of upper cards by 1.
|
||||||
|
*/
|
||||||
public void UpperDrawn(){
|
public void UpperDrawn(){
|
||||||
NUpper--;
|
NUpper--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decrements the number of lower cards by 1.
|
||||||
|
*/
|
||||||
public void LowerDrawn(){
|
public void LowerDrawn(){
|
||||||
NLower--;
|
NLower--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the current game stage.
|
||||||
|
*
|
||||||
|
* @param GameStage the new game stage.
|
||||||
|
*/
|
||||||
public void GameStageUpdate(GameStages GameStage){
|
public void GameStageUpdate(GameStages GameStage){
|
||||||
this.GameStage = GameStage;
|
this.GameStage = GameStage;
|
||||||
}
|
}
|
||||||
// endregion setters
|
// endregion setters
|
||||||
|
|
||||||
// region Constructors
|
// region Constructors
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new CurrentState object with default initial values.
|
||||||
|
* The initial player and slot are {@code null}, the era and round are set to 1,
|
||||||
|
* the number of upper and lower cards is set to 0, and the game stage is set to {@code WAITING}.
|
||||||
|
*/
|
||||||
public CurrentState(){
|
public CurrentState(){
|
||||||
this.player = null;
|
this.player = null;
|
||||||
this.slot = null;
|
this.slot = null;
|
||||||
@@ -78,6 +171,15 @@ public class CurrentState {
|
|||||||
// endregion constructors
|
// endregion constructors
|
||||||
|
|
||||||
// region Functions
|
// region Functions
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the current player and slot.
|
||||||
|
* If the specified slot is {@code null}, the numbers of upper and lower cards are both set to 0.
|
||||||
|
* Otherwise, the numbers of upper and lower cards are updated using the values of the specified slot.
|
||||||
|
*
|
||||||
|
* @param player the new current player.
|
||||||
|
* @param slot the new current slot.
|
||||||
|
*/
|
||||||
public void PlayerUpdate(Player player, Slot slot){
|
public void PlayerUpdate(Player player, Slot slot){
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.slot = slot;
|
this.slot = slot;
|
||||||
|
|||||||
@@ -4,25 +4,75 @@ import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
|
|||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract base class for all order logic cards.
|
||||||
|
* An OrderLogicCard manages a queue of players and defines the effects
|
||||||
|
* applied when players are pushed back into the queue.
|
||||||
|
*/
|
||||||
public abstract class OrderLogicCard {
|
public abstract class OrderLogicCard {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The queue of players associated with this order logic card.
|
||||||
|
*/
|
||||||
private Queue<Player> players;
|
private Queue<Player> players;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an order logic card with the specified list of players.
|
||||||
|
* The input list is shuffled before being inserted into the queue.
|
||||||
|
*
|
||||||
|
* @param players the list of players associated with this order logic card.
|
||||||
|
*/
|
||||||
public OrderLogicCard(ArrayList<Player> players) {
|
public OrderLogicCard(ArrayList<Player> players) {
|
||||||
Collections.shuffle(players);
|
Collections.shuffle(players);
|
||||||
this.players = new LinkedList<>(players);
|
this.players = new LinkedList<>(players);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applies the effect associated with the current queue position of the player
|
||||||
|
* and then adds the player to the end of the queue.
|
||||||
|
*
|
||||||
|
* @param player the player to be pushed into the queue.
|
||||||
|
*/
|
||||||
public void push(Player player){
|
public void push(Player player){
|
||||||
effect(player,players.size());
|
effect(player,players.size());
|
||||||
players.add(player);
|
players.add(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes and returns the first player in the queue.
|
||||||
|
*
|
||||||
|
* @return the first player in the queue, or {@code null} if the queue is empty.
|
||||||
|
*/
|
||||||
public Player pull(){
|
public Player pull(){
|
||||||
return players.poll();
|
return players.poll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the first player in the queue without removing it.
|
||||||
|
*
|
||||||
|
* @return the first player in the queue, or {@code null} if the queue is empty.
|
||||||
|
*/
|
||||||
public Player getFirst()
|
public Player getFirst()
|
||||||
{
|
{
|
||||||
return players.peek();
|
return players.peek();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applies the effect associated with the specified player and queue position.
|
||||||
|
*
|
||||||
|
* @param player the player to whom the effect is applied.
|
||||||
|
* @param index the queue position index associated with the effect.
|
||||||
|
* @throws IndexOutOfBoundsException if the specified index is not valid.
|
||||||
|
*/
|
||||||
protected abstract void effect(Player player, int index) throws IndexOutOfBoundsException;
|
protected abstract void effect(Player player, int index) throws IndexOutOfBoundsException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applies the building-related effect to the specified player.
|
||||||
|
* For each building card owned by the player with effect id equal to 3,
|
||||||
|
* the player gains 1 Food.
|
||||||
|
*
|
||||||
|
* @param player the player to whom the building effect is applied.
|
||||||
|
*/
|
||||||
protected void buildingEffect(Player player)
|
protected void buildingEffect(Player player)
|
||||||
{
|
{
|
||||||
for(BuildingCard b : player.buildingCards.stream().filter(x->x.getEffectId()==3).toList())
|
for(BuildingCard b : player.buildingCards.stream().filter(x->x.getEffectId()==3).toList())
|
||||||
|
|||||||
@@ -1,10 +1,31 @@
|
|||||||
package it.polimi.ingsw.gc14.Model;
|
package it.polimi.ingsw.gc14.Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract base class for all playable cards.
|
||||||
|
* A PlayableCard is characterized by an era value.
|
||||||
|
*/
|
||||||
public abstract class PlayableCard {
|
public abstract class PlayableCard {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The era associated with this playable card.
|
||||||
|
*/
|
||||||
private int Era;
|
private int Era;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the era of this playable card.
|
||||||
|
*
|
||||||
|
* @return the era of this playable card.
|
||||||
|
*/
|
||||||
public int getEra(){
|
public int getEra(){
|
||||||
return Era;
|
return Era;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a playable card with the specified era.
|
||||||
|
*
|
||||||
|
* @param Era the era of the playable card.
|
||||||
|
* @throws IllegalArgumentException if {@code Era <= 0} or {@code Era >= 4}.
|
||||||
|
*/
|
||||||
public PlayableCard (int Era) throws IllegalArgumentException{
|
public PlayableCard (int Era) throws IllegalArgumentException{
|
||||||
if (Era>0 && Era<4) {
|
if (Era>0 && Era<4) {
|
||||||
this.Era = Era;
|
this.Era = Era;
|
||||||
@@ -13,6 +34,11 @@ public abstract class PlayableCard {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the string representation of this playable card.
|
||||||
|
*
|
||||||
|
* @return the string representation of this playable card.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Era:"+String.valueOf(Era);
|
return "Era:"+String.valueOf(Era);
|
||||||
|
|||||||
@@ -1,26 +1,79 @@
|
|||||||
package it.polimi.ingsw.gc14.Model;
|
package it.polimi.ingsw.gc14.Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a slot with a specific identifier and associated values
|
||||||
|
* for upper cards, lower cards, food, and minimum number of players.
|
||||||
|
* The slot configuration depends on the specified slot identifier.
|
||||||
|
*/
|
||||||
public class Slot {
|
public class Slot {
|
||||||
// Getters
|
// Getters
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The identifier of this slot.
|
||||||
|
*/
|
||||||
private char slotId;
|
private char slotId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the identifier of this slot.
|
||||||
|
*
|
||||||
|
* @return the identifier of this slot.
|
||||||
|
*/
|
||||||
public char getSlotId() {
|
public char getSlotId() {
|
||||||
return slotId;
|
return slotId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The number of upper cards associated with this slot.
|
||||||
|
*/
|
||||||
private int NUpper;
|
private int NUpper;
|
||||||
|
/**
|
||||||
|
* Returns the number of upper cards associated with this slot.
|
||||||
|
*
|
||||||
|
* @return the number of upper cards associated with this slot.
|
||||||
|
*/
|
||||||
public int getNUpper(){
|
public int getNUpper(){
|
||||||
return NUpper;
|
return NUpper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The minimum number of players required for this slot.
|
||||||
|
*/
|
||||||
private int nMinPlayer;
|
private int nMinPlayer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the minimum number of players required for this slot.
|
||||||
|
*
|
||||||
|
* @return the minimum number of players required for this slot.
|
||||||
|
*/
|
||||||
public int getNMinPlayer()
|
public int getNMinPlayer()
|
||||||
{
|
{
|
||||||
return nMinPlayer;
|
return nMinPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The number of lower cards associated with this slot.
|
||||||
|
*/
|
||||||
private int NLower;
|
private int NLower;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of lower cards associated with this slot.
|
||||||
|
*
|
||||||
|
* @return the number of lower cards associated with this slot.
|
||||||
|
*/
|
||||||
public int getNLower(){
|
public int getNLower(){
|
||||||
return NLower;
|
return NLower;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The amount of Food associated with this slot.
|
||||||
|
*/
|
||||||
private int Food;
|
private int Food;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the amount of Food associated with this slot.
|
||||||
|
*
|
||||||
|
* @return the amount of Food associated with this slot.
|
||||||
|
*/
|
||||||
public int getFood(){
|
public int getFood(){
|
||||||
return Food;
|
return Food;
|
||||||
}
|
}
|
||||||
@@ -28,7 +81,17 @@ public class Slot {
|
|||||||
|
|
||||||
// Setters
|
// Setters
|
||||||
// End setters
|
// End setters
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a slot with the specified identifier.
|
||||||
|
* The slot values for Food, NLower, NUpper, and minimum number of players
|
||||||
|
* are determined by the given slot identifier.
|
||||||
|
*
|
||||||
|
* @param slotId the identifier of the slot.
|
||||||
|
* @throws IllegalArgumentException if the specified slot identifier is not valid.
|
||||||
|
*/
|
||||||
public Slot(char slotId) throws IllegalArgumentException
|
public Slot(char slotId) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
this.slotId = slotId;
|
this.slotId = slotId;
|
||||||
@@ -78,6 +141,14 @@ public class Slot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the string representation of this slot.
|
||||||
|
* The returned string includes the slot identifier, number of upper cards,
|
||||||
|
* number of lower cards, food value, and minimum number of players.
|
||||||
|
*
|
||||||
|
* @return the string representation of this slot.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return ("SlotID: "+this.getSlotId()+"\nNUpper: "+this.getNUpper()+"\nNLower: "+this.getNLower()+"\nFood: "+this.getFood()+"\nNMinPlayer: "+this.getNMinPlayer()+"\n");
|
return ("SlotID: "+this.getSlotId()+"\nNUpper: "+this.getNUpper()+"\nNLower: "+this.getNLower()+"\nFood: "+this.getFood()+"\nNMinPlayer: "+this.getNMinPlayer()+"\n");
|
||||||
|
|||||||
Reference in New Issue
Block a user