Fixed error highlighted by Checkstyle

This commit is contained in:
0nlineSam 2024-10-27 14:29:07 +01:00
parent 5f6312555d
commit 7ee889d843
19 changed files with 68 additions and 35 deletions

View File

@ -9,6 +9,7 @@
<list>
<ConfigurationLocation id="bundled-sun-checks" type="BUNDLED" scope="All" description="Sun Checks">(bundled)</ConfigurationLocation>
<ConfigurationLocation id="bundled-google-checks" type="BUNDLED" scope="All" description="Google Checks">(bundled)</ConfigurationLocation>
<ConfigurationLocation id="eabae839-0a9c-4483-92ce-fd4170fff7e6" type="LOCAL_FILE" scope="All" description="Homework-1-Checker">$PROJECT_DIR$/ueb01_checkstyle_config-Homework.xml</ConfigurationLocation>
<ConfigurationLocation id="5232a701-ef57-4b8f-b1df-ed9fcf2cc548" type="LOCAL_FILE" scope="All" description="Ueb 01 Checkstyle">$PROJECT_DIR$/ueb01_checkstyle_config.xml</ConfigurationLocation>
</list>
</option>

View File

@ -15,6 +15,8 @@ import fr.enssat.BoulderDash.models.DisplayableElementModel;
* @since 2015-06-19
*/
public class DiamondModel extends DisplayableElementModel {
private static final int SIZ_X_OF_SPRITE = 16;
private static final int SIZ_Y_OF_SPRITE = 16;
private static String spriteName;
private static boolean isDestructible;
private static boolean canMove;
@ -25,8 +27,6 @@ public class DiamondModel extends DisplayableElementModel {
private long previousTime;
private int currentFrame;
private final int SIZ_X_OF_SPRITE = 16;
private final int SIZ_Y_OF_SPRITE = 16;
private long speed;
private ArrayList<BufferedImage> framesDiamond;

View File

@ -210,15 +210,15 @@ public abstract class DisplayableElementModel {
* @return Sprite object
*/
public BufferedImage loadSprite(String spriteName) {
BufferedImage sprite = null;
BufferedImage loadedSprite = null;
try {
sprite = ImageIO.read(new File("res/drawable/field/" + spriteName + ".gif"));
loadedSprite = ImageIO.read(new File("res/drawable/field/" + spriteName + ".gif"));
} catch (IOException e) {
e.printStackTrace();
}
this.sprite = sprite;
sprite = loadedSprite;
return sprite;
}

View File

@ -31,6 +31,11 @@ import java.util.Observable;
* @since 2015-06-19
*/
public class LevelModel extends Observable implements Runnable {
/**
* Animation speed
*/
private static final int DELAY = 25;
private DisplayableElementModel[][] groundGrid;
private String levelName;
private AudioLoadHelper audioLoadHelper;
@ -54,11 +59,6 @@ public class LevelModel extends Observable implements Runnable {
*/
private Thread spriteAnimator;
/**
* Animation speed
*/
private final int DELAY = 25;
/**
* Class constructor
*
@ -196,9 +196,9 @@ public class LevelModel extends Observable implements Runnable {
private void playCollisionSound(int posX, int posY) {
String collisionSound = null;
if (this.getRockford().isCollisionDone() == false) {
if (!this.getRockford().isCollisionDone()) {
// Out of bounds?
if (this.isOutOfBounds(posX, posY) == true) {
if (this.isOutOfBounds(posX, posY)) {
collisionSound = "touch";
} else {
DisplayableElementModel nextElement = this.groundGrid[posX][posY];
@ -246,7 +246,7 @@ public class LevelModel extends Observable implements Runnable {
this.playCollisionSound(posX, posY);
// Check that we are not out of bound...
if (this.isOutOfBounds(posX, posY) == false) {
if (!this.isOutOfBounds(posX, posY)) {
// Create a new empty model in the old pos of Rockford
this.groundGrid[oldX][oldY] = new EmptyModel();
@ -273,13 +273,8 @@ public class LevelModel extends Observable implements Runnable {
* @param blockValue New value
*/
public void triggerBlockChange(String blockValue) {
// No block value?
if(blockValue == null || blockValue.isEmpty()) {
return;
}
// Cancel if Rockford is already in model
if((blockValue.equals("Rockford") || blockValue.equals("rockford")) && this.isRockfordInModel()) {
// No block value? or Cancel if Rockford is already in model
if((blockValue == null || blockValue.isEmpty()) || ((blockValue.equals("Rockford") || blockValue.equals("rockford")) && this.isRockfordInModel())) {
return;
}

View File

@ -15,6 +15,11 @@ import fr.enssat.BoulderDash.models.DisplayableElementModel;
* @since 2015-06-19
*/
public class RockfordModel extends DisplayableElementModel {
/**
* Defines the size of the sprite
* */
private static final int SIZ_X_OF_SPRITE = 16;
private static final int SIZ_Y_OF_SPRITE = 16;
private static String spriteName;
private static boolean isDestructible;
private static boolean canMove;
@ -32,12 +37,6 @@ public class RockfordModel extends DisplayableElementModel {
private static ArrayList<BufferedImage> framesRunningRight;
private static ArrayList<BufferedImage> framesRunningUpOrDown;
/**
* Defines the size of the sprite
*/
private final int SIZ_X_OF_SPRITE = 16;
private final int SIZ_Y_OF_SPRITE = 16;
/**
* Defines the current speed of the object
*/

View File

@ -18,15 +18,15 @@ import fr.enssat.BoulderDash.views.LevelEditorView;
* @since 2015-06-22
*/
public class AssetsLevelEditorComponent extends JPanel implements ActionListener {
private LevelEditorView levelEditorView;
/**
* Available choices
*/
static List<String> choiceList = Arrays.asList(
private static List<String> choiceList = Arrays.asList(
"Boulder", "Diamond", "Dirt", "Brick Wall", "Expanding Wall", "Magic Wall", "Steel Wall", "Rockford"
);
private LevelEditorView levelEditorView;
/**
* Class constructor
*

View File

@ -31,7 +31,7 @@ public class GameGroundView extends GroundView {
this.gameController = gameController;
this.addKeyListener(new GameKeyController(this.levelModel, this.gameController.getAudioLoadHelper()));
this.addKeyListener(new GameKeyController(super.getLevelModel(), this.gameController.getAudioLoadHelper()));
this.setBorder(BorderFactory.createLineBorder(Color.black));
this.setFocusable(true);

View File

@ -22,7 +22,7 @@ import java.util.Observer;
*
*/
public abstract class GroundView extends JPanel implements Observer {
protected LevelModel levelModel;
private LevelModel levelModel;
/**
* Class constructor
@ -34,6 +34,10 @@ public abstract class GroundView extends JPanel implements Observer {
this.levelModel.addObserver(this);
}
protected LevelModel getLevelModel() {
return levelModel;
}
/**
* Draws the map
*

View File

@ -39,10 +39,11 @@ public class WinLoseView extends JFrame{
private void createLayout() {
JTextArea help = new JTextArea();
help.setEditable(false);
if(winOrLose.equals("win"))
help.setText("YOU WIN THE GAME :-)");
else
help.setText("YOU LOSE THE GAME :-( TRY AGAIN!");
if(winOrLose.equals("win")) {
help.setText("YOU WIN THE GAME :-)");
} else {
help.setText("YOU LOSE THE GAME :-( TRY AGAIN!");
}
this.add(help);
}

View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN" "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
<property name="severity" value="error"/>
<module name="TreeWalker">
<module name="NeedBraces">
<property name="tokens" value="LITERAL_DO,LITERAL_ELSE,LITERAL_FOR,LITERAL_IF,LITERAL_WHILE"/>
</module>
<module name="AvoidInlineConditionals"/>
<module name="DeclarationOrder"/>
<module name="ReturnCount"/>
<module name="NestedTryDepth"/>
<module name="SimplifyBooleanExpression"/>
<module name="HiddenField">
<property name="tokens" value="VARIABLE_DEF"/>
</module>
<module name="AbbreviationAsWordInName">
<property name="ignoreStaticFinal" value="true"/>
<property name="ignoreFinal" value="false"/>
<property name="allowedAbbreviationLength" value="3"/>
<property name="tokens"
value="VARIABLE_DEF"/>
</module>
<module name="VisibilityModifier"/>
<module name="StringLiteralEquality">
<property name="severity" value="warning"/>
</module>
<module name="EqualsAvoidNull">
<property name="severity" value="warning"/>
</module>
</module>
</module>