Package it.polimi.ingsw.controller
Class Game
java.lang.Object
java.rmi.server.RemoteObject
java.rmi.server.RemoteServer
java.rmi.server.UnicastRemoteObject
it.polimi.ingsw.controller.Game
- All Implemented Interfaces:
GameI
,Serializable
,Remote
class which represent the instance of the current game
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final double
variable that represent the fast timer of the app for small waiting taskstatic final double
variable that represent the timer for the new turn (changing) interactionstatic boolean
variable that represent if we want to run or debug our applicationstatic final double
variable that represent the standard timer of the app for showing eventsstatic final double
variable that represent the standard timer of the app for advancing the state of the gameFields inherited from class java.rmi.server.RemoteObject
ref
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
method called from remote used to add a client to the store of all the RMI clientsvoid
Set the status of the players for the next turn and assign activePlayer to who will play this turnvoid
function that handle the eventual disconnectiongetter for the input streams from the server to all the clientsgetNames()
getter for the list of names of the players active in this gamevoid
ping()
method that allow the server to be pinged from an RMI clientvoid
pingRMI()
method that periodically pings all the current client connected with RMIvoid
playerDisconnected
(int i, Exception exc) method which acknowledge that one of the client disconnected and set the game to continue without the lost clientvoid
method called from remote which is equivalent to the waitMoveFromClient() method for the socketvoid
sendChatToClients
(String from, String to, String msg) Send message in the chat to other clientvoid
sendToClient
(int i, Message msg) general method to respond to a client, it chooses the right network connection of the playerstatic void
waitForSeconds
(double n) shortcut for the Thread.sleep(int) function, it accepts SECONDS, NOT MILLISECONDSMethods 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
-
waitTimer
public static final double waitTimervariable that represent the standard timer of the app for advancing the state of the game- See Also:
-
fastTimer
public static final double fastTimervariable that represent the fast timer of the app for small waiting task- See Also:
-
passTimer
public static final double passTimervariable that represent the timer for the new turn (changing) interaction- See Also:
-
showTimer
public static final double showTimervariable that represent the standard timer of the app for showing events- See Also:
-
showErrors
public static boolean showErrorsvariable that represent if we want to run or debug our application
-
-
Constructor Details
-
Game
normal constructor for this type of object, this class is also the main process on the server- Parameters:
maxP
- the number of players for this game, chosen before by the userold
- contains yes/no, used to determine if the player wants to load and older game- Throws:
RemoteException
-
-
Method Details
-
advanceTurn
public void advanceTurn()Set the status of the players for the next turn and assign activePlayer to who will play this turn -
sendChatToClients
Send message in the chat to other client- Parameters:
from
- who send the messageto
- who receive the messagemsg
- text inside the message
-
getInStreams
getter for the input streams from the server to all the clients- Returns:
- the ArrayList containing all the input streams
-
getNames
getter for the list of names of the players active in this game- Returns:
- the ArrayList containing all the names of the connected players
-
waitForSeconds
public static void waitForSeconds(double n) shortcut for the Thread.sleep(int) function, it accepts SECONDS, NOT MILLISECONDS- Parameters:
n
- the (decimal) number of seconds to wait
-
connectionLost
function that handle the eventual disconnection- Parameters:
e
- the exception to throw
-
playerDisconnected
method which acknowledge that one of the client disconnected and set the game to continue without the lost client- Parameters:
i
- the index of the lost client
-
sendToClient
general method to respond to a client, it chooses the right network connection of the player- Parameters:
i
- the index of the player to contactmsg
- the message that must be sent
-
addClient
method called from remote used to add a client to the store of all the RMI clients -
redirectToClientRMI
method called from remote which is equivalent to the waitMoveFromClient() method for the socket- Specified by:
redirectToClientRMI
in interfaceGameI
- Parameters:
msg
- the message that the client want to send to the remote server
-
ping
public void ping()method that allow the server to be pinged from an RMI client -
pingRMI
public void pingRMI()method that periodically pings all the current client connected with RMI
-