fr.enssat.BoulderDash.models

## Class LevelModel

- java.lang.Object
- - java.util.Observable
  - - fr.enssat.BoulderDash.models.LevelModel

All Implemented Interfaces:
  java.lang.Runnable

    public class LevelModel
    extends java.util.Observable
    implements java.lang.Runnable

LevelModel Levels are loaded from XML file. The view knows the model, the controller is going to modify the model in function of the game panel. The model notifies the view when there are changes on it.

Since:
  2015-06-19
Author:
  Colin Leverger <me@colinleverger.fr>

### Constructor Summary

Constructors
Constructor and Description
`LevelModel(AudioLoadHelper audioLoadHelper)` Class constructor (editor mode)
`LevelModel(java.lang.String levelName, AudioLoadHelper audioLoadHelper)` Class constructor
`LevelModel(java.lang.String levelName, AudioLoadHelper audioLoadHelper, java.lang.String mode)` Class constructor

### Method Summary

Methods
`void` `checkConstraints()` Returns whether constraints on model are respected or not
`int` `countDiamonds()` Returns number of diamonds
`int` `decrementCursorXPosition()` Decrements the cursor position X value
`int` `decrementCursorYPosition()` Decrements the cursor position Y value
`void` `deleteThisBoulder(int x, int y)` Deletes the BoulderModel[x][y]
`void` `expandThisWallToLeft(int x, int y)` Expand the ExpandingWallModel to left
`void` `expandThisWallToRight(int x, int y)` Expand the ExpandingWallModel to right
`void` `exploseGround(int x, int y)` When a boulder is falling on Rockford there is an explosion around him
`void` `exploseThisBrickWall(int x, int y)` Explose the brick wall
`java.awt.image.BufferedImage` `getCursorImage()` Gets the cursor image image
`int` `getCursorXPosition()` Gets the cursor position X value
`int` `getCursorYPosition()` Gets the cursor position Y value
`DisplayableElementModel` `getDisplayableElement(int x, int y)` Gets the displayable element at given positions
`GameInformationModel` `getGameInformationModel()` Gets gameInformationModel
`boolean` `getGamePaused()` Get the gamePaused variable
`DisplayableElementModel[][]` `getGroundLevelModel()` Gets the ground level model
`java.awt.image.BufferedImage` `getImage(int x, int y)` Gets the image at given positions
`LevelLoadHelper` `getLevelLoadHelper()` Gets the associated level load helper
`java.lang.String` `getMode()` Get the mode where this levelModel is used
`RockfordModel` `getRockford()` Gets the Rockford object instance
`int` `getRockfordPositionX()` Gets the horizontal position of Rockford from the model
`int` `getRockfordPositionY()` Gets the vertical position of Rockford from the model
`boolean` `getShowCursor()` Gets whether cursor is to be shown or not
`int` `getSizeHeight()` Gets the level vertical size
`int` `getSizeWidth()` Gets the level horizontal size
`int` `incrementCursorXPosition()` Increaments the cursor position X value
`int` `incrementCursorYPosition()` Increaments the cursor position Y value
`void` `incrementScore()` Increments the user score
`boolean` `isGameRunning()` tells if the game is running
`boolean` `isRockfordInModel()` Return whether rockford is in model or not Notice: not optimized, be careful
`void` `makeThisBoulderSlideLeft(int x, int y)` Makes the BoulderModel[x][y] slide left
`void` `makeThisBoulderSlideRight(int x, int y)` Makes the BoulderModel[x][y] slide right
`void` `makeThisDisplayableElementFall(int x, int y)` Makes the DisplayableElement[x][y] fall one box down
`void` `moveThisBoulderToLeft(int x, int y)` Makes the BoulderModel[x][y] moving to left
`void` `moveThisBoulderToRight(int x, int y)` Makes the BoulderModel[x][y] moving to right
`void` `resetLevelModel()`
`void` `run()` Update all the sprites So that they can be animated
`void` `setGamePaused(boolean gamePaused)` Set the gamePaused variable
`void` `setGameRunning(boolean gameRunning)` sets the game to a defined state
`void` `setMode(java.lang.String mode)` Set the mode where this levelModel is used
`void` `setPositionOfRockford(int posX, int posY)` Sets the new Rockford position
`void` `setShowCursor(boolean showCursor)` Sets whether cursor is to be shown or not
`void` `setSizeHeight(int sizeHeight)` Sets the level vertical size
`void` `setSizeWidth(int sizeWidth)` Sets the level horizontal size
`void` `transformThisBoulderIntoADiamond(int x, int y)` Makes the BoulderModel[x][y] transform into a diamond
`void` `triggerBlockChange(java.lang.String blockValue)` Trigger block change with provided value
`void` `updateRockfordPosition(int posX, int posY)` Updates the horizontal & vertical positions of Rockford in the model
`void` `updateSprites(int x, int y)` Update the current sprite Notifies the observers

