From 266283c49c60db3d923db1830eb0f1b578a99f63 Mon Sep 17 00:00:00 2001 From: Daniel Langbein Date: Tue, 19 Nov 2024 09:47:00 +0100 Subject: [PATCH] 1b: inline static fields and reuse fields of super class --- .../displayableElement/DiamondModel.java | 25 ++------------- .../DisplayableElementModel.java | 2 +- .../displayableElement/MagicWallModel.java | 31 ++----------------- .../displayableElement/RockfordModel.java | 28 ++--------------- 4 files changed, 10 insertions(+), 76 deletions(-) diff --git a/boulder-dash/src/fr/enssat/BoulderDash/models/displayableElement/DiamondModel.java b/boulder-dash/src/fr/enssat/BoulderDash/models/displayableElement/DiamondModel.java index 6df32537..334b3390 100644 --- a/boulder-dash/src/fr/enssat/BoulderDash/models/displayableElement/DiamondModel.java +++ b/boulder-dash/src/fr/enssat/BoulderDash/models/displayableElement/DiamondModel.java @@ -13,13 +13,6 @@ import java.util.ArrayList; * @since 2015-06-19 */ public class DiamondModel extends DisplayableElementModel { - private static String spriteName; - private static boolean isDestructible; - private static boolean canMove; - private static boolean impactExplosive; - private static boolean animate; - private static int priority; - private static String collideSound; private long previousTime; private int currentFrame; @@ -29,22 +22,10 @@ public class DiamondModel extends DisplayableElementModel { private ArrayList framesDiamond; - /** - * Static dataset - * Specifies the physical parameters of the object - */ - static { - spriteName = "diamond"; - isDestructible = true; - canMove = true; - impactExplosive = false; - animate = true; - priority = 0; - collideSound = "coin"; - } - DiamondModel() { - super(isDestructible, canMove, spriteName, priority, impactExplosive, animate, false, collideSound); + super(true, true, "diamond", + 0, false, true, + false, "coin"); this.initSprites(); } diff --git a/boulder-dash/src/fr/enssat/BoulderDash/models/displayableElement/DisplayableElementModel.java b/boulder-dash/src/fr/enssat/BoulderDash/models/displayableElement/DisplayableElementModel.java index c5d9756f..b17ed181 100644 --- a/boulder-dash/src/fr/enssat/BoulderDash/models/displayableElement/DisplayableElementModel.java +++ b/boulder-dash/src/fr/enssat/BoulderDash/models/displayableElement/DisplayableElementModel.java @@ -24,7 +24,7 @@ public abstract class DisplayableElementModel { private boolean moving; private boolean animate; private boolean impactExplosive; - private String spriteName; + protected final String spriteName; private int priority; private BufferedImage sprite; private boolean falling; diff --git a/boulder-dash/src/fr/enssat/BoulderDash/models/displayableElement/MagicWallModel.java b/boulder-dash/src/fr/enssat/BoulderDash/models/displayableElement/MagicWallModel.java index 5c83ad14..4088bcc1 100644 --- a/boulder-dash/src/fr/enssat/BoulderDash/models/displayableElement/MagicWallModel.java +++ b/boulder-dash/src/fr/enssat/BoulderDash/models/displayableElement/MagicWallModel.java @@ -13,15 +13,6 @@ import java.util.ArrayList; * @since 2015-06-19 */ public class MagicWallModel extends DisplayableElementModel { - private static String spriteName; - private static boolean isDestructible; - private static boolean canMove; - private static boolean impactExplosive; - private static boolean animate; - private static int priority; - private static boolean falling; - private static String collideSound; - /** * Stores the frames * Used for the sprites @@ -32,26 +23,10 @@ public class MagicWallModel extends DisplayableElementModel { private int currentFrame; private long speed; - /** - * Static dataset - * Specifies the physical parameters of the object - */ - static { - spriteName = "magicwall"; - isDestructible = false; - canMove = false; - impactExplosive = false; - animate = false; - priority = 3; - falling = false; - collideSound = "touch"; - } - - /** - * Class constructor - */ MagicWallModel() { - super(isDestructible, canMove, spriteName, priority, impactExplosive, animate, falling, collideSound); + super(false, false, "magicwall", + 3, false, false, + false, "touch"); this.currentFrame = 0; this.speed = 100; this.initSprites(); diff --git a/boulder-dash/src/fr/enssat/BoulderDash/models/displayableElement/RockfordModel.java b/boulder-dash/src/fr/enssat/BoulderDash/models/displayableElement/RockfordModel.java index f4f527d6..57fc575e 100644 --- a/boulder-dash/src/fr/enssat/BoulderDash/models/displayableElement/RockfordModel.java +++ b/boulder-dash/src/fr/enssat/BoulderDash/models/displayableElement/RockfordModel.java @@ -13,15 +13,6 @@ import java.util.ArrayList; * @since 2015-06-19 */ public class RockfordModel extends DisplayableElementModel { - private static String spriteName; - private static boolean isDestructible; - private static boolean canMove; - private static boolean impactExplosive; - private static boolean animate; - private static int priority; - private static boolean falling; - private static String collideSound; - /** * Maps the sub images of the sprite file */ @@ -55,23 +46,10 @@ public class RockfordModel extends DisplayableElementModel { private int currentFrame; private boolean hasExploded; - /** - * Static dataset - * Specifies the physical parameters of the object - */ - static { - spriteName = "rockford"; - isDestructible = true; - canMove = true; - impactExplosive = true; - animate = true; - priority = 1; - falling = false; - collideSound = null; - } - RockfordModel() { - super(isDestructible, canMove, spriteName, priority, impactExplosive, animate, falling, collideSound); + super(true, true, "rockford", + 1, true, true, + false, null); // Speed of the animation of the sprite this.setSpeed(100); // Init the sprites in arrays