@@ -72,7 +72,7 @@ public class ClientLauncherTUI {
|
|||||||
private void getInput(Scanner scanner, ClientController controller, String username) {
|
private void getInput(Scanner scanner, ClientController controller, String username) {
|
||||||
String action = scanner.next();
|
String action = scanner.next();
|
||||||
int pos=-1;
|
int pos=-1;
|
||||||
if(!action.equals("8")&&!action.equals("A")&&!action.equals("B")&&!action.equals("C")&&!action.equals("D")) {
|
if(!action.equals("7")&&!action.equals("8")&&!action.equals("9")&&!action.equals("A")&&!action.equals("B")&&!action.equals("C")) {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
System.out.println("Insert the required position:");
|
System.out.println("Insert the required position:");
|
||||||
@@ -84,14 +84,16 @@ public class ClientLauncherTUI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
switch(action) {
|
switch(action) {
|
||||||
case "1" -> controller.slotChoice(username, pos);
|
case "0" -> controller.slotChoice(username, pos);
|
||||||
case "2" -> controller.drawUpperBuildingCard(username, pos);
|
case "1" -> controller.drawUpperBuildingCard(username, pos);
|
||||||
case "3" -> controller.drawUpperTribeCard(username, pos);
|
case "2" -> controller.drawUpperTribeCard(username, pos);
|
||||||
case "4" -> controller.drawLowerBuildingCard(username, pos);
|
case "3" -> controller.drawLowerBuildingCard(username, pos);
|
||||||
case "5" -> controller.drawLowerTribeCard(username, pos);
|
case "4" -> controller.drawLowerTribeCard(username, pos);
|
||||||
case "6" -> controller.pickOptionalTribeCard(username, pos);
|
case "5" -> controller.pickOptionalTribeCard(username, pos);
|
||||||
case "7" -> controller.pickOptionalBuildingCard(username, pos);
|
case "6" -> controller.pickOptionalBuildingCard(username, pos);
|
||||||
case "8" -> controller.noOptionalCard(username);
|
case "7" -> controller.noOptionalCard(username);
|
||||||
|
case "8" -> controller.skipUpper(username);
|
||||||
|
case "9" -> controller.skipLower(username);
|
||||||
case "A" -> view.fullRender();
|
case "A" -> view.fullRender();
|
||||||
case "B" -> view.renderBoard();
|
case "B" -> view.renderBoard();
|
||||||
case "C" -> view.renderPlayer();
|
case "C" -> view.renderPlayer();
|
||||||
|
|||||||
@@ -80,6 +80,13 @@ public class ClientController {
|
|||||||
client.doEvent(new DrawLowerBuildingCard(playerUsername,pos));
|
client.doEvent(new DrawLowerBuildingCard(playerUsername,pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void skipUpper(String playerUsername) {
|
||||||
|
client.doEvent(new SkipUpper(playerUsername));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void skipLower(String playerUsername) { client.doEvent(new SkipLower(playerUsername));}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempts to pick an optional tribe card for the specified player from the specified position.
|
* Attempts to pick an optional tribe card for the specified player from the specified position.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package it.polimi.ingsw.gc14.Controller;
|
package it.polimi.ingsw.gc14.Controller;
|
||||||
|
|
||||||
import it.polimi.ingsw.gc14.Model.Game;
|
import it.polimi.ingsw.gc14.Model.Game;
|
||||||
|
import it.polimi.ingsw.gc14.Model.GamePackage.GameStages;
|
||||||
import it.polimi.ingsw.gc14.Model.Player;
|
import it.polimi.ingsw.gc14.Model.Player;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -118,6 +119,20 @@ public class GameController {
|
|||||||
return model.DrawLowerBuildingCardByIndex(model.getPlayerByUsername(playerUsername), pos);
|
return model.DrawLowerBuildingCardByIndex(model.getPlayerByUsername(playerUsername), pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean SkipUpperDrawing(String playerUsername) {
|
||||||
|
Player player= model.getPlayerByUsername(playerUsername);
|
||||||
|
if(player==null)
|
||||||
|
return false;
|
||||||
|
return model.SkipUpperDrawing(model.getPlayerByUsername(playerUsername));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean SkipLowerDrawing(String playerUsername) {
|
||||||
|
Player player= model.getPlayerByUsername(playerUsername);
|
||||||
|
if(player==null)
|
||||||
|
return false;
|
||||||
|
return model.SkipLowerDrawing(model.getPlayerByUsername(playerUsername));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempts to pick an optional tribe card for the specified player from the specified position.
|
* Attempts to pick an optional tribe card for the specified player from the specified position.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -318,6 +318,44 @@ public class Game implements Serializable {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean SkipUpperDrawing(Player player) {
|
||||||
|
if(currentState.getGameStage()!= GameStages.RESOLVING_ACTIONS)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(!player.equals(currentState.getCurrentPlayer()))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(currentState.getNUpper() <1)
|
||||||
|
return false;
|
||||||
|
if(hasDrawableUp())
|
||||||
|
return false;
|
||||||
|
currentState.UpperDrawn();
|
||||||
|
if((currentState.getNLower() ==0 ||( !hasDrawableDown() && getLowerListBuilding().isEmpty())) && ((currentState.getNUpper() ==0)||(getUpperListBuilding().isEmpty())))
|
||||||
|
nextPlayerSetup();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean SkipLowerDrawing(Player player) {
|
||||||
|
if(currentState.getGameStage()!= GameStages.RESOLVING_ACTIONS)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(!player.equals(currentState.getCurrentPlayer()))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(currentState.getNUpper() <1)
|
||||||
|
return false;
|
||||||
|
if(hasDrawableDown())
|
||||||
|
return false;
|
||||||
|
currentState.LowerDrawn();
|
||||||
|
if((currentState.getNLower() ==0 ||( getLowerListBuilding().isEmpty())) && ((currentState.getNUpper() ==0)||(!hasDrawableUp()&&getUpperListBuilding().isEmpty())))
|
||||||
|
nextPlayerSetup();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempts to draw the lower tribe card at the specified index for the specified player.
|
* Attempts to draw the lower tribe card at the specified index for the specified player.
|
||||||
* The operation succeeds only if the index is valid, the game stage is {@code RESOLVING_ACTIONS},
|
* The operation succeeds only if the index is valid, the game stage is {@code RESOLVING_ACTIONS},
|
||||||
@@ -569,7 +607,7 @@ public class Game implements Serializable {
|
|||||||
for (Slot s : slotMap.keySet()) {
|
for (Slot s : slotMap.keySet()) {
|
||||||
if (slotMap.get(s) != null) {
|
if (slotMap.get(s) != null) {
|
||||||
currentState.PlayerUpdate(slotMap.get(s), s);
|
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))))
|
if(!((currentState.getNLower() ==0 ||(!hasDrawableDown() && getLowerListBuilding().size()==0)) && ((currentState.getNUpper() ==0)||(!hasDrawableUp() && getUpperListBuilding().size()==0))))
|
||||||
break;
|
break;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -587,7 +625,7 @@ public class Game implements Serializable {
|
|||||||
for (Slot s : slotMap.keySet()) {
|
for (Slot s : slotMap.keySet()) {
|
||||||
if (slotMap.get(s) != null) {
|
if (slotMap.get(s) != null) {
|
||||||
currentState.PlayerUpdate(slotMap.get(s), s);
|
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))) {
|
if((currentState.getNLower() ==0 ||(!hasDrawableDown() && getLowerListBuilding().size()==0)) && ((currentState.getNUpper() ==0)||( !hasDrawableUp() && getUpperListBuilding().size()==0))) {
|
||||||
orderLogicCard.push(currentState.getCurrentPlayer());
|
orderLogicCard.push(currentState.getCurrentPlayer());
|
||||||
|
|
||||||
slotMap.put(currentState.getSlot(), null);
|
slotMap.put(currentState.getSlot(), null);
|
||||||
@@ -661,7 +699,14 @@ public class Game implements Serializable {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private boolean hasDrawableUp()
|
||||||
|
{
|
||||||
|
return getUpperListTribeCards().stream().filter(x-> !x.IsEventCard()).count()==0;
|
||||||
|
}
|
||||||
|
private boolean hasDrawableDown()
|
||||||
|
{
|
||||||
|
return getLowerListTribeCards().stream().filter(x-> !x.IsEventCard()).count()==0;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Resolves all pending event cards if the current game stage is {@code RESOLVING_EVENT}.
|
* Resolves all pending event cards if the current game stage is {@code RESOLVING_EVENT}.
|
||||||
* All pending events are activated on the player list.
|
* All pending events are activated on the player list.
|
||||||
|
|||||||
@@ -9,5 +9,7 @@ public enum EventType {
|
|||||||
DRAW_LOWER_BUILD,
|
DRAW_LOWER_BUILD,
|
||||||
PICK_OPTIONAL_TRIBE,
|
PICK_OPTIONAL_TRIBE,
|
||||||
PICK_OPTIONAL_BUILD,
|
PICK_OPTIONAL_BUILD,
|
||||||
|
SKIP_UPPER,
|
||||||
|
SKIP_LOWER,
|
||||||
NO_OPTIONAL_CARD
|
NO_OPTIONAL_CARD
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package it.polimi.ingsw.gc14.Network.NetworkEvents;
|
||||||
|
|
||||||
|
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||||
|
import it.polimi.ingsw.gc14.Network.EventType;
|
||||||
|
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||||
|
import it.polimi.ingsw.gc14.View.IView;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
//TODO javadoc
|
||||||
|
public class SkipLower extends NetworkEvent implements Serializable{
|
||||||
|
//TODO javadoc
|
||||||
|
public SkipLower(String username){
|
||||||
|
super(username, EventType.SKIP_LOWER, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO javadoc
|
||||||
|
@Override
|
||||||
|
public boolean apply(GameController gameController){
|
||||||
|
return gameController.SkipLowerDrawing(username);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package it.polimi.ingsw.gc14.Network.NetworkEvents;
|
||||||
|
|
||||||
|
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||||
|
import it.polimi.ingsw.gc14.Network.EventType;
|
||||||
|
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||||
|
import it.polimi.ingsw.gc14.View.IView;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
//TODO javadoc
|
||||||
|
public class SkipUpper extends NetworkEvent implements Serializable{
|
||||||
|
|
||||||
|
//TODO javadoc
|
||||||
|
public SkipUpper(String username){
|
||||||
|
super(username, EventType.SKIP_UPPER, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO javadoc
|
||||||
|
@Override
|
||||||
|
public boolean apply(GameController gameController){
|
||||||
|
return gameController.SkipUpperDrawing(username);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -100,14 +100,16 @@ public class TUI implements IView {
|
|||||||
{
|
{
|
||||||
var table=new AsciiTable(BorderStyle.ROUNDED,2);
|
var table=new AsciiTable(BorderStyle.ROUNDED,2);
|
||||||
table.addHeader( "Menu Options","Render Options");
|
table.addHeader( "Menu Options","Render Options");
|
||||||
table.addRow( List.of("1-SlotChoice(pos)","A-Full Render"));
|
table.addRow( List.of("0-SlotChoice(pos)","A-Full Render"));
|
||||||
table.addRow(List.of("2-DrawUpperTribe(pos)","B-Board Render"));
|
table.addRow(List.of("1-DrawUpperTribe(pos)","B-Board Render"));
|
||||||
table.addRow(List.of("3-DrawUpperBuilding(pos)","C-Players Render"));
|
table.addRow(List.of("2-DrawUpperBuilding(pos)","C-Players Render"));
|
||||||
table.addRow(List.of("4-DrawLowerTribe(pos)",""));
|
table.addRow(List.of("3-DrawLowerTribe(pos)",""));
|
||||||
table.addRow(List.of("5-DrawLowerBuilding(pos)",""));
|
table.addRow(List.of("4-DrawLowerBuilding(pos)",""));
|
||||||
table.addRow(List.of("6-PickOptionalTribe(pos)",""));
|
table.addRow(List.of("5-PickOptionalTribe(pos)",""));
|
||||||
table.addRow(List.of("7-PickOptionalBuilding(pos)",""));
|
table.addRow(List.of("6-PickOptionalBuilding(pos)",""));
|
||||||
table.addRow(List.of("8-NoOptional",""));
|
table.addRow(List.of("7-NoOptional",""));
|
||||||
|
table.addRow(List.of("8-NoUpperCard",""));
|
||||||
|
table.addRow(List.of("9-NoLowerCard",""));
|
||||||
return table.build();
|
return table.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user