### Methods inherited from class java.util.Observable

`addObserver, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers`

### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### LevelModel

    public LevelModel(java.lang.String levelName,
              AudioLoadHelper audioLoadHelper,
              java.lang.String mode)

Class constructor

Parameters:
  `levelName` - Level name
  `audioLoadHelper` - Audio load helper
  `mode` - Instance mode

#### LevelModel

    public LevelModel(java.lang.String levelName,
              AudioLoadHelper audioLoadHelper)

Class constructor

Parameters:
  `levelName` - Level name
  `audioLoadHelper` - Audio load helper

#### LevelModel

    public LevelModel(AudioLoadHelper audioLoadHelper)

Class constructor (editor mode)

Parameters:
  `audioLoadHelper` - Audio load helper

### Method Detail

#### resetLevelModel

    public void resetLevelModel()

#### updateRockfordPosition

    public void updateRockfordPosition(int posX,
                              int posY)

Updates the horizontal & vertical positions of Rockford in the model

Parameters:
  `posX` - Horizontal position of Rockford
  `posY` - Vertical position of Rockford

#### getRockfordPositionX

    public int getRockfordPositionX()

Gets the horizontal position of Rockford from the model

Returns:
  Horizontal position of Rockford

#### setPositionOfRockford

    public void setPositionOfRockford(int posX,
                             int posY)

Sets the new Rockford position

Parameters:
  `posX` - Next horizontal position on the grid
  `posY` - Next vertical position on the grid

#### triggerBlockChange

    public void triggerBlockChange(java.lang.String blockValue)

Trigger block change with provided value

Parameters:
  `blockValue` - New value

#### getRockfordPositionY

    public int getRockfordPositionY()

Gets the vertical position of Rockford from the model

Returns:
  Vertical position of Rockford

#### getRockford

    public RockfordModel getRockford()

Gets the Rockford object instance

Returns:
  Rockford object

#### getDisplayableElement

    public DisplayableElementModel getDisplayableElement(int x,
                                                int y)

Gets the displayable element at given positions

Parameters:
  `x` - Block horizontal position
  `y` - Block vertical position
Returns:
  Displayable element at given positions

#### getImage

    public java.awt.image.BufferedImage getImage(int x,
                                        int y)

Gets the image at given positions

Parameters:
  `x` - Block horizontal position
  `y` - Block vertical position
Returns:
  Image at given positions

#### getCursorImage

    public java.awt.image.BufferedImage getCursorImage()

Gets the cursor image image

Returns:
  Cursor image

#### isRockfordInModel

    public boolean isRockfordInModel()

Return whether rockford is in model or not Notice: not optimized, be careful

Returns:
  Whether rockford is in model or not

#### countDiamonds

    public int countDiamonds()

Returns number of diamonds

Returns:
  Number of diamonds

#### checkConstraints

    public void checkConstraints()
                          throws LevelConstraintNotRespectedException

Returns whether constraints on model are respected or not

Throws:
  `LevelConstraintNotRespectedException`

#### getSizeWidth

    public int getSizeWidth()

Gets the level horizontal size

Returns:
  Horizontal size

#### setSizeWidth

    public void setSizeWidth(int sizeWidth)

Sets the level horizontal size

Parameters:
  `sizeWidth` - Horizontal size

#### getSizeHeight

    public int getSizeHeight()

Gets the level vertical size

Returns:
  Vertical size

#### setSizeHeight

    public void setSizeHeight(int sizeHeight)

Sets the level vertical size

#### getGroundLevelModel

    public DisplayableElementModel[][] getGroundLevelModel()

Gets the ground level model

Returns:
  Ground level model

#### updateSprites

    public void updateSprites(int x,
                     int y)

Update the current sprite Notifies the observers

Parameters:
  `x` - Sprite block horizontal position
  `y` - Sprite block vertical position

#### run

    public void run()

Update all the sprites So that they can be animated

Specified by:
  `run` in interface `java.lang.Runnable`

#### incrementScore

    public void incrementScore()

Increments the user score

#### getLevelLoadHelper

    public LevelLoadHelper getLevelLoadHelper()

