OrderLogicCard complete implementation
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
package it.polimi.ingsw.gc14.Model;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public abstract class OrderLogicCard {
|
||||
private Queue<Player> players;
|
||||
public OrderLogicCard(ArrayList<Player> players) {
|
||||
Collections.shuffle(players);
|
||||
this.players = new LinkedList<>(players);
|
||||
}
|
||||
public void push(Player player){
|
||||
players.add(player);
|
||||
}
|
||||
public Player pull(Player player){
|
||||
return players.remove();
|
||||
}
|
||||
protected abstract void effect(Player player, int index) throws IndexOutOfBoundsException;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package it.polimi.ingsw.gc14.Model.Orders;
|
||||
|
||||
import it.polimi.ingsw.gc14.Model.OrderLogicCard;
|
||||
import it.polimi.ingsw.gc14.Model.Player;
|
||||
import java.util.*;
|
||||
|
||||
public class Order2 extends OrderLogicCard {
|
||||
public Order2(ArrayList<Player> players) {
|
||||
super(players);
|
||||
}
|
||||
@Override
|
||||
public void effect(Player player,int index) throws IndexOutOfBoundsException
|
||||
{
|
||||
if(index>=2)
|
||||
{
|
||||
throw new IndexOutOfBoundsException("index out of bounds");
|
||||
}
|
||||
if(index==0)
|
||||
{
|
||||
player.addFood(1);
|
||||
return;
|
||||
}
|
||||
if(index==1){
|
||||
if(player.removeFood(1)){
|
||||
player.removePrestige(2);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package it.polimi.ingsw.gc14.Model.Orders;
|
||||
|
||||
import it.polimi.ingsw.gc14.Model.OrderLogicCard;
|
||||
import it.polimi.ingsw.gc14.Model.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Order3 extends OrderLogicCard {
|
||||
public Order3(ArrayList<Player> players) {
|
||||
super(players);
|
||||
}
|
||||
@Override
|
||||
public void effect(Player player,int index) throws IndexOutOfBoundsException
|
||||
{
|
||||
if(index>=3)
|
||||
{
|
||||
throw new IndexOutOfBoundsException("index out of bounds");
|
||||
}
|
||||
if(index==0)
|
||||
{
|
||||
player.addFood(2);
|
||||
return;
|
||||
}
|
||||
if(index==2){
|
||||
if(player.removeFood(1)){
|
||||
player.removePrestige(2);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package it.polimi.ingsw.gc14.Model.Orders;
|
||||
|
||||
import it.polimi.ingsw.gc14.Model.OrderLogicCard;
|
||||
import it.polimi.ingsw.gc14.Model.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Order4 extends OrderLogicCard {
|
||||
public Order4(ArrayList<Player> players) {
|
||||
super(players);
|
||||
}
|
||||
@Override
|
||||
public void effect(Player player,int index) throws IndexOutOfBoundsException
|
||||
{
|
||||
if(index>=4)
|
||||
{
|
||||
throw new IndexOutOfBoundsException("index out of bounds");
|
||||
}
|
||||
if(index==0)
|
||||
{
|
||||
player.addFood(2);
|
||||
return;
|
||||
}
|
||||
if(index==1)
|
||||
{
|
||||
player.addFood(1);
|
||||
return;
|
||||
}
|
||||
if(index==3){
|
||||
if(player.removeFood(1)){
|
||||
player.removePrestige(2);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package it.polimi.ingsw.gc14.Model.Orders;
|
||||
|
||||
import it.polimi.ingsw.gc14.Model.OrderLogicCard;
|
||||
import it.polimi.ingsw.gc14.Model.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Order5 extends OrderLogicCard {
|
||||
public Order5(ArrayList<Player> players) {
|
||||
super(players);
|
||||
}
|
||||
@Override
|
||||
public void effect(Player player,int index) throws IndexOutOfBoundsException
|
||||
{
|
||||
if(index>=5)
|
||||
{
|
||||
throw new IndexOutOfBoundsException("index out of bounds");
|
||||
}
|
||||
if(index==0)
|
||||
{
|
||||
player.addFood(3);
|
||||
return;
|
||||
}
|
||||
if(index==1)
|
||||
{
|
||||
player.addFood(1);
|
||||
return;
|
||||
}
|
||||
if(index==4){
|
||||
if(player.removeFood(1)){
|
||||
player.removePrestige(2);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user