LevelModel fixed too many fields PMD violation

This commit is contained in:
0nlineSam 2024-11-02 14:33:45 +01:00
parent ff13dca39e
commit 26e9854fb2
2 changed files with 24 additions and 24 deletions

3
.idea/misc.xml generated
View File

@ -1,5 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="PDMPlugin">
<option name="skipTestSources" value="false" />
</component>
<component name="PWA"> <component name="PWA">
<option name="enabled" value="true" /> <option name="enabled" value="true" />
<option name="wasEnabledAtLeastOnce" value="true" /> <option name="wasEnabledAtLeastOnce" value="true" />

View File

@ -16,6 +16,7 @@ import fr.enssat.BoulderDash.models.DirtModel;
import fr.enssat.BoulderDash.models.ExpandingWallModel; import fr.enssat.BoulderDash.models.ExpandingWallModel;
import fr.enssat.BoulderDash.models.CursorModel; import fr.enssat.BoulderDash.models.CursorModel;
import java.awt.*;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.util.Observable; import java.util.Observable;
@ -32,18 +33,16 @@ import java.util.Observable;
*/ */
public class LevelModel extends Observable implements Runnable { public class LevelModel extends Observable implements Runnable {
private DisplayableElementModel[][] groundGrid; private DisplayableElementModel[][] groundGrid;
private String levelName; private AudioLoadHelper audioLoadHelper;
private AudioLoadHelper audioLoadHelper;
private int sizeWidth = 0; private int sizeWidth = 0;
private int sizeHeight = 0; private int sizeHeight = 0;
private int cursorXPosition = 0; private final Point cursorPosition = new Point(0, 0);
private int cursorYPosition = 0;
private boolean showCursor = false; private boolean showCursor = false;
private CursorModel cursorModel; private CursorModel cursorModel;
private LevelLoadHelper levelLoadHelper; private LevelLoadHelper levelLoadHelper;
private RockfordModel rockford; private RockfordModel rockford;
private GameInformationModel gameInformationModel; private GameInformationModel gameInformationModel;
private int rockfordPositionX, rockfordPositionY; private Point rockfordPosition;
private boolean gameRunning; private boolean gameRunning;
private boolean gamePaused; private boolean gamePaused;
// Are we in editor or game mode ? // Are we in editor or game mode ?
@ -67,13 +66,12 @@ public class LevelModel extends Observable implements Runnable {
* @param mode Instance mode * @param mode Instance mode
*/ */
public LevelModel(String levelName, AudioLoadHelper audioLoadHelper, String mode) { public LevelModel(String levelName, AudioLoadHelper audioLoadHelper, String mode) {
this.levelName = levelName; this.audioLoadHelper = audioLoadHelper;
this.audioLoadHelper = audioLoadHelper;
this.gamePaused = false; this.gamePaused = false;
this.gameRunning = true; this.gameRunning = true;
this.mode = mode; this.mode = mode;
this.levelLoadHelper = new LevelLoadHelper(this.levelName); this.levelLoadHelper = new LevelLoadHelper(levelName);
this.groundGrid = this.levelLoadHelper.getGroundGrid(); this.groundGrid = this.levelLoadHelper.getGroundGrid();
this.sizeWidth = this.levelLoadHelper.getWidthSizeValue(); this.sizeWidth = this.levelLoadHelper.getWidthSizeValue();
@ -137,8 +135,7 @@ public class LevelModel extends Observable implements Runnable {
* Initializes the Rockford position attributes * Initializes the Rockford position attributes
*/ */
private void initRockford() { private void initRockford() {
this.rockfordPositionX = this.levelLoadHelper.getRockfordPositionX(); this.rockfordPosition = new Point(this.levelLoadHelper.getRockfordPositionX(), this.levelLoadHelper.getRockfordPositionY());
this.rockfordPositionY = this.levelLoadHelper.getRockfordPositionY();
this.rockford = this.levelLoadHelper.getRockfordInstance(); this.rockford = this.levelLoadHelper.getRockfordInstance();
} }
@ -172,8 +169,8 @@ public class LevelModel extends Observable implements Runnable {
* @param posY Vertical position of Rockford * @param posY Vertical position of Rockford
*/ */
public void updateRockfordPosition(int posX, int posY) { public void updateRockfordPosition(int posX, int posY) {
this.rockfordPositionY = posY; this.rockfordPosition.y = posY;
this.rockfordPositionX = posX; this.rockfordPosition.x = posX;
} }
/** /**
@ -219,7 +216,7 @@ public class LevelModel extends Observable implements Runnable {
* @return Horizontal position of Rockford * @return Horizontal position of Rockford
*/ */
public int getRockfordPositionX() { public int getRockfordPositionX() {
return this.rockfordPositionX; return this.rockfordPosition.x;
} }
/** /**
@ -310,7 +307,7 @@ public class LevelModel extends Observable implements Runnable {
* @return Vertical position of Rockford * @return Vertical position of Rockford
*/ */
public int getRockfordPositionY() { public int getRockfordPositionY() {
return this.rockfordPositionY; return this.rockfordPosition.y;
} }
/** /**
@ -531,7 +528,7 @@ public class LevelModel extends Observable implements Runnable {
* @return Cursor position X value * @return Cursor position X value
*/ */
public int getCursorXPosition() { public int getCursorXPosition() {
return this.cursorXPosition; return this.cursorPosition.x;
} }
/** /**
@ -540,7 +537,7 @@ public class LevelModel extends Observable implements Runnable {
* @return Cursor position Y value * @return Cursor position Y value
*/ */
public int getCursorYPosition() { public int getCursorYPosition() {
return this.cursorYPosition; return this.cursorPosition.y;
} }
/** /**
@ -549,8 +546,8 @@ public class LevelModel extends Observable implements Runnable {
* @return Cursor position new X value * @return Cursor position new X value
*/ */
public int incrementCursorXPosition() { public int incrementCursorXPosition() {
if (this.cursorXPosition < (this.getSizeWidth() - 1 - 2)) { if (this.cursorPosition.x < (this.getSizeWidth() - 1 - 2)) {
this.cursorXPosition = this.cursorXPosition + 1; this.cursorPosition.x = this.cursorPosition.x + 1;
} }
this.localNotifyObservers(); this.localNotifyObservers();
@ -563,8 +560,8 @@ public class LevelModel extends Observable implements Runnable {
* @return Cursor position new X value * @return Cursor position new X value
*/ */
public int decrementCursorXPosition() { public int decrementCursorXPosition() {
if (this.cursorXPosition > 0) { if (this.cursorPosition.x > 0) {
this.cursorXPosition = this.cursorXPosition - 1; this.cursorPosition.x = this.cursorPosition.x - 1;
} }
this.localNotifyObservers(); this.localNotifyObservers();
@ -577,8 +574,8 @@ public class LevelModel extends Observable implements Runnable {
* @return Cursor position new Y value * @return Cursor position new Y value
*/ */
public int incrementCursorYPosition() { public int incrementCursorYPosition() {
if (this.cursorYPosition < (this.getSizeHeight() - 1 - 2)) { if (this.cursorPosition.y < (this.getSizeHeight() - 1 - 2)) {
this.cursorYPosition = this.cursorYPosition + 1; this.cursorPosition.y = this.cursorPosition.y + 1;
} }
this.localNotifyObservers(); this.localNotifyObservers();
@ -591,8 +588,8 @@ public class LevelModel extends Observable implements Runnable {
* @return Cursor position new Y value * @return Cursor position new Y value
*/ */
public int decrementCursorYPosition() { public int decrementCursorYPosition() {
if (this.cursorYPosition > 0) { if (this.cursorPosition.y > 0) {
this.cursorYPosition = this.cursorYPosition - 1; this.cursorPosition.y = this.cursorPosition.y - 1;
} }
this.localNotifyObservers(); this.localNotifyObservers();