Module AM37

Class ServerController

java.lang.Object
it.polimi.ingsw.controller.ServerController
All Implemented Interfaces:
AddWorkerListener, BuildableCellsListener, BuildActionListener, BuildingBlocksListener, EndTurnListener, MoveActionListener, PlayerLostListener, SelectWorkerListener, WalkableCellsListener

public class ServerController
extends java.lang.Object
implements AddWorkerListener, BuildableCellsListener, BuildActionListener, BuildingBlocksListener, EndTurnListener, MoveActionListener, WalkableCellsListener, PlayerLostListener, SelectWorkerListener
Actual game controller

class is responsible for changes in the game state: it

  • makes actions to alter the game (model), based on the users' inputs received in the parser
  • notifies the clients about the changes, propagated from the model using listeners
  • Constructor Summary

    Constructors 
    Constructor Description
    ServerController​(GameInterface game, java.util.Map<User,​PlayerInterface> players, MessageManagerParser parser, java.io.File gameToSave)
    Default constructor
  • Method Summary

    Modifier and Type Method Description
    void addWorker​(java.lang.String username, Cell cell)
    Adds a worker for the player
    void handleBuildAction​(java.lang.String username, BuildAction buildAction)
    Handles a build action
    void handleGameRestore()
    Resumes a previously saved game state
    void handleMoveAction​(java.lang.String username, MoveAction moveAction)
    Handles a movement action
    void obtainBuildableCells​(java.lang.String username)
    Provides the cells on which the player's selected worker can build on
    void obtainWalkableCells​(java.lang.String username)
    Provides the cells on which the player's selected worker can move to
    void onBlocksObtained​(java.lang.String name, java.util.List<Block> blocks)
    Notifies a single user about the possible blocks its selected worker can build, if there's more than one
    void onBuildableCell​(java.lang.String name, java.util.List<Cell> cells)
    Notifies a single user about the possible cells on which its selected worker can build on
    void onBuildAction​(java.util.List<Cell> cells)
    Notifies all users about a successful build action
    Saves the current game state
    void onMoveAction​(java.util.List<Cell> cells)
    Notifies all users about a successful movement action
    Saves the current game state
    void onPlayerLoss​(java.lang.String username, java.util.List<Cell> gameBoard)
    Notifies all users that a player lost
    void onSelectedWorker​(java.lang.String username, java.util.List<PossibleActions> possibleActions, Worker selectedWorker)
    Notifies a single user that its worker choice was correct
    Saves the current game state
    void onTurnEnd​(java.lang.String name, java.util.List<Cell> workersCells)
    Notifies all users about the end of the current turn and the next player who has to play
    Saves the current state
    void onWalkableCells​(java.lang.String name, java.util.List<Cell> cells)
    Notifies a single user about the possible cells on which its selected worker can walk to
    void onWorkerAdd​(java.util.List<Cell> cells)
    Notifies all users about a successful worker placement
    void passTurn​(java.lang.String username)
    Handles a turn end request
    void saveState()
    Saves the current state of the game to a file
    void selectBuildingCell​(java.lang.String username, Cell selectedCell)
    Provides the possible blocks which the current player's worker can build
    void selectWorker​(java.lang.String username, Worker worker)
    Sets a player's selected worker for the following actions to be performed
    void setFile​(java.io.File file)
    Sets the file to save the game to and saves the current state to it

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait