Class Game

All Implemented Interfaces:
GameI, Serializable, Remote

public class Game extends UnicastRemoteObject implements Serializable, GameI
class which represent the instance of the current game
See Also:
  • Field Details

    • waitTimer

      public static final double waitTimer
      variable that represent the standard timer of the app for advancing the state of the game
      See Also:
    • fastTimer

      public static final double fastTimer
      variable that represent the fast timer of the app for small waiting task
      See Also:
    • passTimer

      public static final double passTimer
      variable that represent the timer for the new turn (changing) interaction
      See Also:
    • showTimer

      public static final double showTimer
      variable that represent the standard timer of the app for showing events
      See Also:
    • showErrors

      public static boolean showErrors
      variable that represent if we want to run or debug our application
  • Constructor Details

    • Game

      public Game(int maxP, String old) throws RemoteException
      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 user
      old - 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

      public void sendChatToClients(String from, String to, String msg)
      Send message in the chat to other client
      Parameters:
      from - who send the message
      to - who receive the message
      msg - text inside the message
    • getInStreams

      public ArrayList<ObjectInputStream> getInStreams()
      getter for the input streams from the server to all the clients
      Returns:
      the ArrayList containing all the input streams
    • getNames

      public ArrayList<String> 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

      public void connectionLost(Exception e)
      function that handle the eventual disconnection
      Parameters:
      e - the exception to throw
    • playerDisconnected

      public void playerDisconnected(int i, Exception exc)
      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

      public void sendToClient(int i, Message msg)
      general method to respond to a client, it chooses the right network connection of the player
      Parameters:
      i - the index of the player to contact
      msg - the message that must be sent
    • addClient

      public void addClient(String name, PlayerI p)
      method called from remote used to add a client to the store of all the RMI clients
      Specified by:
      addClient in interface GameI
      Parameters:
      name - the nickname of the player
      p - the player object, passed as the remote interface
    • redirectToClientRMI

      public void redirectToClientRMI(Message msg)
      method called from remote which is equivalent to the waitMoveFromClient() method for the socket
      Specified by:
      redirectToClientRMI in interface GameI
      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
      Specified by:
      ping in interface GameI
    • pingRMI

      public void pingRMI()
      method that periodically pings all the current client connected with RMI