Merge pull request #25

JavaDoc-for-order
This commit is contained in:
GabrieleRadice
2026-04-12 19:46:16 +02:00
committed by GitHub
4 changed files with 77 additions and 5 deletions
@@ -1,18 +1,35 @@
package it.polimi.ingsw.gc14.Model.Orders;
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
import it.polimi.ingsw.gc14.Model.OrderLogicCard;
import it.polimi.ingsw.gc14.Model.Player;
import java.util.*;
public class Order2 extends OrderLogicCard {
/**
* Creates an Order2 logic card for a two-player game.
*
* @param players the list of players associated with this order card.
* @throws NoSuchElementException if the number of players is not equal to 2.
*/
public Order2(ArrayList<Player> players)throws NoSuchElementException {
if(players.size()!=2)
throw new NoSuchElementException();
super(players);
}
/**
* 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 == 1}, the player tries to remove 1 Food; if the player cannot remove it,
* the player loses 2 Prestige.
*
* @param player the player to whom the effect is applied.
* @param index the position index of the effect to apply.
* @throws IndexOutOfBoundsException if {@code index < 0} or {@code index >= 2}.
*/
@Override
protected void effect(Player player,int index) throws IndexOutOfBoundsException
{
@@ -29,7 +46,6 @@ public class Order2 extends OrderLogicCard {
if(index==1){
if(!player.removeFood(1)){
player.removePrestige(2);
return;
}
}
}
@@ -7,11 +7,29 @@ import java.util.ArrayList;
import java.util.NoSuchElementException;
public class Order3 extends OrderLogicCard {
/**
* Creates an Order3 logic card for a three-player game.
*
* @param players the list of players associated with this order card.
* @throws NoSuchElementException if the number of players is not equal to 3.
*/
public Order3(ArrayList<Player> players) throws NoSuchElementException{
if(players.size()!=3)
throw new NoSuchElementException();
super(players);
}
/**
* 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 == 1}, no effect is applied.
* <p>If {@code index == 2}, if the player can remove 1 Food, the player loses 2 Prestige.
*
* @param player the player to whom the effect is applied.
* @param index the position index of the effect to apply.
* @throws IndexOutOfBoundsException if {@code index < 0} or {@code index >= 3}.
*/
@Override
protected void effect(Player player,int index) throws IndexOutOfBoundsException
{
@@ -29,7 +47,6 @@ public class Order3 extends OrderLogicCard {
if(player.removeFood(1)){
player.removePrestige(2);
}
return;
}
}
}
@@ -7,11 +7,31 @@ import java.util.ArrayList;
import java.util.NoSuchElementException;
public class Order4 extends OrderLogicCard {
/**
* Creates an Order4 logic card for a four-player game.
*
* @param players the list of players associated with this order card.
* @throws NoSuchElementException if the number of players is not equal to 4.
*/
public Order4(ArrayList<Player> players)throws NoSuchElementException {
if(players.size()!=4)
throw new NoSuchElementException();
super(players);
}
/**
* 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 == 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 == 3}, the player tries to remove 1 Food; if the removal succeeds,
* the player loses 2 Prestige.
*
* @param player the player to whom the effect is applied.
* @param index the position index of the effect to apply.
* @throws IndexOutOfBoundsException if {@code index < 0} or {@code index >= 4}.
*/
@Override
protected void effect(Player player,int index) throws IndexOutOfBoundsException
{
@@ -35,7 +55,6 @@ public class Order4 extends OrderLogicCard {
if(player.removeFood(1)){
player.removePrestige(2);
}
return;
}
}
}
@@ -7,11 +7,32 @@ import java.util.ArrayList;
import java.util.NoSuchElementException;
public class Order5 extends OrderLogicCard {
/**
* Creates an Order5 logic card for a five-player game.
*
* @param players the list of players associated with this order card.
* @throws NoSuchElementException if the number of players is not equal to 5.
*/
public Order5(ArrayList<Player> players) throws NoSuchElementException{
if(players.size()!=5)
throw new NoSuchElementException();
super(players);
}
/**
* Applies the effect associated with the specified position index for the given player.
* <p>If {@code index == 0}, the player gains 3 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 == 3}, no effect is applied.
* <p>If {@code index == 4}, the player tries to remove 1 Food; if the removal succeeds,
* the player loses 2 Prestige.
*
* @param player the player to whom the effect is applied.
* @param index the position index of the effect to apply.
* @throws IndexOutOfBoundsException if {@code index < 0} or {@code index >= 5}.
*/
@Override
protected void effect(Player player,int index) throws IndexOutOfBoundsException
{
@@ -35,7 +56,6 @@ public class Order5 extends OrderLogicCard {
if(player.removeFood(1)){
player.removePrestige(2);
}
return;
}
}
}