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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a layer into this game mode.intgetCore()intgetSpawnPosition(Piece piece) Compute the spawn position of a piece in terms of its left bottom corner.intgetWidth()final booleanTemplate method.final voidnotifyAllObservers(DataPackage dataPackage) Template method.final voidTemplate method.booleanremoveLayer(GameLayer layer) Remove layer from this game mode.voidSet 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:
getPieceGeneratorin interfaceGameCore- Returns:
- the pieceGenerator this game would use
-
getRotationSystem
- Specified by:
getRotationSystemin interfaceGameCore- Returns:
- the rotationSystem this game would use
-
getSpawnPosition
Description copied from interface:GameCoreCompute the spawn position of a piece in terms of its left bottom corner.- Specified by:
getSpawnPositionin 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:
onGameStartin 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:
notifyAllObserversin 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
-