Class VersusModel


  • public class VersusModel
    extends java.lang.Object
    • Field Detail

      • height

        public int height
      • width

        public int width
      • baseSpeed

        public int baseSpeed
      • fallSpeedPlayerA

        public int fallSpeedPlayerA
      • fallSpeedPlayerB

        public int fallSpeedPlayerB
      • pieceListPlayerA

        java.util.ArrayList<java.lang.Object> pieceListPlayerA
      • pieceListPlayerB

        java.util.ArrayList<java.lang.Object> pieceListPlayerB
      • effectListPlayerA

        public java.util.ArrayList<EffectModel> effectListPlayerA
      • effectListPlayerB

        public java.util.ArrayList<EffectModel> effectListPlayerB
      • fallingPiecePlayerA

        public PieceModel fallingPiecePlayerA
      • fallingPiecePlayerB

        public PieceModel fallingPiecePlayerB
      • nextPiecePlayerA

        public PieceModel nextPiecePlayerA
      • nextPiecePlayerB

        public PieceModel nextPiecePlayerB
      • hideNextPieceA

        public boolean hideNextPieceA
      • hideNextPieceB

        public boolean hideNextPieceB
      • bestScore

        public int bestScore
      • currentScorePlayerA

        public int currentScorePlayerA
      • currentScorePlayerB

        public int currentScorePlayerB
      • nextEffectPlayerA

        public int nextEffectPlayerA
      • nextEffectPlayerB

        public int nextEffectPlayerB
      • effectStep

        public int effectStep
      • winner

        public java.lang.String winner
      • rand

        java.util.Random rand
    • Constructor Detail

      • VersusModel

        public VersusModel()
    • Method Detail

      • setCtrl

        public void setCtrl​(VersusController ctrl)
        Sets the current controller
        Parameters:
        ctrl - an instance of VersusController
      • 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 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​(int player,
                                               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,
                                                     int player)
        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,
                                       int player)
        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,
                                   int player)
        Calculate the current score based of the point multiplier of the LineCompleted parameter
        Parameters:
        lc - what multiplier should we use
      • checkEffect

        private void checkEffect()