Package fr.iut.tetris.models
Class SoloModel
- java.lang.Object
-
- fr.iut.tetris.models.SoloModel
-
public class SoloModel extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description (package private) int
baseSpeed
int
bestScore
(package private) SoloController
ctrl
int
currentScore
PieceModel
fallingPiece
int
fallSpeed
GameState
gameState
int
height
PieceModel
nextPiece
(package private) java.util.ArrayList<java.lang.Object>
pieceList
(package private) java.util.Random
rand
int
width
-
Constructor Summary
Constructors Constructor Description SoloModel()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
calculateScore(LineCompleted lc)
Calculate the current score based of the point multiplier of the LineCompleted parameter(package private) java.lang.Object
checkForFullLineAndRemoveIt(boolean firstCall)
A recursive function that check for line that are completed and falls down every line over it then recursively calls itself with the parm `firstCall` at true which make the function return an integer instead of a LineCompletedBlockModel[][]
computeMixedGrid(boolean render_dropped_piece)
This is the function that the game is based on throws an error if the board is impossible if else return the grid for the vue(package private) void
convertFullPiecesToBlocks(PieceModel piece)
When a piece has fallen down to it's maximum it needs to be converted to individual blocks so that we can adjust individuals Y's of blocks instead of moving the whole piece (useful when a piece is cut in the middle for example)void
fallCurrent()
Fall the current piece down by one.void
fallCurrentAtBottom()
Execute fallCurrent() until the `fallingPiece` is no more(package private) static java.lang.Object
getRandomElement(java.lang.Object[] list, java.util.Random rand)
Fetch a random element from a listPieceModel
getRandomPiece()
Return a random pieces from PieceModel.Piecesboolean
moveCurrentX(Direction dir)
Move the current piece in the X axis also send a "GAME:FAILED_ACTION" event to the controller if the movement is impossibleboolean
rotateCurrent(Direction dir)
Rotate the current piece also send a "GAME:FAILED_ACTION" event to the controller if the rotation is impossiblevoid
setCtrl(SoloController ctrl)
Sets the current controllervoid
spawnPiece()
Spawn a new piece for the player.
-
-
-
Field Detail
-
height
public int height
-
width
public int width
-
baseSpeed
int baseSpeed
-
fallSpeed
public int fallSpeed
-
pieceList
java.util.ArrayList<java.lang.Object> pieceList
-
fallingPiece
public PieceModel fallingPiece
-
nextPiece
public PieceModel nextPiece
-
gameState
public GameState gameState
-
ctrl
SoloController ctrl
-
bestScore
public int bestScore
-
currentScore
public int currentScore
-
rand
java.util.Random rand
-
-
Method Detail
-
setCtrl
public void setCtrl(SoloController ctrl)
Sets the current controller- Parameters:
ctrl
- an instance of SoloController
-
getRandomElement
static java.lang.Object getRandomElement(java.lang.Object[] list, java.util.Random rand)
Fetch a random element from a list- Parameters:
list
- the list of objectsrand
- the Random class- Returns:
- a random object
-
getRandomPiece
public PieceModel getRandomPiece()
Return a random pieces from PieceModel.Pieces- Returns:
- a PieceModel
-
spawnPiece
public void spawnPiece()
Spawn a new piece for the player. Transfer the `nextPiece` to `fallingPiece` and generate a new piece for `nextPiece`
-
computeMixedGrid
public BlockModel[][] computeMixedGrid(boolean render_dropped_piece) throws OverlappedPieceException, PieceOutOfBoardException
This is the function that the game is based on throws an error if the board is impossible if else return the grid for the vue- Parameters:
render_dropped_piece
- should be false is the function isn't used by the ui- Returns:
- an arrays of the game size that contains BlockModels for the vue to display
- Throws:
OverlappedPieceException
- in case a piece collide with an other onePieceOutOfBoardException
- if a piece has a position outside of the board
-
checkForFullLineAndRemoveIt
java.lang.Object checkForFullLineAndRemoveIt(boolean firstCall)
A recursive function that check for line that are completed and falls down every line over it then recursively calls itself with the parm `firstCall` at true which make the function return an integer instead of a LineCompleted- Parameters:
firstCall
- In the program should be set to false only used by the function for the socre multiplier calculation- Returns:
- When use in the program return LineCompleted if not it return an Integer of the umber of line removed
-
convertFullPiecesToBlocks
void convertFullPiecesToBlocks(PieceModel piece)
When a piece has fallen down to it's maximum it needs to be converted to individual blocks so that we can adjust individuals Y's of blocks instead of moving the whole piece (useful when a piece is cut in the middle for example)- Parameters:
piece
- the piece to transform
-
moveCurrentX
public boolean moveCurrentX(Direction dir)
Move the current piece in the X axis also send a "GAME:FAILED_ACTION" event to the controller if the movement is impossible- Parameters:
dir
- the direction- Returns:
- if the movment was successful
-
rotateCurrent
public boolean rotateCurrent(Direction dir)
Rotate the current piece also send a "GAME:FAILED_ACTION" event to the controller if the rotation is impossible- Parameters:
dir
- the direction of the rotation- Returns:
- if the rotation was successful
-
fallCurrent
public void fallCurrent()
Fall the current piece down by one. Also test if the fall is possible if else the piece get converted to blocks and we check for a full line, we send a event to the controller for sound effects and we calculate the score
-
fallCurrentAtBottom
public void fallCurrentAtBottom()
Execute fallCurrent() until the `fallingPiece` is no more
-
calculateScore
public void calculateScore(LineCompleted lc)
Calculate the current score based of the point multiplier of the LineCompleted parameter- Parameters:
lc
- what multiplier should we use
-
-