java.lang.Object
java.rmi.server.RemoteObject
java.rmi.server.RemoteServer
java.rmi.server.UnicastRemoteObject
it.polimi.ingsw.am13.network.rmi.GameControllerRMI
- All Implemented Interfaces:
GameControllerRMIIF
,Serializable
,Remote
Version of class representing gameController for the RMI connection. Hence this class is exposed to the network as RMI remote object.
The controller is the controller given to a particular players using RMI for connection. This implies the methods called
via this gameController are implicitly referred to the players it belongs to.
This is a controller for a single game/match
This is a controller for a single game/match
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final GameController
Wrapped gameControllerprivate final PlayerLobby
Fields inherited from class java.rmi.server.RemoteObject
ref
-
Constructor Summary
ConstructorsConstructorDescriptionGameControllerRMI
(GameController gameController, PlayerLobby player) Wraps the given gameController to be exposed to the network, and associates this specific controller to the given player -
Method Summary
Modifier and TypeMethodDescriptionvoid
choosePersonalObjective
(CardObjectiveIF cardObj) Method callable only during INIT phase.int
private void
logCommand
(String cmd) Logging function which notifies the command which has been received on the server console .void
pickCard
(CardPlayableIF card) Picks one of the 6 cards on the table, and makes the game proceed to the next Turn.void
playCard
(CardPlayableIF card, Side side, Coordinates coord) Plays a given card side on the field, at the given coordinatesvoid
playStarter
(Side side) Method callable only once during INIT phase.void
transmitChatMessage
(List<PlayerLobby> receivers, String text) Transmits a chat message (while this message will not cause any change in the model, nor will it be stored, it follows the same path as all the other messages)void
Updates the ping of the player's listener by setting it to the current timeMethods inherited from class java.rmi.server.UnicastRemoteObject
clone, exportObject, exportObject, exportObject, exportObject, exportObject, unexportObject
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
-
Field Details
-
gameController
Wrapped gameController -
player
-
-
Constructor Details
-
GameControllerRMI
public GameControllerRMI(GameController gameController, PlayerLobby player) throws RemoteException, InvalidPlayerException Wraps the given gameController to be exposed to the network, and associates this specific controller to the given player- Parameters:
gameController
- gameController to wrap in order to be exposed to the networkplayer
- Player (client RMI) who will use this gameController- Throws:
InvalidPlayerException
- If the given player is not present in the gameRemoteException
-
-
Method Details
-
logCommand
Logging function which notifies the command which has been received on the server console .- Parameters:
cmd
- Command name
-
updatePing
Updates the ping of the player's listener by setting it to the current time- Specified by:
updatePing
in interfaceGameControllerRMIIF
- Throws:
RemoteException
-
playStarter
public void playStarter(Side side) throws RemoteException, InvalidPlayCardException, GameStatusException Method callable only once during INIT phase. It plays the starter card of the player on the passed side- Specified by:
playStarter
in interfaceGameControllerRMIIF
- Parameters:
side
- The side of the starting card- Throws:
GameStatusException
- If game phase is not INITInvalidPlayCardException
- Positioning error of the card at coordinates (0,0).RemoteException
-
choosePersonalObjective
public void choosePersonalObjective(CardObjectiveIF cardObj) throws RemoteException, InvalidChoiceException, VariableAlreadySetException, GameStatusException Method callable only during INIT phase. Sets the personal objective of the player according to his choice. The objective card must be between the 2 possible cards given to the player. They can be retrieved withfetchPersonalObjectives(player)
- Specified by:
choosePersonalObjective
in interfaceGameControllerRMIIF
- Parameters:
cardObj
- the objective chosen by the player- Throws:
GameStatusException
- if this method isn't called in the INIT phaseInvalidChoiceException
- if the objective card does not belong to the list of the possible objective cards for the playerVariableAlreadySetException
- if this method has been called before for the playerRemoteException
-
playCard
public void playCard(CardPlayableIF card, Side side, Coordinates coord) throws RemoteException, RequirementsNotMetException, InvalidPlayCardException, GameStatusException Plays a given card side on the field, at the given coordinates- Specified by:
playCard
in interfaceGameControllerRMIIF
- Parameters:
card
- Card which is being played. It must be in player's handside
- Indicates whether the card is going to be played on the front or on the backcoord
- Coordinates in the field of the player where the card is going to be positioned- Throws:
RequirementsNotMetException
- If the requirements for playing the specified card in player's field are not metInvalidPlayCardException
- If the player doesn't have the specified cardGameStatusException
- If this method is called in the INIT or CALC POINTS phaseRemoteException
-
pickCard
public void pickCard(CardPlayableIF card) throws RemoteException, InvalidDrawCardException, GameStatusException Picks one of the 6 cards on the table, and makes the game proceed to the next Turn. If there is no other turn to play after this one, it adds the objective points and calculates the winner.- Specified by:
pickCard
in interfaceGameControllerRMIIF
- Parameters:
card
- A playable card that should be in the field- Throws:
InvalidDrawCardException
- if the passed card is not on the tableGameStatusException
- if this method is called in the INIT or CALC POINTS phaseRemoteException
-
getGameId
- Specified by:
getGameId
in interfaceGameControllerRMIIF
- Returns:
- Unique number indicating the actual game model (hence the game/match to its all entirety)
- Throws:
RemoteException
-
getPlayers
- Specified by:
getPlayers
in interfaceGameControllerRMIIF
- Returns:
- the players of the match
- Throws:
RemoteException
-
transmitChatMessage
Transmits a chat message (while this message will not cause any change in the model, nor will it be stored, it follows the same path as all the other messages)- Specified by:
transmitChatMessage
in interfaceGameControllerRMIIF
- Parameters:
receivers
- of the messagetext
- content of the message- Throws:
RemoteException
-