package it.polimi.ingsw.gc14.Controller; import it.polimi.ingsw.gc14.Model.Game; import it.polimi.ingsw.gc14.Model.Player; import it.polimi.ingsw.gc14.Network.IClient; import it.polimi.ingsw.gc14.Network.NetworkEvents.*; import it.polimi.ingsw.gc14.Network.Observer; import it.polimi.ingsw.gc14.View.IView; /** * Controller class that holds all the components of the client, such as view, network client and Game Controller. * It provides methods to set the client components and to execute requested actions. */ public class ClientController { /** Game Controller of the client */ public GameController localController; /** View of the client */ public IView view; /** Network client (either TCP or RMI) */ private IClient client; /** * Constructor of the class. Initializes all attributes. * @param view The client view to set (either TUI or GUI). */ public ClientController(IView view) { this.view = view; this.localController = new GameController(); this.client = null; } /** * Method to set the network client. * @param client The client to sei (either TCP or RMI) */ public void setClient(IClient client) { this.client = client; } /** * Method to set the model in the Game Controller and in the view. * @param model The model to set */ public void setModel(Game model) { localController.setModel(model); view.update(localController.getModel()); } /** * Method to show an error in the view. * @param message The error message to show in the view */ public void onError(String message) { view.showError(message); } /** * Used to draw a tribe card from the upper list. * Create a NetworkEvent and then sends it through the network client. * @param playerUsername The name of the player who requested to perform the action * @param pos Index of the card to draw */ public void drawUpperTribeCard(String playerUsername, int pos) { client.doEvent(new DrawUpperTribeCard(playerUsername,pos)); } /** * Used to draw a tribe card from the lower list. * Create a NetworkEvent and then sends it through the network client. * @param playerUsername The name of the player who requested to perform the action * @param pos Index of the card to draw */ public void drawLowerTribeCard(String playerUsername,int pos) { client.doEvent(new DrawLowerTribeCard(playerUsername,pos)); } /** * Used to draw a building card from the upper list. * Create a NetworkEvent and then sends it through the network client. * @param playerUsername The name of the player who requested to perform the action * @param pos Index of the card to draw */ public void drawUpperBuildingCard(String playerUsername,int pos) { client.doEvent(new DrawUpperBuildingCard(playerUsername,pos)); } /** * Used to draw a building card from the lower list. * Create a NetworkEvent and then sends it through the network client. * @param playerUsername The name of the player who requested to perform the action * @param pos Index of the card to draw */ public void drawLowerBuildingCard(String playerUsername,int pos) { client.doEvent(new DrawLowerBuildingCard(playerUsername,pos)); } /** * Used to skip the drawing action from the upper list. * Available only when the upper list is empty (or the player can't draw any card). * @param playerUsername The name of the player who requested to perform the action */ public void skipUpper(String playerUsername) { client.doEvent(new SkipUpper(playerUsername)); } /** * Used to skip the drawing action from the lower list. * Available only when the lower list is empty (or the player can't draw any card). * @param playerUsername The name of the player who requested to perform the action */ public void skipLower(String playerUsername) { client.doEvent(new SkipLower(playerUsername));} /** * Used to draw a tribe card from the upper list. * Available only if the player owns the building 12. * @param playerUsername The name of the player who requested to perform the action * @param pos Index of the card to draw */ public void pickOptionalTribeCard(String playerUsername,int pos) { client.doEvent(new PickOptionalTribeCard(playerUsername,pos)); } /** * Used to draw a building card from the upper list. * Available only if the player owns the building 12. * @param playerUsername The name of the player who requested to perform the action * @param pos Index of the card to draw */ public void pickOptionalBuildingCard(String playerUsername,int pos) { client.doEvent(new PickOptionalBuildingCard(playerUsername,pos)); } /** * Used to skip the action of drawing a card from the upper list. * Available only if the player owns the building 12. * @param playerUsername The name of the player who requested to perform the action */ public void noOptionalCard(String playerUsername) { client.doEvent(new NoOptionalCard(playerUsername)); } /** * Used to sperform the slot choiche action for the specified player at the specified position. * @param playerUsername The name of the player who requested to perform the action * @param pos Index of the selected slot */ public void slotChoice(String playerUsername,int pos) { client.doEvent(new SlotChoice(playerUsername,pos)); } }