Gets the associated level load helper

Returns:
  Level load helper

#### getCursorXPosition

    public int getCursorXPosition()

Gets the cursor position X value

Returns:
  Cursor position X value

#### getCursorYPosition

    public int getCursorYPosition()

Gets the cursor position Y value

Returns:
  Cursor position Y value

#### incrementCursorXPosition

    public int incrementCursorXPosition()

Increaments the cursor position X value

Returns:
  Cursor position new X value

#### decrementCursorXPosition

    public int decrementCursorXPosition()

Decrements the cursor position X value

Returns:
  Cursor position new X value

#### incrementCursorYPosition

    public int incrementCursorYPosition()

Increaments the cursor position Y value

Returns:
  Cursor position new Y value

#### decrementCursorYPosition

    public int decrementCursorYPosition()

Decrements the cursor position Y value

Returns:
  Cursor position new Y value

#### setGameRunning

    public void setGameRunning(boolean gameRunning)

sets the game to a defined state

Parameters:
  `gameRunning` - Whether game is running or not

#### isGameRunning

    public boolean isGameRunning()

tells if the game is running

Returns:
  whether the game is running or not

#### getShowCursor

    public boolean getShowCursor()

Gets whether cursor is to be shown or not

Returns:
  whether cursor needs to be shown or not

#### setShowCursor

    public void setShowCursor(boolean showCursor)

Sets whether cursor is to be shown or not

Parameters:
  `showCursor` - whether cursor needs to be shown or not

#### exploseGround

    public void exploseGround(int x,
                     int y)

When a boulder is falling on Rockford there is an explosion around him

Parameters:
  `x` - Object horizontal position
  `y` - Object vertical position

#### makeThisDisplayableElementFall

    public void makeThisDisplayableElementFall(int x,
                                      int y)

Makes the DisplayableElement[x][y] fall one box down

Parameters:
  `x` - Object horizontal position
  `y` - Object vertical position

#### makeThisBoulderSlideLeft

    public void makeThisBoulderSlideLeft(int x,
                                int y)

Makes the BoulderModel[x][y] slide left

Parameters:
  `x` - Object horizontal position
  `y` - Object vertical position

#### makeThisBoulderSlideRight

    public void makeThisBoulderSlideRight(int x,
                                 int y)

Makes the BoulderModel[x][y] slide right

Parameters:
  `x` - Object horizontal position
  `y` - Object vertical position

#### transformThisBoulderIntoADiamond

    public void transformThisBoulderIntoADiamond(int x,
                                        int y)

Makes the BoulderModel[x][y] transform into a diamond

Parameters:
  `x` - Object horizontal position
  `y` - Object vertical position

#### moveThisBoulderToRight

    public void moveThisBoulderToRight(int x,
                              int y)

Makes the BoulderModel[x][y] moving to right

Parameters:
  `x` - Object horizontal position
  `y` - Object vertical position

#### moveThisBoulderToLeft

    public void moveThisBoulderToLeft(int x,
                             int y)

Makes the BoulderModel[x][y] moving to left

Parameters:
  `x` - Object horizontal position
  `y` - Object vertical position

#### deleteThisBoulder

    public void deleteThisBoulder(int x,
                         int y)

Deletes the BoulderModel[x][y]

Parameters:
  `x` - Object horizontal position
  `y` - Object vertical position

#### getGameInformationModel

    public GameInformationModel getGameInformationModel()

Gets gameInformationModel

Returns:
  gameInfos like score, remainings Diamonds etc

#### exploseThisBrickWall

    public void exploseThisBrickWall(int x,
                            int y)

Explose the brick wall

Parameters:
  `x` -
  `y` -

#### expandThisWallToLeft

    public void expandThisWallToLeft(int x,
                            int y)

Expand the ExpandingWallModel to left

Parameters:
  `x` -
  `y` -

#### expandThisWallToRight

    public void expandThisWallToRight(int x,
                             int y)

Expand the ExpandingWallModel to right

Parameters:
  `x` -
  `y` -

#### setGamePaused

    public void setGamePaused(boolean gamePaused)

Set the gamePaused variable

Parameters:
  `gamePaused` -

#### getGamePaused

    public boolean getGamePaused()

Get the gamePaused variable

Returns:
  gamePaused

#### getMode

    public java.lang.String getMode()

Get the mode where this levelModel is used

Returns:
  mode

#### setMode

    public void setMode(java.lang.String mode)

Set the mode where this levelModel is used

Parameters:
  `mode` -