Class GUISocketListener

java.lang.Object
it.polimi.ingsw.Client.GUI.Listeners.GUISocketListener
All Implemented Interfaces:
Runnable

public class GUISocketListener extends Object implements Runnable
Handles messages received from server and keep a record of current player's actions executed during its turn
  • Field Details

    • requestAndFeedback

      private final List<Pair<PlayerAction,PlayerActionFeedback>> requestAndFeedback
      List of actions executed by current player and their feedbacks
    • ctx

      private final Context ctx
      Context received from GameInProgressPanel
    • sw

      private final SocketWrapper sw
      SocketWrapper used to communicate with Server
    • gameInProgressPanel

      private GameInProgressPanel gameInProgressPanel
      JTabbedPane containing all others JPanels
    • playerActionRequest

      private PlayerAction playerActionRequest
      Last player's request sent to Server
  • Constructor Details

    • GUISocketListener

      public GUISocketListener(Context ctx)
      Create a new GUIReader
      Parameters:
      ctx - Context containing socket and GUI's window
  • Method Details

    • run

      public void run()
      Listen for Server's responses and updated window basing on responses
      Specified by:
      run in interface Runnable
    • savePlayerActionRequest

      public void savePlayerActionRequest(PlayerAction playerActionRequest)
      Save user's request that will be added in history after receiving its feedback
      Parameters:
      playerActionRequest - playerActionRequest to save
    • awaitingPlayerActionFeedback

      public boolean awaitingPlayerActionFeedback()
      Check to see if a new PlayerActionRequest can be sent to the server or if the gui should wait before allowing any more actions to be sent
      Returns:
      true if the listener is polling for a feedback to a previous player's action, false otherwise
    • getSuccessfulRequestsByType

      public int getSuccessfulRequestsByType(Class<?> playerActionClass)
      Count PlayerActions that have received a successful response from Server
      Parameters:
      playerActionClass - PlayerAction's class that will be counted
      Returns:
      PlayerAction amount that received a successful response from Server