Package sac.model.gamemodes
Class GameMode
java.lang.Object
sac.model.gamemodes.GameMode
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a layer into this game mode.int
getCore()
int
getSpawnPosition
(Piece piece) Compute the spawn position of a piece in terms of its left bottom corner.int
getWidth()
final boolean
Template method.final void
notifyAllObservers
(DataPackage dataPackage) Template method.final void
Template method.boolean
removeLayer
(GameLayer layer) Remove layer from this game mode.void
Set the game core of this game mode.
-
Constructor Details
-
GameMode
Set the game core and Add the layer.- Parameters:
core
- - the game core to be usedlayer
- - the layer to be added
-
GameMode
Set the game core and the layers.- Parameters:
core
- - the game core to be usedlayers
- - the layer stack to be used
-
-
Method Details
-
getPieceGenerator
- Specified by:
getPieceGenerator
in interfaceGameCore
- Returns:
- the pieceGenerator this game would use
-
getRotationSystem
- Specified by:
getRotationSystem
in interfaceGameCore
- Returns:
- the rotationSystem this game would use
-
getSpawnPosition
Description copied from interface:GameCore
Compute the spawn position of a piece in terms of its left bottom corner.- Specified by:
getSpawnPosition
in interfaceGameCore
- Parameters:
piece
- - current piece spawned- Returns:
- the spawn position
-
getWidth
public int getWidth() -
getHeight
public int getHeight() -
getBuffer
public int getBuffer() -
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 interfaceGameLayer
-
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. -
notifyAllObservers
Template method. Delegate the notifying task to game layers. Subclass should not override this method.- Specified by:
notifyAllObservers
in interfaceGameLayer
- Parameters:
dataPackage
- - relavent data received from game
-
getCore
- Returns:
- the game core this game mode is using
-
setCore
Set the game core of this game mode.- Parameters:
core
-
-
addLayer
Add a layer into this game mode.- Parameters:
layer
- - the layer to be added
-
removeLayer
Remove layer from this game mode.- Parameters:
layer
- - the layer to be removed- Returns:
- true iff the removal is successful
-