Class GameMode

java.lang.Object
sac.model.gamemodes.GameMode
All Implemented Interfaces:
GameCore, GameLayer

public class GameMode extends Object implements GameCore, GameLayer
Define a game mode. This mode can be customized by replacing its game core or adding game layers. In particular, a game mode can be used as a game core or game layer set to another game mode.
  • Constructor Details

    • GameMode

      public GameMode(GameCore core, GameLayer layer)
      Set the game core and Add the layer.
      Parameters:
      core - - the game core to be used
      layer - - the layer to be added
    • GameMode

      public GameMode(GameCore core, Stack<GameLayer> layers)
      Set the game core and the layers.
      Parameters:
      core - - the game core to be used
      layers - - the layer stack to be used
  • Method Details

    • getPieceGenerator

      public Generator getPieceGenerator()
      Specified by:
      getPieceGenerator in interface GameCore
      Returns:
      the pieceGenerator this game would use
    • getRotationSystem

      public RotationSystem getRotationSystem()
      Specified by:
      getRotationSystem in interface GameCore
      Returns:
      the rotationSystem this game would use
    • getSpawnPosition

      public Point getSpawnPosition(Piece piece)
      Description copied from interface: GameCore
      Compute the spawn position of a piece in terms of its left bottom corner.
      Specified by:
      getSpawnPosition in interface GameCore
      Parameters:
      piece - - current piece spawned
      Returns:
      the spawn position
    • getWidth

      public int getWidth()
      Specified by:
      getWidth in interface GameCore
      Returns:
      width of the board
    • getHeight

      public int getHeight()
      Specified by:
      getHeight in interface GameCore
      Returns:
      height of the board (buffer included)
    • getBuffer

      public int getBuffer()
      Specified by:
      getBuffer in interface GameCore
      Returns:
      height of the buffer zone of the board
    • onGameStart

      public final void onGameStart()
      Template method. Initialize every game layer maintained by this game mode when game starts. Subclass should not override this method.
      Specified by:
      onGameStart in interface GameLayer
    • isGameEnd

      public final boolean isGameEnd()
      Template method. Check if the game-over condition of every game layer is met. Subclass should not override this method.
      Specified by:
      isGameEnd in interface GameLayer
      Returns:
      true if the game-over condition of at least one of the game layer is met
    • notifyAllObservers

      public final void notifyAllObservers(DataPackage dataPackage)
      Template method. Delegate the notifying task to game layers. Subclass should not override this method.
      Specified by:
      notifyAllObservers in interface GameLayer
      Parameters:
      dataPackage - - relavent data received from game
    • getCore

      public GameCore getCore()
      Returns:
      the game core this game mode is using
    • setCore

      public void setCore(GameCore core)
      Set the game core of this game mode.
      Parameters:
      core -
    • addLayer

      public void addLayer(GameLayer layer)
      Add a layer into this game mode.
      Parameters:
      layer - - the layer to be added
    • removeLayer

      public boolean removeLayer(GameLayer layer)
      Remove layer from this game mode.
      Parameters:
      layer - - the layer to be removed
      Returns:
      true iff the removal is successful