Interface GameControls
- All Known Subinterfaces:
PropertyChangeEnabledGameControls
- All Known Implementing Classes:
TetrisGame
public interface GameControls
The controls for a Tetris game. A Tetris game consists of the following constructs:
- A game state as defined by the
GameStateenum. - A game "board" made up of width (w) by height (h) blocks.
- The data class
Pointis used to represent a location on the board. - The "bottom" row of the board is represented by
y = 0- Positive y moves "up" the board
- The "right" column of the board is represented by
x = 0- Positive x moves "right" across the board
- The data class
- A current movable piece that the user may manipulate.
- The data class
IndividualPieceis used to represent the current movable piece.
- The data class
- A set of frozen blocks that represent all Tetris
Blockobjects that have frozen into place.
- Version:
- Autumn 25
- Author:
- Charles Bryan
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enumThe different types of blocks that can be stored in a Board's grid.static final recordData class that represents all TetrisBlockobjects that have frozen into place.static enumSpecifies a game state for Tetris.static final recordData class that represents a single Tetris tetromino in a location on the Tetris board.static final recordData class that represents a "point" on the Tetris game board. -
Method Summary
Modifier and TypeMethodDescriptionvoiddown()Try to move the movable piece down.voiddrop()Drop the movable piece until it is set.voidendGame()Places the game inGameState.OVER.voidleft()Try to move the movable piece left.voidnewGame()Places the game inGameState.NEWfollowed by placing the game intoGameState.RUNNING.voidpause()Places the game intoGameState.PAUSED.voidright()Try to move the movable piece right.voidTry to rotate the movable piece in the counter-clockwise direction.voidrotateCW()Try to rotate the movable piece in the clockwise direction.voidstep()Advances the game by one 'step'.voidToggles the game into eitherGameState.RUNNINGorGameState.PAUSED.voidunPause()Places the game intoGameState.RUNNING.
-
Method Details
-
newGame
void newGame()Places the game inGameState.NEWfollowed by placing the game intoGameState.RUNNING. This method must be called before the first game and before each new game. No restriction on the current GameState is enforced. -
endGame
void endGame()Places the game inGameState.OVER. The game must be inGameState.PAUSEDorGameState.RUNNINGfor this action to have an effect. -
step
void step()Advances the game by one 'step'. The game must be inGameState.RUNNINGfor this action to have an effect.
This action could include:- moving the movable piece down 1 line
- freezing the movable piece if appropriate
(which may end the game placing it into
GameState.OVER) - clearing full lines as needed
-
down
void down()Try to move the movable piece down. The game must be inGameState.RUNNINGfor this action to have an effect.
This action could include:- freezing the movable piece if appropriate
(which may end the game placing it into
GameState.OVER) - clearing full lines as needed
- freezing the movable piece if appropriate
(which may end the game placing it into
-
left
void left()Try to move the movable piece left. The game must be inGameState.RUNNINGfor this action to have an effect. -
right
void right()Try to move the movable piece right. The game must be inGameState.RUNNINGfor this action to have an effect. -
rotateCW
void rotateCW()Try to rotate the movable piece in the clockwise direction. The game must be inGameState.RUNNINGfor this action to have an effect. -
rotateCCW
void rotateCCW()Try to rotate the movable piece in the counter-clockwise direction. The game must be inGameState.RUNNINGfor this action to have an effect. -
drop
void drop()Drop the movable piece until it is set. The game must be inGameState.RUNNINGfor this action to have an effect. This action will include:- freezing the movable piece
(which may end the game placing it into
GameState.OVER) - clearing full lines as needed
- freezing the movable piece
(which may end the game placing it into
-
pause
void pause()Places the game intoGameState.PAUSED. The game must be inGameState.RUNNINGfor this action to have an effect. -
unPause
void unPause()Places the game intoGameState.RUNNING. The game must be inGameState.PAUSEDfor this action to have an effect. -
togglePause
void togglePause()Toggles the game into eitherGameState.RUNNINGorGameState.PAUSED. More formally, if the game is inGameState.PAUSEDthis action places the game intoGameState.RUNNINGand if the game is inGameState.RUNNING, this action places the game inGameState.PAUSED. The game must be inGameState.PAUSEDorGameState.RUNNINGfor this action to have an effect.
-