Merge branch 'main' into javadoc-fixes

This commit is contained in:
rubenpirreram
2026-05-06 17:36:37 +02:00
committed by GitHub
191 changed files with 2398 additions and 367 deletions
@@ -1,12 +1,13 @@
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;
import java.rmi.RemoteException;
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.
@@ -50,7 +51,7 @@ public class ClientController {
*/
public void setModel(Game model) {
localController.setModel(model);
view.update(localController.getModel());
view.setModel(localController.getModel());
}
@@ -70,7 +71,19 @@ public class ClientController {
* @param pos the index of the card to draw
*/
public void drawUpperTribeCard(String playerUsername, int pos) {
client.doEvent(new DrawUpperTribeCard(playerUsername,pos));
if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName()))
{
view.showError("It's not your turn!");
}
else
{
try {
client.drawUpperTribeCard(playerUsername, pos);
} catch (RemoteException e) {
throw new RuntimeException(e);
}
}
}
@@ -81,7 +94,14 @@ public class ClientController {
* @param pos the index of the card to draw
*/
public void drawLowerTribeCard(String playerUsername,int pos) {
client.doEvent(new DrawLowerTribeCard(playerUsername,pos));
if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName()))
view.showError("It's not your turn!");
else
try {
client.drawLowerTribeCard(playerUsername, pos);
} catch (RemoteException e) {
throw new RuntimeException(e);
}
}
@@ -92,7 +112,16 @@ public class ClientController {
* @param pos the index of the card to draw
*/
public void drawUpperBuildingCard(String playerUsername,int pos) {
client.doEvent(new DrawUpperBuildingCard(playerUsername,pos));
if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName()))
view.showError("It's not your turn!");
else {
try {
client.drawUpperBuildingCard(playerUsername,pos);
} catch (RemoteException e) {
throw new RuntimeException(e);
}
}
}
@@ -103,7 +132,15 @@ public class ClientController {
* @param pos the index of the card to draw
*/
public void drawLowerBuildingCard(String playerUsername,int pos) {
client.doEvent(new DrawLowerBuildingCard(playerUsername,pos));
if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName()))
view.showError("It's not your turn!");
else {
try {
client.drawLowerBuildingCard(playerUsername,pos);
} catch (RemoteException e) {
throw new RuntimeException(e);
}
}
}
@@ -113,7 +150,15 @@ public class ClientController {
* @param playerUsername the name of the player performing the action
*/
public void skipUpper(String playerUsername) {
client.doEvent(new SkipUpper(playerUsername));
if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName()))
view.showError("It's not your turn!");
else {
try {
client.skipUpper(playerUsername);
} catch (RemoteException e) {
throw new RuntimeException(e);
}
}
}
@@ -122,7 +167,17 @@ public class ClientController {
* This action is available only when the lower list is empty or the player cannot draw any card.
* @param playerUsername the name of the player performing the action
*/
public void skipLower(String playerUsername) { client.doEvent(new SkipLower(playerUsername));}
public void skipLower(String playerUsername) {
if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName()))
view.showError("It's not your turn!");
else {
try {
client.skipLower(playerUsername);
} catch (RemoteException e) {
throw new RuntimeException(e);
}
}
}
/**
@@ -132,7 +187,15 @@ public class ClientController {
* @param pos the index of the card to draw
*/
public void pickOptionalTribeCard(String playerUsername,int pos) {
client.doEvent(new PickOptionalTribeCard(playerUsername,pos));
if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName()))
view.showError("It's not your turn!");
else {
try {
client.pickOptionalTribeCard(playerUsername,pos);
} catch (RemoteException e) {
throw new RuntimeException(e);
}
}
}
@@ -143,7 +206,15 @@ public class ClientController {
* @param pos the index of the card to draw
*/
public void pickOptionalBuildingCard(String playerUsername,int pos) {
client.doEvent(new PickOptionalBuildingCard(playerUsername,pos));
if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName()))
view.showError("It's not your turn!");
else {
try {
client.pickOptionalBuildingCard(playerUsername,pos);
} catch (RemoteException e) {
throw new RuntimeException(e);
}
}
}
@@ -153,7 +224,15 @@ public class ClientController {
* @param playerUsername the name of the player performing the action
*/
public void noOptionalCard(String playerUsername) {
client.doEvent(new NoOptionalCard(playerUsername));
if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName()))
view.showError("It's not your turn!");
else {
try {
client.noOptionalCard(playerUsername);
} catch (RemoteException e) {
throw new RuntimeException(e);
}
}
}
@@ -163,7 +242,15 @@ public class ClientController {
* @param pos the index of the selected slot
*/
public void slotChoice(String playerUsername,int pos) {
client.doEvent(new SlotChoice(playerUsername,pos));
if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName()))
view.showError("It's not your turn!");
else {
try {
client.slotChoice(playerUsername,pos);
} catch (RemoteException e) {
throw new RuntimeException(e);
}
}
}
}