From 952eb535c8b45df48a6801a51a34de0ccccc9a17 Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Tue, 1 Oct 2019 21:18:29 -0300 Subject: [PATCH] Optimize code Fix spelling Signed-off-by: Chris Cromer --- .idea/dictionaries/cromer.xml | 12 +++++++++ src/cl/cromer/azaraka/Celda.java | 12 ++++----- src/cl/cromer/azaraka/Constantes.java | 28 +++++++++---------- src/cl/cromer/azaraka/Escenario.java | 10 +++---- src/cl/cromer/azaraka/Lienzo.java | 14 +++++----- src/cl/cromer/azaraka/Main.java | 2 +- src/cl/cromer/azaraka/json/Json.java | 2 +- src/cl/cromer/azaraka/object/Enemy.java | 2 +- src/cl/cromer/azaraka/object/Gem.java | 9 ------- src/cl/cromer/azaraka/object/Object.java | 30 ++++++++++----------- src/cl/cromer/azaraka/object/Player.java | 2 +- src/cl/cromer/azaraka/panel/Config.java | 5 ++-- src/cl/cromer/azaraka/panel/Game.java | 2 +- src/cl/cromer/azaraka/sound/Sound.java | 4 +-- src/cl/cromer/azaraka/sprite/Animation.java | 7 ++--- src/cl/cromer/azaraka/sprite/Sheet.java | 4 +-- 16 files changed, 74 insertions(+), 71 deletions(-) diff --git a/.idea/dictionaries/cromer.xml b/.idea/dictionaries/cromer.xml index 6476eae..7015fa7 100644 --- a/.idea/dictionaries/cromer.xml +++ b/.idea/dictionaries/cromer.xml @@ -1,7 +1,19 @@ + aventura + azaraka + celda + celdas + cellpadding + cellspacing + constantes cromer + escenario + gameover + ganaste + lienzo + ventana \ No newline at end of file diff --git a/src/cl/cromer/azaraka/Celda.java b/src/cl/cromer/azaraka/Celda.java index aa0af86..7377c9f 100644 --- a/src/cl/cromer/azaraka/Celda.java +++ b/src/cl/cromer/azaraka/Celda.java @@ -29,27 +29,27 @@ public class Celda extends JComponent implements Constantes { /** * The x graphical coordinate of the cell */ - private int xPixels; + private final int xPixels; /** * The y graphical coordinate of the cell */ - private int yPixels; + private final int yPixels; /** * The x coordinate of the cell */ - private int x; + private final int x; /** * The y coordinate of the cell */ - private int y; + private final int y; /** * The textures to show in this cell */ - private ArrayList textures = new ArrayList<>(); + private final ArrayList textures = new ArrayList<>(); /** * The texture numbers */ - private ArrayList textureNumbers = new ArrayList<>(); + private final ArrayList textureNumbers = new ArrayList<>(); /** * The object in the cell */ diff --git a/src/cl/cromer/azaraka/Constantes.java b/src/cl/cromer/azaraka/Constantes.java index f3aa785..cd8bb57 100644 --- a/src/cl/cromer/azaraka/Constantes.java +++ b/src/cl/cromer/azaraka/Constantes.java @@ -202,25 +202,25 @@ public interface Constantes { */ enum LogLevel { GLOBAL(Level.WARNING), - MAIN(Level.WARNING), - VENTANA_PRINCIPAL(Level.WARNING), - LIENZO(Level.WARNING), - ESCENARIO(Level.WARNING), + MAIN(Level.INFO), + VENTANA_PRINCIPAL(Level.INFO), + LIENZO(Level.INFO), + ESCENARIO(Level.INFO), PLAYER(Level.WARNING), ENEMY(Level.WARNING), - CHEST(Level.WARNING), - CONFIG(Level.WARNING), - SOUND(Level.WARNING), - ANIMATION(Level.WARNING), - SHEET(Level.WARNING), - KEY(Level.WARNING), - JSON(Level.WARNING), - PORTAL(Level.WARNING); + CHEST(Level.INFO), + CONFIG(Level.INFO), + SOUND(Level.INFO), + ANIMATION(Level.INFO), + SHEET(Level.INFO), + KEY(Level.INFO), + JSON(Level.INFO), + PORTAL(Level.INFO); /** * The level of log for the enum */ - private Level level; + private final Level level; /** * Initialize the log level enum @@ -236,7 +236,7 @@ public interface Constantes { * * @return Returns the level */ - public Level getLevel() { + protected Level getLevel() { return this.level; } } diff --git a/src/cl/cromer/azaraka/Escenario.java b/src/cl/cromer/azaraka/Escenario.java index 91d7989..1088238 100644 --- a/src/cl/cromer/azaraka/Escenario.java +++ b/src/cl/cromer/azaraka/Escenario.java @@ -42,19 +42,19 @@ public class Escenario extends JComponent implements Constantes { /** * The width of the scene */ - protected int width = CELL_PIXELS * HORIZONTAL_CELLS; + protected final int width = CELL_PIXELS * HORIZONTAL_CELLS; /** * The height of the scene */ - protected int height = CELL_PIXELS * VERTICAL_CELLS; + protected final int height = CELL_PIXELS * VERTICAL_CELLS; /** * The canvas */ - private Lienzo canvas; + private final Lienzo canvas; /** * The cells of the game */ - private Celda[][] celdas; + private final Celda[][] celdas; /** * A collection of tiles that can be used in the scene */ @@ -66,7 +66,7 @@ public class Escenario extends JComponent implements Constantes { /** * The logger */ - private Logger logger; + private final Logger logger; /** * Initialize the scene diff --git a/src/cl/cromer/azaraka/Lienzo.java b/src/cl/cromer/azaraka/Lienzo.java index a631829..0906a9b 100644 --- a/src/cl/cromer/azaraka/Lienzo.java +++ b/src/cl/cromer/azaraka/Lienzo.java @@ -39,7 +39,7 @@ public class Lienzo extends Canvas implements Constantes { /** * The game scene */ - private Escenario escenario; + private final Escenario escenario; /** * The graphics buffer */ @@ -51,7 +51,7 @@ public class Lienzo extends Canvas implements Constantes { /** * The threads for the objects */ - private HashMap threads = new HashMap<>(); + private final HashMap threads = new HashMap<>(); /** * The player */ @@ -59,15 +59,15 @@ public class Lienzo extends Canvas implements Constantes { /** * The enemies */ - private ArrayList enemies = new ArrayList<>(); + private final ArrayList enemies = new ArrayList<>(); /** * The keys */ - private ArrayList keys = new ArrayList<>(); + private final ArrayList keys = new ArrayList<>(); /** * The chests */ - private ArrayList chests = new ArrayList<>(); + private final ArrayList chests = new ArrayList<>(); /** * The magic portal */ @@ -75,11 +75,11 @@ public class Lienzo extends Canvas implements Constantes { /** * The logger */ - private Logger logger; + private final Logger logger; /** * The game over animation */ - private Animation gameOverAnimation; + private final Animation gameOverAnimation; /** * The hearts animation */ diff --git a/src/cl/cromer/azaraka/Main.java b/src/cl/cromer/azaraka/Main.java index 29babf2..6c62e58 100644 --- a/src/cl/cromer/azaraka/Main.java +++ b/src/cl/cromer/azaraka/Main.java @@ -26,7 +26,7 @@ public class Main implements Constantes { /** * Initialize the main class */ - public Main() { + private Main() { Logger logger = getLogger(this.getClass(), LogLevel.MAIN); logger.info("Load main window"); diff --git a/src/cl/cromer/azaraka/json/Json.java b/src/cl/cromer/azaraka/json/Json.java index b1ae0c9..dbb71bd 100644 --- a/src/cl/cromer/azaraka/json/Json.java +++ b/src/cl/cromer/azaraka/json/Json.java @@ -32,7 +32,7 @@ public class Json implements Constantes { /** * The logger */ - private Logger logger; + private final Logger logger; /** * Initialize the JSON object diff --git a/src/cl/cromer/azaraka/object/Enemy.java b/src/cl/cromer/azaraka/object/Enemy.java index cf9f612..658e784 100644 --- a/src/cl/cromer/azaraka/object/Enemy.java +++ b/src/cl/cromer/azaraka/object/Enemy.java @@ -41,7 +41,7 @@ public class Enemy extends Object implements Constantes { /** * The lock helps prevent race conditions when checking positioning */ - private Lock lock; + private final Lock lock; /** * The enemy attack sound */ diff --git a/src/cl/cromer/azaraka/object/Gem.java b/src/cl/cromer/azaraka/object/Gem.java index 4ad0da7..59f425d 100644 --- a/src/cl/cromer/azaraka/object/Gem.java +++ b/src/cl/cromer/azaraka/object/Gem.java @@ -50,13 +50,4 @@ public class Gem extends Object { public Gem(Escenario escenario, Celda celda) { super(escenario, celda); } - - /** - * ` - * This method is run when the thread starts - */ - @Override - public void run() { - super.run(); - } } diff --git a/src/cl/cromer/azaraka/object/Object.java b/src/cl/cromer/azaraka/object/Object.java index a2a82b1..ef12775 100644 --- a/src/cl/cromer/azaraka/object/Object.java +++ b/src/cl/cromer/azaraka/object/Object.java @@ -40,7 +40,7 @@ public class Object implements Runnable { /** * The scene the object is in */ - private Escenario escenario; + private final Escenario escenario; /** * The cell the object is in */ @@ -68,7 +68,7 @@ public class Object implements Runnable { * @param escenario The scene the object is in * @param celda The cell the object is in */ - public Object(Escenario escenario, Celda celda) { + protected Object(Escenario escenario, Celda celda) { this.escenario = escenario; this.celda = celda; this.x = celda.getX(); @@ -80,7 +80,7 @@ public class Object implements Runnable { * * @return Returns the x coordinate */ - public int getX() { + protected int getX() { return x; } @@ -89,7 +89,7 @@ public class Object implements Runnable { * * @param x The new x coordinate */ - public void setX(int x) { + protected void setX(int x) { this.x = x; } @@ -98,7 +98,7 @@ public class Object implements Runnable { * * @return Returns the y coordinate */ - public int getY() { + protected int getY() { return y; } @@ -107,7 +107,7 @@ public class Object implements Runnable { * * @param y The new y coordinate */ - public void setY(int y) { + protected void setY(int y) { this.y = y; } @@ -116,7 +116,7 @@ public class Object implements Runnable { * * @return Returns the scene */ - public Escenario getEscenario() { + protected Escenario getEscenario() { return escenario; } @@ -134,7 +134,7 @@ public class Object implements Runnable { * * @return Returns an animation */ - public Animation getAnimation() { + protected Animation getAnimation() { return animation; } @@ -143,7 +143,7 @@ public class Object implements Runnable { * * @param animation The new animation */ - public void setAnimation(Animation animation) { + protected void setAnimation(Animation animation) { this.animation = animation; } @@ -152,7 +152,7 @@ public class Object implements Runnable { * * @param useOffset If true the animation will use an offset to help center it */ - public void setUseOffset(boolean useOffset) { + protected void setUseOffset(boolean useOffset) { this.useOffset = useOffset; } @@ -162,7 +162,7 @@ public class Object implements Runnable { * @param path The path to the image * @param character The character number */ - public void loadCharacter(String path, int character) { + protected void loadCharacter(String path, int character) { Sheet characterSheet = new Sheet(path, 54, 39); try { Animation animation = new Animation(); @@ -217,7 +217,7 @@ public class Object implements Runnable { * * @param celda The cell */ - public void setCelda(Celda celda) { + protected void setCelda(Celda celda) { this.celda = celda; } @@ -226,7 +226,7 @@ public class Object implements Runnable { * * @return Returns a logger */ - public Logger getLogger() { + protected Logger getLogger() { return logger; } @@ -235,7 +235,7 @@ public class Object implements Runnable { * * @param logger The logger to set */ - public void setLogger(Logger logger) { + protected void setLogger(Logger logger) { this.logger = logger; } @@ -244,7 +244,7 @@ public class Object implements Runnable { * * @return Returns true if the object is active or false otherwise */ - public boolean getActive() { + protected boolean getActive() { return active; } diff --git a/src/cl/cromer/azaraka/object/Player.java b/src/cl/cromer/azaraka/object/Player.java index 69272a9..41bd96a 100644 --- a/src/cl/cromer/azaraka/object/Player.java +++ b/src/cl/cromer/azaraka/object/Player.java @@ -39,7 +39,7 @@ public class Player extends Object implements Constantes { /** * Objects that the player is carrying */ - private ArrayList carrying = new ArrayList<>(); + private final ArrayList carrying = new ArrayList<>(); /** * Initialize the player diff --git a/src/cl/cromer/azaraka/panel/Config.java b/src/cl/cromer/azaraka/panel/Config.java index 3d93538..39e6277 100644 --- a/src/cl/cromer/azaraka/panel/Config.java +++ b/src/cl/cromer/azaraka/panel/Config.java @@ -29,12 +29,11 @@ public class Config extends JPanel implements Constantes { /** * The game panel to modify with the new configuration */ - private Game gamePanel; - + private final Game gamePanel; /** * The logger */ - private Logger logger; + private final Logger logger; /** * The game panel used to modify with the new config diff --git a/src/cl/cromer/azaraka/panel/Game.java b/src/cl/cromer/azaraka/panel/Game.java index 5bf1e53..ef2eaec 100644 --- a/src/cl/cromer/azaraka/panel/Game.java +++ b/src/cl/cromer/azaraka/panel/Game.java @@ -28,7 +28,7 @@ public class Game extends JPanel implements Constantes { /** * The canvas */ - private Lienzo canvas; + private final Lienzo canvas; /** * Initialize the game panel diff --git a/src/cl/cromer/azaraka/sound/Sound.java b/src/cl/cromer/azaraka/sound/Sound.java index d9b4e20..09e3c4b 100644 --- a/src/cl/cromer/azaraka/sound/Sound.java +++ b/src/cl/cromer/azaraka/sound/Sound.java @@ -34,11 +34,11 @@ public class Sound implements Constantes { /** * The path to the sound */ - private String path; + private final String path; /** * The logger */ - private Logger logger; + private final Logger logger; /** * Load the sound diff --git a/src/cl/cromer/azaraka/sprite/Animation.java b/src/cl/cromer/azaraka/sprite/Animation.java index 531599e..7cf80cf 100644 --- a/src/cl/cromer/azaraka/sprite/Animation.java +++ b/src/cl/cromer/azaraka/sprite/Animation.java @@ -48,11 +48,11 @@ public class Animation implements Cloneable, Constantes { /** * The collection of all the images that make up the object */ - private HashMap> imageHash; + private final HashMap> imageHash; /** * The logger */ - private Logger logger; + private final Logger logger; /** * Initialize the sprite @@ -70,7 +70,8 @@ public class Animation implements Cloneable, Constantes { * @param height The new height * @return Returns the scaled image */ - static public BufferedImage scaleImage(BufferedImage image, int width, int height) { + @SuppressWarnings("unused") + public static BufferedImage scaleImage(BufferedImage image, int width, int height) { Image tmpImage = image.getScaledInstance(width, height, BufferedImage.SCALE_SMOOTH); BufferedImage resized = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D graphics2D = resized.createGraphics(); diff --git a/src/cl/cromer/azaraka/sprite/Sheet.java b/src/cl/cromer/azaraka/sprite/Sheet.java index 62ca164..d856030 100644 --- a/src/cl/cromer/azaraka/sprite/Sheet.java +++ b/src/cl/cromer/azaraka/sprite/Sheet.java @@ -24,13 +24,13 @@ import java.util.ArrayList; import java.util.logging.Logger; /** - * This class handles loading the images and subimages + * This class handles loading the images and sub-images */ public class Sheet implements Constantes { /** * A list of all the textures in the collection */ - private ArrayList images; + private final ArrayList images; /** * Initialize the texture collection