Package fr.iut.tetris.models
Class CoopModel
- java.lang.Object
-
- fr.iut.tetris.models.CoopModel
-
public class CoopModel extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description (package private) int
baseSpeed
int
bestScore
(package private) CoopController
ctrl
int
currentScore
PieceModel
fallingPiecePlayerA
PieceModel
fallingPiecePlayerB
int
fallSpeed
GameState
gameState
int
height
PieceModel
nextPiecePlayerA
PieceModel
nextPiecePlayerB
(package private) java.util.ArrayList<java.lang.Object>
pieceList
(package private) java.util.Random
rand
int
width
-
Constructor Summary
Constructors Constructor Description CoopModel()
-
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
fallCurrentAtBottomForPlayerA()
Execute fallCurrentForPlayerA() until the `fallingPiecePlayerA` is no morevoid
fallCurrentAtBottomForPlayerB()
Execute fallCurrentForPlayerB() until the `fallingPiecePlayerB` is no morevoid
fallCurrentForPlayerA()
Fall the current piece down by one for the player A.void
fallCurrentForPlayerB()
Fall the current piece down by one for the player B.(package private) static java.lang.Object
getRandomElement(java.lang.Object[] list, java.util.Random rand)
Fetch a random element from a listPieceModel
getRandomPiece(int player)
Return a random pieces from PieceModel.Pieces and colors it according to which playerboolean
moveCurrentX(int player, Direction dir)
Move the current piece for the correct player in the X axis also send a "GAME:FAILED_ACTION" event to the controller if the movement is impossibleboolean
rotateCurrent(int player, Direction dir)
Rotate the current piece for the correct player also send a "GAME:FAILED_ACTION" event to the controller if the rotation is impossiblevoid
setCtrl(CoopController ctrl)
Sets the current controllervoid
spawnPlayerAPiece()
Spawn a new piece for the 1st player.void
spawnPlayerBPiece()
Spawn a new piece for the 2nd 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
-
gameState
public GameState gameState
-
fallingPiecePlayerA
public PieceModel fallingPiecePlayerA
-
fallingPiecePlayerB
public PieceModel fallingPiecePlayerB
-
nextPiecePlayerA
public PieceModel nextPiecePlayerA
-
nextPiecePlayerB
public PieceModel nextPiecePlayerB
-
ctrl
CoopController ctrl
-
bestScore
public int bestScore
-
currentScore
public int currentScore
-
rand
java.util.Random rand
-
-
Method Detail
-
setCtrl
public void setCtrl(CoopController ctrl)
Sets the current controller- Parameters:
ctrl
- an instance of CoopController
-
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(int player)
Return a random pieces from PieceModel.Pieces and colors it according to which player- Returns:
- a PieceModel
-
spawnPlayerAPiece
public void spawnPlayerAPiece()
Spawn a new piece for the 1st player. Transfer the `nextPiecePlayerA` to `fallingPiecePlayerA` and generate a new piece for `nextPiecePlayerA`
-
spawnPlayerBPiece
public void spawnPlayerBPiece()
Spawn a new piece for the 2nd player. Transfer the `nextPiecePlayerB` to `fallingPiecePlayerB` and generate a new piece for `nextPiecePlayerB`
-
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(int player, Direction dir)
Move the current piece for the correct player 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(int player, Direction dir)
Rotate the current piece for the correct player 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
-
fallCurrentForPlayerA
public void fallCurrentForPlayerA()
Fall the current piece down by one for the player A. 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
-
fallCurrentForPlayerB
public void fallCurrentForPlayerB()
Fall the current piece down by one for the player B. 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
-
fallCurrentAtBottomForPlayerA
public void fallCurrentAtBottomForPlayerA()
Execute fallCurrentForPlayerA() until the `fallingPiecePlayerA` is no more
-
fallCurrentAtBottomForPlayerB
public void fallCurrentAtBottomForPlayerB()
Execute fallCurrentForPlayerB() until the `fallingPiecePlayerB` 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
-
-