Merge branch 'main' into Launcher
This commit is contained in:
@@ -169,8 +169,9 @@ public class Game implements Serializable {
|
||||
* @throws IllegalArgumentException if {@code nPlayers < 0} or {@code nPlayers > 5}.
|
||||
*/
|
||||
public Game(int nPlayers) throws IllegalArgumentException{
|
||||
if(nPlayers < 0||nPlayers > 5)
|
||||
if(nPlayers !=0 && (nPlayers < 2 || nPlayers > 5)) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
this.nPlayers = nPlayers;
|
||||
board=new Board(nPlayers);
|
||||
slotMap = new LinkedHashMap<>();
|
||||
@@ -312,10 +313,9 @@ public class Game implements Serializable {
|
||||
tempCard.insert(player);
|
||||
board.removeUpperTribeCard(tempCard);
|
||||
currentState.UpperDrawn();
|
||||
if(currentState.getNUpper() ==0 && currentState.getNLower() ==0)
|
||||
if((currentState.getNLower() ==0 ||( getLowerListTribeCards().size()==0 && getLowerListBuilding().size()==0)) && ((currentState.getNUpper() ==0)||( getUpperListTribeCards().size()==0 && getUpperListBuilding().size()==0)))
|
||||
nextPlayerSetup();
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -354,7 +354,7 @@ public class Game implements Serializable {
|
||||
tempCard.insert(player);
|
||||
board.removeLowerTribeCard(tempCard);
|
||||
currentState.LowerDrawn();
|
||||
if(currentState.getNLower() ==0 && currentState.getNUpper() ==0)
|
||||
if((currentState.getNLower() ==0 ||( getLowerListTribeCards().size()==0 && getLowerListBuilding().size()==0)) && ((currentState.getNUpper() ==0)||( getUpperListTribeCards().size()==0 && getUpperListBuilding().size()==0)))
|
||||
nextPlayerSetup();
|
||||
return true;
|
||||
|
||||
@@ -393,7 +393,7 @@ public class Game implements Serializable {
|
||||
}
|
||||
else
|
||||
return false;
|
||||
if(currentState.getNLower() ==0 && currentState.getNUpper() ==0)
|
||||
if((currentState.getNLower() ==0 ||( getLowerListTribeCards().size()==0 && getLowerListBuilding().size()==0)) && ((currentState.getNUpper() ==0)||( getUpperListTribeCards().size()==0 && getUpperListBuilding().size()==0)))
|
||||
nextPlayerSetup();
|
||||
|
||||
return true;
|
||||
@@ -418,7 +418,7 @@ public class Game implements Serializable {
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if(!player.equals(currentState.getCurrentPlayer()))
|
||||
{
|
||||
return false;
|
||||
@@ -433,7 +433,7 @@ public class Game implements Serializable {
|
||||
}
|
||||
else
|
||||
return false;
|
||||
if(currentState.getNLower() ==0 && currentState.getNUpper() ==0)
|
||||
if((currentState.getNLower() ==0 ||( getLowerListTribeCards().size()==0 && getLowerListBuilding().size()==0)) && ((currentState.getNUpper() ==0)||( getUpperListTribeCards().size()==0 && getUpperListBuilding().size()==0)))
|
||||
nextPlayerSetup();
|
||||
|
||||
return true;
|
||||
@@ -509,8 +509,8 @@ public class Game implements Serializable {
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
nextPlayerSetup();
|
||||
OptionalCardQueue.removeIf(x->x.equals(player));
|
||||
nextPlayerSetup();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -566,10 +566,16 @@ public class Game implements Serializable {
|
||||
return;
|
||||
}
|
||||
currentState.GameStageUpdate(GameStages.RESOLVING_ACTIONS);
|
||||
for (Map.Entry<Slot,Player> s : slotMap.entrySet()) {
|
||||
if (s.getValue()!=null) {
|
||||
currentState.PlayerUpdate(s.getValue(), s.getKey());
|
||||
return;
|
||||
for (Slot s : slotMap.keySet()) {
|
||||
if (slotMap.get(s) != null) {
|
||||
currentState.PlayerUpdate(slotMap.get(s), s);
|
||||
if(!((currentState.getNLower() ==0 ||( getLowerListTribeCards().size()==0 && getLowerListBuilding().size()==0)) && ((currentState.getNUpper() ==0)||( getUpperListTribeCards().size()==0 && getUpperListBuilding().size()==0))))
|
||||
break;
|
||||
else
|
||||
{
|
||||
orderLogicCard.push(currentState.getCurrentPlayer());
|
||||
slotMap.put(currentState.getSlot(), null);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
@@ -581,7 +587,15 @@ public class Game implements Serializable {
|
||||
for (Slot s : slotMap.keySet()) {
|
||||
if (slotMap.get(s) != null) {
|
||||
currentState.PlayerUpdate(slotMap.get(s), s);
|
||||
break;
|
||||
if((currentState.getNLower() ==0 ||( getLowerListTribeCards().size()==0 && getLowerListBuilding().size()==0)) && ((currentState.getNUpper() ==0)||( getUpperListTribeCards().size()==0 && getUpperListBuilding().size()==0))) {
|
||||
orderLogicCard.push(currentState.getCurrentPlayer());
|
||||
|
||||
slotMap.put(currentState.getSlot(), null);
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(slotMap.values().stream().allMatch(v -> v == null))
|
||||
@@ -600,31 +614,51 @@ public class Game implements Serializable {
|
||||
{
|
||||
OptionalCardQueue.add(e.getKey());
|
||||
}
|
||||
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();
|
||||
}
|
||||
Player optionalPlayer = OptionalCardQueue.poll();
|
||||
|
||||
if (optionalPlayer != null) {
|
||||
currentState.PlayerUpdate(optionalPlayer, null);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(GameStages.OPTIONAL_CARD_EFFECT==currentState.getGameStage()) {
|
||||
currentState.PlayerUpdate(OptionalCardQueue.remove(), null);
|
||||
if(currentState.getCurrentPlayer()==null)
|
||||
{
|
||||
|
||||
currentState.GameStageUpdate(GameStages.RESOLVING_EVENT);
|
||||
|
||||
if (currentState.getRound() < 10) {
|
||||
nextRound();
|
||||
currentState.PlayerUpdate(orderLogicCard.pull(), null);
|
||||
currentState.GameStageUpdate(GameStages.SLOT_CHOICE);
|
||||
} else {
|
||||
EventResolution();
|
||||
currentState.GameStageUpdate(GameStages.ENDING);
|
||||
endGame();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (GameStages.OPTIONAL_CARD_EFFECT == currentState.getGameStage()) {
|
||||
Player optionalPlayer = OptionalCardQueue.poll();
|
||||
|
||||
if (optionalPlayer != null) {
|
||||
currentState.PlayerUpdate(optionalPlayer, null);
|
||||
return;
|
||||
}
|
||||
|
||||
currentState.GameStageUpdate(GameStages.RESOLVING_EVENT);
|
||||
|
||||
if (currentState.getRound() < 10) {
|
||||
nextRound();
|
||||
currentState.PlayerUpdate(orderLogicCard.pull(), null);
|
||||
currentState.GameStageUpdate(GameStages.SLOT_CHOICE);
|
||||
} else {
|
||||
EventResolution();
|
||||
currentState.GameStageUpdate(GameStages.ENDING);
|
||||
endGame();
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -669,9 +703,13 @@ public class Game implements Serializable {
|
||||
{
|
||||
currentState.GameStageUpdate(GameStages.ENDING);
|
||||
endGame();
|
||||
return;
|
||||
}
|
||||
if(currentState.getEra()!= board.nextRound())
|
||||
|
||||
if(currentState.getEra()!= board.nextRound()) {
|
||||
currentState.EraUpdate();
|
||||
}
|
||||
|
||||
currentState.RoundUpdate();
|
||||
|
||||
}
|
||||
@@ -695,11 +733,28 @@ public class Game implements Serializable {
|
||||
* @param nPlayers the new configured number of players.
|
||||
* @return {@code true} if the number of players is updated, {@code false} otherwise.
|
||||
*/
|
||||
public boolean setNPlayer(int nPlayers)
|
||||
{
|
||||
if(this.nPlayers!=0)
|
||||
public boolean setNPlayer(int nPlayers) {
|
||||
if (this.nPlayers != 0) {
|
||||
return false;
|
||||
this.nPlayers=nPlayers;
|
||||
}
|
||||
|
||||
if (nPlayers < 2 || nPlayers > 5) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.nPlayers = nPlayers;
|
||||
|
||||
board = new Board(nPlayers);
|
||||
|
||||
slotMap = new LinkedHashMap<>();
|
||||
for (Slot s : board.getSlotList()) {
|
||||
slotMap.put(s, null);
|
||||
}
|
||||
|
||||
currentState = new CurrentState();
|
||||
playersList = new ArrayList<>();
|
||||
OptionalCardQueue = new LinkedList<>();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -771,19 +826,10 @@ public class Game implements Serializable {
|
||||
BuildTableLower.addRow(getLowerListBuilding().get(i).toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//offerTrack.addRow(stringUpperListTribe);
|
||||
stringUpperListTribe.forEach(x->TribeTableUpper.addRow(x));
|
||||
stringLowerListTribe.forEach(x->TribeTableLower.addRow(x));
|
||||
|
||||
offerTrack.addRow(stringUpOffer);
|
||||
offerTrack.addRow(stringDownOffer);
|
||||
//offerTrack.addRow(stringLowerListTribe);
|
||||
|
||||
|
||||
|
||||
return orderLogicCard.toString()+"\n"+ AsciiTable.sideBySide(Arrays.stream((TribeTableUpper.build().split("\n"))).toList(), Arrays.stream(BuildTableUpper.build().split("\n")).toList(),2)+"\n"+offerTrack.build()+"\n"+AsciiTable.sideBySide(List.of(TribeTableLower.build().split("\n")), Arrays.stream(BuildTableLower.build().split("\n")).toList(),2);
|
||||
//return s.toString()+"\n"++"\nOFFER TRACK\n"+ table.build()+"\n" ;
|
||||
return "CURRENT STATE\n"+getCurrentState()+"\n"+orderLogicCard.toString()+"\n"+ AsciiTable.sideBySide(Arrays.stream((TribeTableUpper.build().split("\n"))).toList(), Arrays.stream(BuildTableUpper.build().split("\n")).toList(),2)+"\n"+offerTrack.build()+"\n"+AsciiTable.sideBySide(List.of(TribeTableLower.build().split("\n")), Arrays.stream(BuildTableLower.build().split("\n")).toList(),2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,12 @@ package it.polimi.ingsw.gc14.Model.GamePackage;
|
||||
import it.polimi.ingsw.gc14.Model.Player;
|
||||
import it.polimi.ingsw.gc14.Model.Slot;
|
||||
import it.polimi.ingsw.gc14.Model.GamePackage.GameStages;
|
||||
import it.polimi.ingsw.gc14.View.TUI.AsciiTable;
|
||||
import it.polimi.ingsw.gc14.View.TUI.BorderStyle;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents the current state of the game.
|
||||
@@ -194,5 +199,27 @@ public class CurrentState implements Serializable {
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public String toString(){
|
||||
var table= new AsciiTable(BorderStyle.UNICODE,6);
|
||||
List<String>header= new ArrayList<>();
|
||||
header.add("Player");
|
||||
header.add("NUpper");
|
||||
header.add("NLower");
|
||||
header.add("Round");
|
||||
header.add("Era");
|
||||
header.add("GameStage");
|
||||
table.addRow(header);
|
||||
table.addSeparator();
|
||||
List<String>values= new ArrayList<>();
|
||||
values.add(player.getUserName());
|
||||
values.add(Integer.toString(NUpper));
|
||||
values.add(Integer.toString(NLower));
|
||||
values.add(Integer.toString(round));
|
||||
values.add(Integer.toString(Era));
|
||||
values.add(GameStage.toString());
|
||||
table.addRow(values);
|
||||
return table.build();
|
||||
}
|
||||
// endregion functions
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class Order3 extends OrderLogicCard {
|
||||
return;
|
||||
}
|
||||
if(index==2){
|
||||
if(player.removeFood(1)){
|
||||
if(!player.removeFood(1)){
|
||||
player.removePrestige(2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ public class Order4 extends OrderLogicCard {
|
||||
return;
|
||||
}
|
||||
if(index==3){
|
||||
if(player.removeFood(1)){
|
||||
if(!player.removeFood(1)){
|
||||
player.removePrestige(2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ public class Order5 extends OrderLogicCard {
|
||||
return;
|
||||
}
|
||||
if(index==4){
|
||||
if(player.removeFood(1)){
|
||||
if(!player.removeFood(1)){
|
||||
player.removePrestige(2);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user