Docs: refine JavaDoc for building effects and controllers
This commit is contained in:
@@ -1,42 +1,39 @@
|
||||
package it.polimi.ingsw.gc14.Controller;
|
||||
|
||||
import it.polimi.ingsw.gc14.Model.*;
|
||||
import it.polimi.ingsw.gc14.Model.GamePackage.Board;
|
||||
import it.polimi.ingsw.gc14.Model.GamePackage.CurrentState;
|
||||
import it.polimi.ingsw.gc14.Model.MiniModel;
|
||||
import it.polimi.ingsw.gc14.Network.IClient;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvents.*;
|
||||
import it.polimi.ingsw.gc14.View.IView;
|
||||
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* Controller responsible for coordinating the client-side components,
|
||||
* including the view, the network client and the local mini model.
|
||||
*
|
||||
* <p>It receives user actions from the view, performs basic client-side
|
||||
* checks and forwards valid requests to the network client.
|
||||
*/
|
||||
public class ClientController {
|
||||
|
||||
/** Game Controller of the client */
|
||||
/** Local mini model representing the client-side game state. */
|
||||
public MiniModel miniModel;
|
||||
|
||||
/** View of the client */
|
||||
/** View of the client. */
|
||||
public IView view;
|
||||
|
||||
/** Network client (either TCP or RMI) */
|
||||
/** Network client, either TCP or RMI. */
|
||||
private IClient client;
|
||||
|
||||
/**
|
||||
* The username of the client associated with this event.
|
||||
*/
|
||||
/** Username associated with this client. */
|
||||
public String myUsername;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Constructs the ClientController.
|
||||
* Initializes all attributes.
|
||||
* @param view the client view (either TUI or GUI)
|
||||
* Constructs a client controller with the specified view.
|
||||
*
|
||||
* <p>The network client is initially unset and an empty local mini model
|
||||
* is created.
|
||||
*
|
||||
* @param view the client view, either TUI or GUI.
|
||||
*/
|
||||
public ClientController(IView view) {
|
||||
this.view = view;
|
||||
@@ -44,19 +41,19 @@ public class ClientController {
|
||||
this.miniModel = new MiniModel();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the network client.
|
||||
* @param client the client to set (either TCP or RMI)
|
||||
*
|
||||
* @param client the client to set, either TCP or RMI.
|
||||
*/
|
||||
public void setClient(IClient client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the model in the GameController and updates the view.
|
||||
* @param model the model to set
|
||||
* Sets the local mini model and updates the view accordingly.
|
||||
*
|
||||
* @param model the mini model to set.
|
||||
*/
|
||||
public void setModel(MiniModel model) {
|
||||
this.miniModel = model;
|
||||
@@ -64,131 +61,139 @@ public class ClientController {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the username of the client associated with this event.
|
||||
* Sets the username associated with this client.
|
||||
*
|
||||
* @param username the username to set.
|
||||
*/
|
||||
public void setMyUsername (String username) {
|
||||
this.myUsername=username;
|
||||
public void setMyUsername(String username) {
|
||||
this.myUsername = username;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Displays an error message in the view.
|
||||
* @param message the error message to display
|
||||
*
|
||||
* @param message the error message to display.
|
||||
*/
|
||||
public void onError(String message) {
|
||||
view.showError(message);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Requests to draw a tribe card from the upper list.
|
||||
* Creates a NetworkEvent and sends it through the network client.
|
||||
* @param playerUsername the name of the player performing the action
|
||||
* @param pos the index of the card to draw
|
||||
*
|
||||
* <p>If the specified player is not the current player, an error message
|
||||
* is shown. Otherwise, the request is forwarded to the network client.
|
||||
*
|
||||
* @param playerUsername the username of the player performing the action.
|
||||
* @param pos the index of the card to draw.
|
||||
*/
|
||||
public void drawUpperTribeCard(String playerUsername, int pos) {
|
||||
|
||||
if(!Objects.equals(playerUsername, miniModel.currentState.getCurrentPlayer().getUserName()))
|
||||
{
|
||||
if (!Objects.equals(playerUsername, miniModel.currentState.getCurrentPlayer().getUserName())) {
|
||||
view.showError("It's not your turn!");
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
client.drawUpperTribeCard(playerUsername, pos);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Requests to draw a tribe card from the lower list.
|
||||
* Creates a NetworkEvent and sends it through the network client.
|
||||
* @param playerUsername the name of the player performing the action
|
||||
* @param pos the index of the card to draw
|
||||
*
|
||||
* <p>If the specified player is not the current player, an error message
|
||||
* is shown. Otherwise, the request is forwarded to the network client.
|
||||
*
|
||||
* @param playerUsername the username of the player performing the action.
|
||||
* @param pos the index of the card to draw.
|
||||
*/
|
||||
public void drawLowerTribeCard(String playerUsername,int pos) {
|
||||
if(!Objects.equals(playerUsername, miniModel.currentState.getCurrentPlayer().getUserName()))
|
||||
public void drawLowerTribeCard(String playerUsername, int pos) {
|
||||
if (!Objects.equals(playerUsername, miniModel.currentState.getCurrentPlayer().getUserName())) {
|
||||
view.showError("It's not your turn!");
|
||||
else
|
||||
} else {
|
||||
client.drawLowerTribeCard(playerUsername, pos);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Requests to draw a building card from the upper list.
|
||||
* Creates a NetworkEvent and sends it through the network client.
|
||||
* @param playerUsername the name of the player performing the action
|
||||
* @param pos the index of the card to draw
|
||||
*
|
||||
* <p>If the specified player is not the current player, an error message
|
||||
* is shown. Otherwise, the request is forwarded to the network client.
|
||||
*
|
||||
* @param playerUsername the username of the player performing the action.
|
||||
* @param pos the index of the card to draw.
|
||||
*/
|
||||
public void drawUpperBuildingCard(String playerUsername,int pos) {
|
||||
if(!Objects.equals(playerUsername, miniModel.currentState.getCurrentPlayer().getUserName()))
|
||||
public void drawUpperBuildingCard(String playerUsername, int pos) {
|
||||
if (!Objects.equals(playerUsername, miniModel.currentState.getCurrentPlayer().getUserName())) {
|
||||
view.showError("It's not your turn!");
|
||||
else {
|
||||
client.drawUpperBuildingCard(playerUsername,pos);
|
||||
} else {
|
||||
client.drawUpperBuildingCard(playerUsername, pos);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Requests to draw a building card from the lower list.
|
||||
* Creates a NetworkEvent and sends it through the network client.
|
||||
* @param playerUsername the name of the player performing the action
|
||||
* @param pos the index of the card to draw
|
||||
*
|
||||
* <p>If the specified player is not the current player, an error message
|
||||
* is shown. Otherwise, the request is forwarded to the network client.
|
||||
*
|
||||
* @param playerUsername the username of the player performing the action.
|
||||
* @param pos the index of the card to draw.
|
||||
*/
|
||||
public void drawLowerBuildingCard(String playerUsername,int pos) {
|
||||
if(!Objects.equals(playerUsername,miniModel.currentState.getCurrentPlayer().getUserName()))
|
||||
public void drawLowerBuildingCard(String playerUsername, int pos) {
|
||||
if (!Objects.equals(playerUsername, miniModel.currentState.getCurrentPlayer().getUserName())) {
|
||||
view.showError("It's not your turn!");
|
||||
else {
|
||||
client.drawLowerBuildingCard(playerUsername,pos);
|
||||
} else {
|
||||
client.drawLowerBuildingCard(playerUsername, pos);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Requests to skip turn .
|
||||
* This action is available only when the player cannot draw any tribe card.
|
||||
* @param playerUsername the name of the player performing the action
|
||||
* Requests to skip the current turn.
|
||||
*
|
||||
* <p>If the specified player is not the current player, an error message
|
||||
* is shown. Otherwise, the request is forwarded to the network client.
|
||||
*
|
||||
* @param playerUsername the username of the player performing the action.
|
||||
*/
|
||||
public void skipTurn(String playerUsername) {
|
||||
if(!Objects.equals(playerUsername,miniModel.currentState.getCurrentPlayer().getUserName()))
|
||||
if (!Objects.equals(playerUsername, miniModel.currentState.getCurrentPlayer().getUserName())) {
|
||||
view.showError("It's not your turn!");
|
||||
else {
|
||||
} else {
|
||||
client.skipTurn(playerUsername);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Used to perform the slot choice action for the specified player at the specified position.
|
||||
* @param playerUsername the name of the player performing the action
|
||||
* @param pos the index of the selected slot
|
||||
* Requests the selection of a slot by the specified player.
|
||||
*
|
||||
* <p>If the specified player is not the current player, an error message
|
||||
* is shown. Otherwise, the request is forwarded to the network client.
|
||||
*
|
||||
* @param playerUsername the username of the player performing the action.
|
||||
* @param pos the index of the selected slot.
|
||||
*/
|
||||
public void slotChoice(String playerUsername,int pos) {
|
||||
if(!Objects.equals(playerUsername, miniModel.currentState.getCurrentPlayer().getUserName()))
|
||||
public void slotChoice(String playerUsername, int pos) {
|
||||
if (!Objects.equals(playerUsername, miniModel.currentState.getCurrentPlayer().getUserName())) {
|
||||
view.showError("It's not your turn!");
|
||||
else {
|
||||
client.slotChoice(playerUsername,pos);
|
||||
} else {
|
||||
client.slotChoice(playerUsername, pos);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the selection of a totem by the specified player.
|
||||
*
|
||||
* <p>If the player is not the current one, an error message is shown.
|
||||
* Otherwise, the selected totem is retrieved from the available totems
|
||||
* and the choice is forwarded to the client.
|
||||
* <p>If the specified player is not the current player, an error message
|
||||
* is shown. Otherwise, the selected totem is retrieved from the available
|
||||
* totems list and the choice is forwarded to the network client.
|
||||
*
|
||||
* @param playerUsername the username of the player making the choice.
|
||||
* @param pos the position of the selected totem in the available totems list.
|
||||
* @param pos the index of the selected totem in the available totems list.
|
||||
*/
|
||||
public void totemChoice(String playerUsername,int pos) {
|
||||
if(!Objects.equals(playerUsername, miniModel.currentState.getCurrentPlayer().getUserName()))
|
||||
public void totemChoice(String playerUsername, int pos) {
|
||||
if (!Objects.equals(playerUsername, miniModel.currentState.getCurrentPlayer().getUserName())) {
|
||||
view.showError("It's not your turn!");
|
||||
else {
|
||||
} else {
|
||||
client.totemChoice(playerUsername, String.valueOf(miniModel.availableTotems.get(pos)));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,10 @@ import it.polimi.ingsw.gc14.Model.Player;
|
||||
import it.polimi.ingsw.gc14.Model.Totems;
|
||||
|
||||
/**
|
||||
* Controller class that manages interactions between the client-side logic
|
||||
* and the {@link Game} model.
|
||||
* It provides methods to add players and to perform game actions by delegating them to the model.
|
||||
* Controller responsible for managing interactions with the {@link Game} model.
|
||||
*
|
||||
* <p>It provides methods to update the game state by delegating player-related
|
||||
* actions and game actions to the underlying model.
|
||||
*/
|
||||
public class GameController {
|
||||
|
||||
@@ -36,7 +37,8 @@ public class GameController {
|
||||
*
|
||||
* @param username the username of the player who disconnected.
|
||||
* @return {@code true} if the disconnection is handled successfully,
|
||||
* {@code false} if no player with the specified username exists.
|
||||
* {@code false} if no player with the specified username exists
|
||||
* or if the operation fails.
|
||||
*/
|
||||
public boolean DisconnectedPlayer(String username)
|
||||
{
|
||||
@@ -51,7 +53,8 @@ public class GameController {
|
||||
*
|
||||
* @param username the username of the player who reconnected.
|
||||
* @return {@code true} if the reconnection is handled successfully,
|
||||
* {@code false} if no player with the specified username exists.
|
||||
* {@code false} if no player with the specified username exists
|
||||
* or if the operation fails.
|
||||
*/
|
||||
public boolean ReconnectPlayer(String username)
|
||||
{
|
||||
@@ -83,19 +86,21 @@ public class GameController {
|
||||
* Attempts to add a new player with the specified username to the game model.
|
||||
*
|
||||
* @param username the username of the player to add.
|
||||
* @return {@code true} if the player is successfully added, {@code false} otherwise.
|
||||
* @return {@code true} if the player is successfully added,
|
||||
* {@code false} otherwise.
|
||||
*/
|
||||
public boolean addPlayer(String username) {
|
||||
return model.addPlayer(new Player(username));
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to draw an upper tribe card for the specified player from the specified position.
|
||||
* 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.
|
||||
* @return {@code true} if the action succeeds,
|
||||
* {@code false} if the player does not exist or if the draw operation fails.
|
||||
*/
|
||||
public boolean drawUpperTribeCard(String playerUsername,int pos) {
|
||||
Player player= model.getPlayerByUsername(playerUsername);
|
||||
@@ -105,12 +110,13 @@ public class GameController {
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to draw a lower tribe card for the specified player from the specified position.
|
||||
* 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.
|
||||
* @return {@code true} if the action succeeds,
|
||||
* {@code false} if the player does not exist or if the draw operation fails.
|
||||
*/
|
||||
public boolean drawLowerTribeCard(String playerUsername,int pos) {
|
||||
Player player= model.getPlayerByUsername(playerUsername);
|
||||
@@ -120,12 +126,13 @@ public class GameController {
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to draw an upper building card for the specified player from the specified position.
|
||||
* 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.
|
||||
* @return {@code true} if the action succeeds,
|
||||
* {@code false} if the player does not exist or if the draw operation fails.
|
||||
*/
|
||||
public boolean drawUpperBuildingCard(String playerUsername,int pos) {
|
||||
Player player= model.getPlayerByUsername(playerUsername);
|
||||
@@ -135,12 +142,13 @@ public class GameController {
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to draw a lower building card for the specified player from the specified position.
|
||||
* 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.
|
||||
* @return {@code true} if the action succeeds,
|
||||
* {@code false} if the player does not exist or if the draw operation fails.
|
||||
*/
|
||||
public boolean drawLowerBuildingCard(String playerUsername,int pos) {
|
||||
Player player= model.getPlayerByUsername(playerUsername);
|
||||
@@ -153,9 +161,9 @@ public class GameController {
|
||||
/**
|
||||
* Skips the card drawing action for the specified player.
|
||||
*
|
||||
* @param playerUsername the username of the player who wants to skip the turn action.
|
||||
* @return {@code true} if the skip action is valid and successfully performed;
|
||||
* {@code false} if the player does not exist or the action is not valid.
|
||||
* @param playerUsername the username of the player performing the action.
|
||||
* @return {@code true} if the skip action is valid and successfully performed,
|
||||
* {@code false} if the player does not exist or if the action is not valid.
|
||||
*/
|
||||
public boolean SkipTurn(String playerUsername) {
|
||||
Player player= model.getPlayerByUsername(playerUsername);
|
||||
@@ -167,12 +175,13 @@ public class GameController {
|
||||
|
||||
|
||||
/**
|
||||
* Attempts to perform the slot choice action for the specified player at the specified position.
|
||||
* 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.
|
||||
* @return {@code true} if the action succeeds,
|
||||
* {@code false} if the player does not exist or if the slot choice operation fails.
|
||||
*/
|
||||
public boolean slotChoice(String playerUsername,int pos) {
|
||||
Player player= model.getPlayerByUsername(playerUsername);
|
||||
@@ -185,9 +194,10 @@ public class GameController {
|
||||
* Applies the totem choice made by the player associated with the specified username.
|
||||
*
|
||||
* @param playerUsername the username of the player making the choice.
|
||||
* @param totem the name of the selected totem.
|
||||
* @param totem the name of the selected totem.
|
||||
* @return {@code true} if the choice is handled successfully,
|
||||
* {@code false} if no player with the specified username exists.
|
||||
* {@code false} if no player with the specified username exists
|
||||
* or if the choice operation fails.
|
||||
*/
|
||||
public boolean TotemChoice(String playerUsername,String totem) {
|
||||
Player player= model.getPlayerByUsername(playerUsername);
|
||||
@@ -195,4 +205,4 @@ public class GameController {
|
||||
return false;
|
||||
return model.TotemChoice(player, Totems.valueOf(totem));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user