diff --git a/src/main/java/it/polimi/ingsw/gc14/Controller/ClientController.java b/src/main/java/it/polimi/ingsw/gc14/Controller/ClientController.java index d51891c..18b3a70 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Controller/ClientController.java +++ b/src/main/java/it/polimi/ingsw/gc14/Controller/ClientController.java @@ -77,7 +77,7 @@ public class ClientController { } else { - client.doEvent(new DrawUpperTribeCard(playerUsername,pos)); + client.drawUpperTribeCard(playerUsername, pos); } } @@ -92,7 +92,7 @@ public class ClientController { if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName())) view.showError("It's not your turn!"); else - client.doEvent(new DrawLowerTribeCard(playerUsername,pos)); + client.drawLowerTribeCard(playerUsername,pos); } @@ -106,7 +106,7 @@ public class ClientController { if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName())) view.showError("It's not your turn!"); else - client.doEvent(new DrawUpperBuildingCard(playerUsername,pos)); + client.drawUpperBuildingCard(playerUsername,pos); } @@ -121,7 +121,7 @@ public class ClientController { if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName())) view.showError("It's not your turn!"); else - client.doEvent(new DrawLowerBuildingCard(playerUsername,pos)); + client.drawLowerBuildingCard(playerUsername,pos); } @@ -134,7 +134,7 @@ public class ClientController { if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName())) view.showError("It's not your turn!"); else - client.doEvent(new SkipUpper(playerUsername)); + client.skipUpper(playerUsername); } @@ -147,7 +147,8 @@ public class ClientController { if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName())) view.showError("It's not your turn!"); else - client.doEvent(new SkipLower(playerUsername));} + client.skipLower(playerUsername); + } /** @@ -160,7 +161,7 @@ public class ClientController { if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName())) view.showError("It's not your turn!"); else - client.doEvent(new PickOptionalTribeCard(playerUsername,pos)); + client.pickOptionalTribeCard(playerUsername,pos); } @@ -174,7 +175,7 @@ public class ClientController { if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName())) view.showError("It's not your turn!"); else - client.doEvent(new PickOptionalBuildingCard(playerUsername,pos)); + client.pickOptionalBuildingCard(playerUsername,pos); } @@ -187,7 +188,7 @@ public class ClientController { if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName())) view.showError("It's not your turn!"); else - client.doEvent(new NoOptionalCard(playerUsername)); + client.noOptionalCard(playerUsername); } @@ -200,7 +201,7 @@ public class ClientController { if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName())) view.showError("It's not your turn!"); else - client.doEvent(new SlotChoice(playerUsername,pos)); + client.slotChoice(playerUsername,pos); } } diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/IClient.java b/src/main/java/it/polimi/ingsw/gc14/Network/IClient.java index 86f6435..f52aaba 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/IClient.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/IClient.java @@ -1,8 +1,33 @@ package it.polimi.ingsw.gc14.Network; +import it.polimi.ingsw.gc14.Network.NetworkEvents.*; + import java.rmi.RemoteException; +import java.util.Objects; public interface IClient { public boolean connect(String username,int preferredInt); - public void doEvent(NetworkEvent event) ; + + public void drawUpperTribeCard(String playerUsername, int pos) ; + + public void drawLowerTribeCard(String playerUsername,int pos) ; + + public void drawUpperBuildingCard(String playerUsername,int pos); + + + public void drawLowerBuildingCard(String playerUsername,int pos) ; + + public void skipUpper(String playerUsername) ; + + public void skipLower(String playerUsername) ; + + + public void pickOptionalTribeCard(String playerUsername,int pos) ; + + public void pickOptionalBuildingCard(String playerUsername,int pos); + + + public void noOptionalCard(String playerUsername) ; + + public void slotChoice(String playerUsername,int pos) ; } diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/RMIClient.java b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/RMIClient.java index be92164..deb8d15 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/RMIClient.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/RMIClient.java @@ -2,10 +2,12 @@ package it.polimi.ingsw.gc14.Network.RMI.Client; import java.rmi.RemoteException; import java.rmi.registry.LocateRegistry; import java.rmi.registry.Registry; +import java.util.Objects; import it.polimi.ingsw.gc14.Controller.ClientController; import it.polimi.ingsw.gc14.Network.IClient; import it.polimi.ingsw.gc14.Network.NetworkEvent; +import it.polimi.ingsw.gc14.Network.NetworkEvents.*; import it.polimi.ingsw.gc14.Network.RMI.Common.IClientCallback; import it.polimi.ingsw.gc14.Network.RMI.Common.IGameServer; import it.polimi.ingsw.gc14.Network.RMI.Server.RMIServer; @@ -64,17 +66,111 @@ public class RMIClient implements IClient { } - /** - * Sends a {@link NetworkEvent} to the server. - * @param event the event to send - * @throws RemoteException if any RMI error occurs - */ - public void doEvent(NetworkEvent event) { - try { - stub.doEvent(event); - }catch (Exception e) { - } + /** + * 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 + */ + public void drawUpperTribeCard(String playerUsername, int pos) { + stub.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 + */ + public void drawLowerTribeCard(String playerUsername,int pos) { + stub.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 + */ + public void drawUpperBuildingCard(String playerUsername,int pos) { + stub.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 + */ + public void drawLowerBuildingCard(String playerUsername,int pos) { + stub.drawLowerBuildingCard(playerUsername,pos); + } + + + /** + * Requests to skip drawing from the upper list. + * This action is available only when the upper list is empty or the player cannot draw any card. + * @param playerUsername the name of the player performing the action + */ + public void skipUpper(String playerUsername) { + stub.skipUpper(playerUsername); + } + + + /** + * Requests to skip drawing from the lower list. + * 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) { + stub.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 performing the action + * @param pos the index of the card to draw + */ + public void pickOptionalTribeCard(String playerUsername,int pos) { + stub.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 performing the action + * @param pos the index of the card to draw + */ + public void pickOptionalBuildingCard(String playerUsername,int pos) { + stub.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 performing the action + */ + public void noOptionalCard(String playerUsername) { + stub.noOptionalCard(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 + */ + public void slotChoice(String playerUsername,int pos) { + stub.slotChoice(playerUsername,pos); + } + + } \ No newline at end of file diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Common/IGameServer.java b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Common/IGameServer.java index 7a1ef25..24bd19a 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Common/IGameServer.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Common/IGameServer.java @@ -8,5 +8,27 @@ public interface IGameServer extends Remote { boolean joinGame(String username,int preferredInt, IClientCallback callback) throws RemoteException; boolean doEvent(NetworkEvent event) throws RemoteException; + void drawUpperTribeCard(String playerUsername, int pos) ; + + void drawLowerTribeCard(String playerUsername,int pos) ; + + void drawUpperBuildingCard(String playerUsername,int pos); + + + void drawLowerBuildingCard(String playerUsername,int pos) ; + + void skipUpper(String playerUsername) ; + + void skipLower(String playerUsername) ; + + + void pickOptionalTribeCard(String playerUsername,int pos) ; + + void pickOptionalBuildingCard(String playerUsername,int pos); + + + void noOptionalCard(String playerUsername) ; + + void slotChoice(String playerUsername,int pos) ; } diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java index 66daa9d..664a686 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java @@ -4,6 +4,7 @@ import it.polimi.ingsw.gc14.Controller.GameController; import it.polimi.ingsw.gc14.LimitedList; import it.polimi.ingsw.gc14.Model.Game; import it.polimi.ingsw.gc14.Network.NetworkEvent; +import it.polimi.ingsw.gc14.Network.NetworkEvents.*; import it.polimi.ingsw.gc14.Network.RMI.Common.IClientCallback; import it.polimi.ingsw.gc14.Network.RMI.Common.IGameServer; @@ -12,6 +13,7 @@ import java.rmi.registry.LocateRegistry; import java.rmi.registry.Registry; import java.rmi.server.UnicastRemoteObject; import java.util.Map; +import java.util.Objects; import java.util.concurrent.BlockingQueue; import java.util.concurrent.ConcurrentHashMap; @@ -109,6 +111,121 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer { return actionQueue.offer(action); } + /** + * 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 + */ + @Override + public void drawUpperTribeCard(String playerUsername, int pos) { + + actionQueue.offer(new 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 + */ + @Override + public void drawLowerTribeCard(String playerUsername,int pos) { + actionQueue.offer(new 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 + */ + @Override + public void drawUpperBuildingCard(String playerUsername,int pos) { + actionQueue.offer(new 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 + */ + @Override + public void drawLowerBuildingCard(String playerUsername,int pos) { + actionQueue.offer(new DrawLowerBuildingCard(playerUsername,pos)); + } + + + /** + * Requests to skip drawing from the upper list. + * This action is available only when the upper list is empty or the player cannot draw any card. + * @param playerUsername the name of the player performing the action + */ + @Override + public void skipUpper(String playerUsername) { + actionQueue.offer(new SkipUpper(playerUsername)); + } + + + /** + * Requests to skip drawing from the lower list. + * 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 + */ + @Override + public void skipLower(String playerUsername) { + actionQueue.offer(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 performing the action + * @param pos the index of the card to draw + */ + @Override + public void pickOptionalTribeCard(String playerUsername,int pos) { + actionQueue.offer(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 performing the action + * @param pos the index of the card to draw + */ + @Override + public void pickOptionalBuildingCard(String playerUsername,int pos) { + actionQueue.offer(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 performing the action + */ + @Override + public void noOptionalCard(String playerUsername) { + actionQueue.offer(new NoOptionalCard(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 + */ + @Override + public void slotChoice(String playerUsername,int pos) { + actionQueue.offer(new SlotChoice(playerUsername,pos)); + } // RMI's internal methods diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Client/TCPClient.java b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Client/TCPClient.java index c7b1aac..e9ef147 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Client/TCPClient.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Client/TCPClient.java @@ -4,7 +4,7 @@ import it.polimi.ingsw.gc14.Controller.ClientController; import it.polimi.ingsw.gc14.Model.Game; import it.polimi.ingsw.gc14.Network.IClient; import it.polimi.ingsw.gc14.Network.NetworkEvent; -import it.polimi.ingsw.gc14.Network.NetworkEvents.AddPlayer; +import it.polimi.ingsw.gc14.Network.NetworkEvents.*; import java.io.*; import java.net.*; @@ -113,12 +113,117 @@ public class TCPClient implements IClient { } } + /** + * 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 + */ + public void drawUpperTribeCard(String playerUsername, int pos) { + doEvent(new 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 + */ + public void drawLowerTribeCard(String playerUsername,int pos) { + doEvent(new 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 + */ + public void drawUpperBuildingCard(String playerUsername,int pos) { + doEvent(new 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 + */ + public void drawLowerBuildingCard(String playerUsername,int pos) { + doEvent(new DrawLowerBuildingCard(playerUsername,pos)); + } + + + /** + * Requests to skip drawing from the upper list. + * This action is available only when the upper list is empty or the player cannot draw any card. + * @param playerUsername the name of the player performing the action + */ + public void skipUpper(String playerUsername) { + doEvent(new SkipUpper(playerUsername)); + } + + + /** + * Requests to skip drawing from the lower list. + * 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) { + 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 performing the action + * @param pos the index of the card to draw + */ + public void pickOptionalTribeCard(String playerUsername,int pos) { + 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 performing the action + * @param pos the index of the card to draw + */ + public void pickOptionalBuildingCard(String playerUsername,int pos) { + 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 performing the action + */ + public void noOptionalCard(String playerUsername) { + doEvent(new NoOptionalCard(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 + */ + public void slotChoice(String playerUsername,int pos) { + doEvent(new SlotChoice(playerUsername,pos)); + } /** * Sends a {@link NetworkEvent} to the server. * @param event The NetworkEvent to send. */ - public void doEvent(NetworkEvent event) { + private void doEvent(NetworkEvent event) { try { socketSend.writeObject(event); } catch (IOException e) {