Updated: Game.java nextPlayer changed
This commit is contained in:
@@ -5,8 +5,6 @@ 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.Character;
|
||||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.EventCard;
|
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.EventCard;
|
||||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.EventType;
|
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.EventType;
|
||||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Events.ShamanicRitual;
|
|
||||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Events.Sustenance;
|
|
||||||
import it.polimi.ingsw.gc14.Model.GamePackage.Board;
|
import it.polimi.ingsw.gc14.Model.GamePackage.Board;
|
||||||
import it.polimi.ingsw.gc14.Model.GamePackage.CurrentState;
|
import it.polimi.ingsw.gc14.Model.GamePackage.CurrentState;
|
||||||
import it.polimi.ingsw.gc14.Model.Orders.Order2;
|
import it.polimi.ingsw.gc14.Model.Orders.Order2;
|
||||||
@@ -14,7 +12,6 @@ import it.polimi.ingsw.gc14.Model.Orders.Order3;
|
|||||||
import it.polimi.ingsw.gc14.Model.Orders.Order4;
|
import it.polimi.ingsw.gc14.Model.Orders.Order4;
|
||||||
import it.polimi.ingsw.gc14.Model.Orders.Order5;
|
import it.polimi.ingsw.gc14.Model.Orders.Order5;
|
||||||
import it.polimi.ingsw.gc14.Model.GamePackage.GameStages;
|
import it.polimi.ingsw.gc14.Model.GamePackage.GameStages;
|
||||||
import javafx.event.Event;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -25,8 +22,10 @@ public class Game {
|
|||||||
private CurrentState currentState;
|
private CurrentState currentState;
|
||||||
private HashMap<Slot,Player> slotMap;
|
private HashMap<Slot,Player> slotMap;
|
||||||
private int nPlayers;
|
private int nPlayers;
|
||||||
|
private Queue<Player> OptionalCardQueue;
|
||||||
private OrderLogicCard orderLogicCard;
|
private OrderLogicCard orderLogicCard;
|
||||||
private Board board;
|
private Board board;
|
||||||
|
|
||||||
public Game(int nPlayers) {
|
public Game(int nPlayers) {
|
||||||
this.nPlayers = nPlayers;
|
this.nPlayers = nPlayers;
|
||||||
board=new Board(nPlayers);
|
board=new Board(nPlayers);
|
||||||
@@ -37,6 +36,20 @@ public class Game {
|
|||||||
}
|
}
|
||||||
currentState= new CurrentState();
|
currentState= new CurrentState();
|
||||||
playersList = new ArrayList<>();
|
playersList = new ArrayList<>();
|
||||||
|
OptionalCardQueue = new LinkedList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean addPlayer(Player player) {
|
||||||
|
if(currentState.getGameStage()!= GameStages.WAITING)
|
||||||
|
return false;
|
||||||
|
playersList.add(player);
|
||||||
|
|
||||||
|
if(playersList.size()>=nPlayers)
|
||||||
|
{
|
||||||
|
init();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
public void init() {
|
public void init() {
|
||||||
|
|
||||||
@@ -58,13 +71,17 @@ public class Game {
|
|||||||
currentState.GameStageUpdate(GameStages.SLOT_CHOICE);
|
currentState.GameStageUpdate(GameStages.SLOT_CHOICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//region Cotroller Methods
|
||||||
public boolean SlotChoice(Player player, Slot slot) {
|
public boolean SlotChoice(Player player, Slot slot) {
|
||||||
if(currentState.getGameStage()!= GameStages.SLOT_CHOICE)
|
if(currentState.getGameStage()!= GameStages.SLOT_CHOICE)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(player.equals(currentState.getCurrentPlayer()))
|
if(!player.equals(currentState.getCurrentPlayer()))
|
||||||
{
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if(slotMap.get(slot)!=null)
|
if(slotMap.get(slot)!=null)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@@ -74,21 +91,9 @@ public class Game {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
slotMap.put(slot,player);
|
slotMap.put(slot,player);
|
||||||
currentState.PlayerUpdate(orderLogicCard.pull(),null);
|
nextPlayerSetup();
|
||||||
if(currentState.getCurrentPlayer()==null)
|
|
||||||
{
|
|
||||||
currentState.GameStageUpdate(GameStages.RESOLVING_ACTIONS);
|
|
||||||
for(Slot s : board.getSlotList())
|
|
||||||
{
|
|
||||||
if(slotMap.get(s)!=null)
|
|
||||||
{
|
|
||||||
currentState.PlayerUpdate(slotMap.get(s),s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//region Drawing Methods
|
//region Drawing Methods
|
||||||
@@ -201,7 +206,28 @@ public class Game {
|
|||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
|
//region Optional Card Methods
|
||||||
|
public boolean PickOptionalTribeCard(Player player,TribeCard tribeCard) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public boolean PickOptionalBuildingCard(Player player, BuildingCard buildingCard) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public boolean NoOptionalCard(Player player) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
private void nextPlayerSetup() {
|
private void nextPlayerSetup() {
|
||||||
|
if(GameStages.SLOT_CHOICE==currentState.getGameStage()) {
|
||||||
|
currentState.PlayerUpdate(orderLogicCard.pull(), null);
|
||||||
|
if(currentState.getCurrentPlayer()==null)
|
||||||
|
{
|
||||||
|
currentState.GameStageUpdate(GameStages.RESOLVING_ACTIONS);
|
||||||
|
}
|
||||||
|
}
|
||||||
if(GameStages.RESOLVING_ACTIONS==currentState.getGameStage()) {
|
if(GameStages.RESOLVING_ACTIONS==currentState.getGameStage()) {
|
||||||
orderLogicCard.push(currentState.getCurrentPlayer());
|
orderLogicCard.push(currentState.getCurrentPlayer());
|
||||||
slotMap.put(currentState.getSlot(), null);
|
slotMap.put(currentState.getSlot(), null);
|
||||||
@@ -212,15 +238,36 @@ public class Game {
|
|||||||
}
|
}
|
||||||
if(slotMap.values().stream().allMatch(v -> v == null))
|
if(slotMap.values().stream().allMatch(v -> v == null))
|
||||||
{
|
{
|
||||||
currentState.GameStageUpdate(GameStages.BUILDING_EFFECT_12);
|
currentState.GameStageUpdate(GameStages.OPTIONAL_CARD_EFFECT);
|
||||||
BuildingEffect12( playersList.stream().filter(x->x.buildingCards.stream().anyMatch(y->y.getEffectId()==12)).toList());
|
OptionalCardQueue=(playersList.stream().filter(x->x.buildingCards.stream().anyMatch(y->y.getEffectId()==12)).collect(Collectors.toCollection(LinkedList::new)));
|
||||||
//currentState.PlayerUpdate(orderLogicCard.pull(),null);
|
currentState.PlayerUpdate(OptionalCardQueue.remove(), null);
|
||||||
|
if(currentState.getCurrentPlayer()==null)
|
||||||
|
{
|
||||||
|
currentState.GameStageUpdate(GameStages.RESOLVING_EVENT);
|
||||||
|
if(currentState.getRound()<10)
|
||||||
|
{
|
||||||
|
nextRound();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
EventResolution();
|
||||||
|
currentState.GameStageUpdate(GameStages.ENDING);
|
||||||
|
endGame();
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void BuildingEffect12(List<Player> playerList){
|
if(GameStages.OPTIONAL_CARD_EFFECT==currentState.getGameStage()) {
|
||||||
|
currentState.PlayerUpdate(OptionalCardQueue.remove(), null);
|
||||||
|
if(currentState.getCurrentPlayer()==null)
|
||||||
|
{
|
||||||
|
currentState.GameStageUpdate(GameStages.RESOLVING_EVENT);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void EventResolution() {
|
private void EventResolution() {
|
||||||
|
|
||||||
@@ -242,7 +289,6 @@ public class Game {
|
|||||||
e.activateEvent(playersList);
|
e.activateEvent(playersList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
private void nextRound() {
|
private void nextRound() {
|
||||||
|
|
||||||
@@ -265,19 +311,6 @@ public class Game {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public boolean addPlayer(Player player) {
|
|
||||||
if(currentState.getGameStage()!= GameStages.WAITING)
|
|
||||||
return false;
|
|
||||||
playersList.add(player);
|
|
||||||
|
|
||||||
if(playersList.size()>=nPlayers)
|
|
||||||
{
|
|
||||||
init();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
package it.polimi.ingsw.gc14.Model.GamePackage;
|
package it.polimi.ingsw.gc14.Model.GamePackage;
|
||||||
|
|
||||||
public enum GameStages {
|
public enum GameStages {
|
||||||
WAITING,SLOT_CHOICE, RESOLVING_ACTIONS,BUILDING_EFFECT_12, RESOLVING_EVENT,ENDING,ENDED
|
WAITING,SLOT_CHOICE, RESOLVING_ACTIONS, OPTIONAL_CARD_EFFECT, RESOLVING_EVENT,ENDING,ENDED
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user