Fix: MVC (Client) Add:IClient

This commit is contained in:
rubenpirreram
2026-04-30 18:34:40 +02:00
parent d66af3a112
commit 5246818fca
6 changed files with 127 additions and 15 deletions
@@ -1,6 +1,9 @@
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;
@@ -8,12 +11,15 @@ public class ClientController {
public GameController localController;
public IView view=null;
private IClient client;
public ClientController(IView view) {
this.view = view;
this.localController = new GameController();
}
public void setClient(IClient client) {
this.client = client;
}
public void setModel(Game model) {
localController.setModel(model);
view.update(localController.getModel());
@@ -23,4 +29,88 @@ public class ClientController {
view.showError(message);
}
/**
* Attempts to draw an upper tribe card for the specified player from the specified position.
*
* @param playerUsername the username of the player performing the action.
* @param pos the position of the upper tribe card to draw.
* @return {@code true} if the action succeeds, {@code false} if the player does not exist
* or if the draw operation fails.
*/
public void drawUpperTribeCard(String playerUsername,int pos) {
client.doEvent(new DrawUpperTribeCard(playerUsername,pos));
}
/**
* Attempts to draw a lower tribe card for the specified player from the specified position.
*
* @param playerUsername the username of the player performing the action.
* @param pos the position of the lower tribe card to draw.
* @return {@code true} if the action succeeds, {@code false} if the player does not exist
* or if the draw operation fails.
*/
public void drawLowerTribeCard(String playerUsername,int pos) {
client.doEvent(new DrawLowerTribeCard(playerUsername,pos));
}
/**
* Attempts to draw an upper building card for the specified player from the specified position.
*
* @param playerUsername the username of the player performing the action.
* @param pos the position of the upper building card to draw.
* @return {@code true} if the action succeeds, {@code false} if the player does not exist
* or if the draw operation fails.
*/
public void drawUpperBuildingCard(String playerUsername,int pos) {
client.doEvent(new DrawUpperBuildingCard(playerUsername,pos));
}
/**
* Attempts to draw a lower building card for the specified player from the specified position.
*
* @param playerUsername the username of the player performing the action.
* @param pos the position of the lower building card to draw.
* @return {@code true} if the action succeeds, {@code false} if the player does not exist
* or if the draw operation fails.
*/
public void drawLowerBuildingCard(String playerUsername,int pos) {
client.doEvent(new DrawLowerBuildingCard(playerUsername,pos));
}
/**
* Attempts to pick an optional tribe card for the specified player from the specified position.
*
* @param playerUsername the username of the player performing the action.
* @param pos the position of the optional tribe card to pick.
* @return {@code true} if the action succeeds, {@code false} if the player does not exist
* or if the pick operation fails.
*/
public void pickOptionalTribeCard(String playerUsername,int pos) {
client.doEvent(new PickOptionalTribeCard(playerUsername,pos));
}
/**
* Attempts to pick an optional building card for the specified player from the specified position.
*
* @param playerUsername the username of the player performing the action.
* @param pos the position of the optional building card to pick.
* @return {@code true} if the action succeeds, {@code false} if the player does not exist
* or if the pick operation fails.
*/
public void pickOptionalBuildingCard(String playerUsername,int pos) {
client.doEvent(new PickOptionalBuildingCard(playerUsername,pos));
}
/**
* Attempts to perform the slot choice action for the specified player at the specified position.
*
* @param playerUsername the username of the player performing the action.
* @param pos the position of the chosen slot.
* @return {@code true} if the action succeeds, {@code false} if the player does not exist
* or if the slot choice operation fails.
*/
public void slotChoice(String playerUsername,int pos) {
client.doEvent(new SlotChoice(playerUsername,pos));
}
}