Class SoloModel


  • public class SoloModel
    extends java.lang.Object
    • 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 LineCompleted
      BlockModel[][] 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 list
      PieceModel getRandomPiece()
      Return a random pieces from PieceModel.Pieces
      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
      boolean rotateCurrent​(Direction dir)
      Rotate the current piece also send a "GAME:FAILED_ACTION" event to the controller if the rotation is impossible
      void setCtrl​(SoloController ctrl)
      Sets the current controller
      void spawnPiece()
      Spawn a new piece for the player.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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
      • bestScore

        public int bestScore
      • currentScore

        public int currentScore
      • rand

        java.util.Random rand
    • Constructor Detail

      • SoloModel

        public SoloModel()
    • 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 objects
        rand - 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 one
        PieceOutOfBoardException - 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