Merge branch 'main' into javadoc-fixes
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;
|
||||
}
|
||||
|
||||
@@ -715,88 +770,76 @@ public class Game implements Serializable {
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
var table = new AsciiTable(BorderStyle.UNICODE, slotMap.size());
|
||||
List<String> stringUp=new ArrayList<>();
|
||||
List<String> stringEmpty=new ArrayList<>();
|
||||
List<String> stringDown=new ArrayList<>();
|
||||
return PlayersStamp()+"\n"+BoardStamp()+"\n";
|
||||
}
|
||||
public String PlayersStamp()
|
||||
{
|
||||
StringBuilder stringBuilder=new StringBuilder();
|
||||
for(int i=0;i<playersList.size()/2;i++)
|
||||
{
|
||||
stringBuilder.append(AsciiTable.sideBySide(List.of(playersList.get((i*2)).toString().split("\n")),List.of(playersList.get((i*2+1)).toString().split("\n")),2));
|
||||
}
|
||||
stringBuilder.append("\n");
|
||||
if(playersList.size()%2!=0)
|
||||
{
|
||||
stringBuilder.append(playersList.get(playersList.size()-1).toString());
|
||||
stringBuilder.append("\n");
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
public String BoardStamp()
|
||||
{
|
||||
var offerTrack = new AsciiTable(BorderStyle.UNICODE, slotMap.size());
|
||||
List<String> stringUpOffer=new ArrayList<>();
|
||||
List<String> stringDownOffer=new ArrayList<>();
|
||||
|
||||
for(Map.Entry<Slot,Player> entry:slotMap.entrySet())
|
||||
{
|
||||
stringEmpty.add(" ");
|
||||
stringDown.add(entry.getKey().toStringTUI());
|
||||
stringDownOffer.add(entry.getKey().toStringTUI());
|
||||
if(entry.getValue()!=null)
|
||||
stringUp.add(entry.getValue().getUserName());
|
||||
stringUpOffer.add(entry.getValue().getUserName());
|
||||
else
|
||||
stringUp.add(" ");
|
||||
stringUpOffer.add(" ");
|
||||
}
|
||||
table.addRow(stringUp);
|
||||
table.addRow(stringEmpty);
|
||||
table.addRow(stringDown);
|
||||
|
||||
List<String>lines=List.of(orderLogicCard.toString().split("\n"));
|
||||
List<String> lines2=new ArrayList<>();
|
||||
lines2.add("OFFER TRACK");
|
||||
lines2.addAll(List.of(table.build().split("\n")));
|
||||
var TribeTableUpper = new AsciiTable(BorderStyle.UNICODE,1);
|
||||
var TribeTableLower = new AsciiTable(BorderStyle.UNICODE,1);
|
||||
|
||||
String boardToString=AsciiTable.sideBySide(lines,lines2,1);
|
||||
|
||||
|
||||
|
||||
var table2 = new AsciiTable(BorderStyle.UNICODE, Math.max(getUpperListTribeCards().size(),getLowerListTribeCards().size()));
|
||||
List<String> stringUp2=new ArrayList<>();
|
||||
List<String> stringDown2=new ArrayList<>();
|
||||
List<String> stringUpperListTribe=new ArrayList<>();
|
||||
List<String> stringLowerListTribe=new ArrayList<>();
|
||||
stringUpperListTribe.add("Char/Events");
|
||||
stringLowerListTribe.add("Char/Events");
|
||||
for(int i=0;i<Math.max(getUpperListTribeCards().size(),getLowerListTribeCards().size());i++)
|
||||
{
|
||||
if(i<getUpperListTribeCards().size())
|
||||
{
|
||||
stringUp2.add(getUpperListTribeCards().get(i).toStringBoard());
|
||||
}
|
||||
else
|
||||
{
|
||||
stringUp2.add("");
|
||||
stringUpperListTribe.add(getUpperListTribeCards().get(i).toStringBoard());
|
||||
}
|
||||
if(i<getLowerListTribeCards().size())
|
||||
{
|
||||
stringDown2.add(getLowerListTribeCards().get(i).toStringBoard());
|
||||
}
|
||||
else
|
||||
{
|
||||
stringDown2.add("");
|
||||
stringLowerListTribe.add(getLowerListTribeCards().get(i).toStringBoard());
|
||||
}
|
||||
}
|
||||
table2.addRow(stringUp2);
|
||||
table2.addRow(stringDown2);
|
||||
var BuildTableUpper = new AsciiTable(BorderStyle.UNICODE,1);
|
||||
BuildTableUpper.addHeader("Building ");
|
||||
var BuildTableLower = new AsciiTable(BorderStyle.UNICODE,1);
|
||||
BuildTableLower.addHeader("Building ");
|
||||
|
||||
var table3 = new AsciiTable(BorderStyle.UNICODE, Math.max(getUpperListBuilding().size(),getLowerListBuilding().size()));
|
||||
List<String> stringUp3=new ArrayList<>();
|
||||
List<String> stringDown3=new ArrayList<>();
|
||||
for(int i=0;i<Math.max(getUpperListBuilding().size(),getLowerListBuilding().size());i++)
|
||||
{
|
||||
if(i<getUpperListBuilding().size())
|
||||
{
|
||||
stringUp3.add(getUpperListBuilding().get(i).toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
stringUp3.add("-");
|
||||
BuildTableUpper.addRow(getUpperListBuilding().get(i).toString());
|
||||
}
|
||||
if(i<getLowerListBuilding().size())
|
||||
{
|
||||
stringDown3.add(getLowerListBuilding().get(i).toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
stringDown3.add("-");
|
||||
BuildTableLower.addRow(getLowerListBuilding().get(i).toString());
|
||||
}
|
||||
}
|
||||
table3.addRow(stringUp3);
|
||||
table3.addRow(stringDown3);
|
||||
|
||||
String PlayerToString ="";
|
||||
for(Player p:playersList)
|
||||
{
|
||||
PlayerToString+=p.toString()+"\n";
|
||||
}
|
||||
return PlayerToString+"\n"+ boardToString +"UPPERList\\LOWERList\n"+table2.build() + "\nBUILDING\n"+table3.build() + "\n";
|
||||
//return s.toString()+"\n"++"\nOFFER TRACK\n"+ table.build()+"\n" ;
|
||||
stringUpperListTribe.forEach(x->TribeTableUpper.addRow(x));
|
||||
stringLowerListTribe.forEach(x->TribeTableLower.addRow(x));
|
||||
offerTrack.addRow(stringUpOffer);
|
||||
offerTrack.addRow(stringDownOffer);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user