Optimize code
Fix spelling Signed-off-by: Chris Cromer <chris@cromer.cl>
This commit is contained in:
parent
b9d3532fbc
commit
952eb535c8
@ -1,7 +1,19 @@
|
|||||||
<component name="ProjectDictionaryState">
|
<component name="ProjectDictionaryState">
|
||||||
<dictionary name="cromer">
|
<dictionary name="cromer">
|
||||||
<words>
|
<words>
|
||||||
|
<w>aventura</w>
|
||||||
|
<w>azaraka</w>
|
||||||
|
<w>celda</w>
|
||||||
|
<w>celdas</w>
|
||||||
|
<w>cellpadding</w>
|
||||||
|
<w>cellspacing</w>
|
||||||
|
<w>constantes</w>
|
||||||
<w>cromer</w>
|
<w>cromer</w>
|
||||||
|
<w>escenario</w>
|
||||||
|
<w>gameover</w>
|
||||||
|
<w>ganaste</w>
|
||||||
|
<w>lienzo</w>
|
||||||
|
<w>ventana</w>
|
||||||
</words>
|
</words>
|
||||||
</dictionary>
|
</dictionary>
|
||||||
</component>
|
</component>
|
@ -29,27 +29,27 @@ public class Celda extends JComponent implements Constantes {
|
|||||||
/**
|
/**
|
||||||
* The x graphical coordinate of the cell
|
* The x graphical coordinate of the cell
|
||||||
*/
|
*/
|
||||||
private int xPixels;
|
private final int xPixels;
|
||||||
/**
|
/**
|
||||||
* The y graphical coordinate of the cell
|
* The y graphical coordinate of the cell
|
||||||
*/
|
*/
|
||||||
private int yPixels;
|
private final int yPixels;
|
||||||
/**
|
/**
|
||||||
* The x coordinate of the cell
|
* The x coordinate of the cell
|
||||||
*/
|
*/
|
||||||
private int x;
|
private final int x;
|
||||||
/**
|
/**
|
||||||
* The y coordinate of the cell
|
* The y coordinate of the cell
|
||||||
*/
|
*/
|
||||||
private int y;
|
private final int y;
|
||||||
/**
|
/**
|
||||||
* The textures to show in this cell
|
* The textures to show in this cell
|
||||||
*/
|
*/
|
||||||
private ArrayList<BufferedImage> textures = new ArrayList<>();
|
private final ArrayList<BufferedImage> textures = new ArrayList<>();
|
||||||
/**
|
/**
|
||||||
* The texture numbers
|
* The texture numbers
|
||||||
*/
|
*/
|
||||||
private ArrayList<Integer> textureNumbers = new ArrayList<>();
|
private final ArrayList<Integer> textureNumbers = new ArrayList<>();
|
||||||
/**
|
/**
|
||||||
* The object in the cell
|
* The object in the cell
|
||||||
*/
|
*/
|
||||||
|
@ -202,25 +202,25 @@ public interface Constantes {
|
|||||||
*/
|
*/
|
||||||
enum LogLevel {
|
enum LogLevel {
|
||||||
GLOBAL(Level.WARNING),
|
GLOBAL(Level.WARNING),
|
||||||
MAIN(Level.WARNING),
|
MAIN(Level.INFO),
|
||||||
VENTANA_PRINCIPAL(Level.WARNING),
|
VENTANA_PRINCIPAL(Level.INFO),
|
||||||
LIENZO(Level.WARNING),
|
LIENZO(Level.INFO),
|
||||||
ESCENARIO(Level.WARNING),
|
ESCENARIO(Level.INFO),
|
||||||
PLAYER(Level.WARNING),
|
PLAYER(Level.WARNING),
|
||||||
ENEMY(Level.WARNING),
|
ENEMY(Level.WARNING),
|
||||||
CHEST(Level.WARNING),
|
CHEST(Level.INFO),
|
||||||
CONFIG(Level.WARNING),
|
CONFIG(Level.INFO),
|
||||||
SOUND(Level.WARNING),
|
SOUND(Level.INFO),
|
||||||
ANIMATION(Level.WARNING),
|
ANIMATION(Level.INFO),
|
||||||
SHEET(Level.WARNING),
|
SHEET(Level.INFO),
|
||||||
KEY(Level.WARNING),
|
KEY(Level.INFO),
|
||||||
JSON(Level.WARNING),
|
JSON(Level.INFO),
|
||||||
PORTAL(Level.WARNING);
|
PORTAL(Level.INFO);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The level of log for the enum
|
* The level of log for the enum
|
||||||
*/
|
*/
|
||||||
private Level level;
|
private final Level level;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the log level enum
|
* Initialize the log level enum
|
||||||
@ -236,7 +236,7 @@ public interface Constantes {
|
|||||||
*
|
*
|
||||||
* @return Returns the level
|
* @return Returns the level
|
||||||
*/
|
*/
|
||||||
public Level getLevel() {
|
protected Level getLevel() {
|
||||||
return this.level;
|
return this.level;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,19 +42,19 @@ public class Escenario extends JComponent implements Constantes {
|
|||||||
/**
|
/**
|
||||||
* The width of the scene
|
* 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
|
* The height of the scene
|
||||||
*/
|
*/
|
||||||
protected int height = CELL_PIXELS * VERTICAL_CELLS;
|
protected final int height = CELL_PIXELS * VERTICAL_CELLS;
|
||||||
/**
|
/**
|
||||||
* The canvas
|
* The canvas
|
||||||
*/
|
*/
|
||||||
private Lienzo canvas;
|
private final Lienzo canvas;
|
||||||
/**
|
/**
|
||||||
* The cells of the game
|
* The cells of the game
|
||||||
*/
|
*/
|
||||||
private Celda[][] celdas;
|
private final Celda[][] celdas;
|
||||||
/**
|
/**
|
||||||
* A collection of tiles that can be used in the scene
|
* A collection of tiles that can be used in the scene
|
||||||
*/
|
*/
|
||||||
@ -66,7 +66,7 @@ public class Escenario extends JComponent implements Constantes {
|
|||||||
/**
|
/**
|
||||||
* The logger
|
* The logger
|
||||||
*/
|
*/
|
||||||
private Logger logger;
|
private final Logger logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the scene
|
* Initialize the scene
|
||||||
|
@ -39,7 +39,7 @@ public class Lienzo extends Canvas implements Constantes {
|
|||||||
/**
|
/**
|
||||||
* The game scene
|
* The game scene
|
||||||
*/
|
*/
|
||||||
private Escenario escenario;
|
private final Escenario escenario;
|
||||||
/**
|
/**
|
||||||
* The graphics buffer
|
* The graphics buffer
|
||||||
*/
|
*/
|
||||||
@ -51,7 +51,7 @@ public class Lienzo extends Canvas implements Constantes {
|
|||||||
/**
|
/**
|
||||||
* The threads for the objects
|
* The threads for the objects
|
||||||
*/
|
*/
|
||||||
private HashMap<Object, Thread> threads = new HashMap<>();
|
private final HashMap<Object, Thread> threads = new HashMap<>();
|
||||||
/**
|
/**
|
||||||
* The player
|
* The player
|
||||||
*/
|
*/
|
||||||
@ -59,15 +59,15 @@ public class Lienzo extends Canvas implements Constantes {
|
|||||||
/**
|
/**
|
||||||
* The enemies
|
* The enemies
|
||||||
*/
|
*/
|
||||||
private ArrayList<Enemy> enemies = new ArrayList<>();
|
private final ArrayList<Enemy> enemies = new ArrayList<>();
|
||||||
/**
|
/**
|
||||||
* The keys
|
* The keys
|
||||||
*/
|
*/
|
||||||
private ArrayList<Key> keys = new ArrayList<>();
|
private final ArrayList<Key> keys = new ArrayList<>();
|
||||||
/**
|
/**
|
||||||
* The chests
|
* The chests
|
||||||
*/
|
*/
|
||||||
private ArrayList<Chest> chests = new ArrayList<>();
|
private final ArrayList<Chest> chests = new ArrayList<>();
|
||||||
/**
|
/**
|
||||||
* The magic portal
|
* The magic portal
|
||||||
*/
|
*/
|
||||||
@ -75,11 +75,11 @@ public class Lienzo extends Canvas implements Constantes {
|
|||||||
/**
|
/**
|
||||||
* The logger
|
* The logger
|
||||||
*/
|
*/
|
||||||
private Logger logger;
|
private final Logger logger;
|
||||||
/**
|
/**
|
||||||
* The game over animation
|
* The game over animation
|
||||||
*/
|
*/
|
||||||
private Animation gameOverAnimation;
|
private final Animation gameOverAnimation;
|
||||||
/**
|
/**
|
||||||
* The hearts animation
|
* The hearts animation
|
||||||
*/
|
*/
|
||||||
|
@ -26,7 +26,7 @@ public class Main implements Constantes {
|
|||||||
/**
|
/**
|
||||||
* Initialize the main class
|
* Initialize the main class
|
||||||
*/
|
*/
|
||||||
public Main() {
|
private Main() {
|
||||||
Logger logger = getLogger(this.getClass(), LogLevel.MAIN);
|
Logger logger = getLogger(this.getClass(), LogLevel.MAIN);
|
||||||
|
|
||||||
logger.info("Load main window");
|
logger.info("Load main window");
|
||||||
|
@ -32,7 +32,7 @@ public class Json implements Constantes {
|
|||||||
/**
|
/**
|
||||||
* The logger
|
* The logger
|
||||||
*/
|
*/
|
||||||
private Logger logger;
|
private final Logger logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the JSON object
|
* Initialize the JSON object
|
||||||
|
@ -41,7 +41,7 @@ public class Enemy extends Object implements Constantes {
|
|||||||
/**
|
/**
|
||||||
* The lock helps prevent race conditions when checking positioning
|
* The lock helps prevent race conditions when checking positioning
|
||||||
*/
|
*/
|
||||||
private Lock lock;
|
private final Lock lock;
|
||||||
/**
|
/**
|
||||||
* The enemy attack sound
|
* The enemy attack sound
|
||||||
*/
|
*/
|
||||||
|
@ -50,13 +50,4 @@ public class Gem extends Object {
|
|||||||
public Gem(Escenario escenario, Celda celda) {
|
public Gem(Escenario escenario, Celda celda) {
|
||||||
super(escenario, celda);
|
super(escenario, celda);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* `
|
|
||||||
* This method is run when the thread starts
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
super.run();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ public class Object implements Runnable {
|
|||||||
/**
|
/**
|
||||||
* The scene the object is in
|
* The scene the object is in
|
||||||
*/
|
*/
|
||||||
private Escenario escenario;
|
private final Escenario escenario;
|
||||||
/**
|
/**
|
||||||
* The cell the object is in
|
* The cell the object is in
|
||||||
*/
|
*/
|
||||||
@ -68,7 +68,7 @@ public class Object implements Runnable {
|
|||||||
* @param escenario The scene the object is in
|
* @param escenario The scene the object is in
|
||||||
* @param celda The cell 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.escenario = escenario;
|
||||||
this.celda = celda;
|
this.celda = celda;
|
||||||
this.x = celda.getX();
|
this.x = celda.getX();
|
||||||
@ -80,7 +80,7 @@ public class Object implements Runnable {
|
|||||||
*
|
*
|
||||||
* @return Returns the x coordinate
|
* @return Returns the x coordinate
|
||||||
*/
|
*/
|
||||||
public int getX() {
|
protected int getX() {
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ public class Object implements Runnable {
|
|||||||
*
|
*
|
||||||
* @param x The new x coordinate
|
* @param x The new x coordinate
|
||||||
*/
|
*/
|
||||||
public void setX(int x) {
|
protected void setX(int x) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,7 +98,7 @@ public class Object implements Runnable {
|
|||||||
*
|
*
|
||||||
* @return Returns the y coordinate
|
* @return Returns the y coordinate
|
||||||
*/
|
*/
|
||||||
public int getY() {
|
protected int getY() {
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,7 +107,7 @@ public class Object implements Runnable {
|
|||||||
*
|
*
|
||||||
* @param y The new y coordinate
|
* @param y The new y coordinate
|
||||||
*/
|
*/
|
||||||
public void setY(int y) {
|
protected void setY(int y) {
|
||||||
this.y = y;
|
this.y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,7 +116,7 @@ public class Object implements Runnable {
|
|||||||
*
|
*
|
||||||
* @return Returns the scene
|
* @return Returns the scene
|
||||||
*/
|
*/
|
||||||
public Escenario getEscenario() {
|
protected Escenario getEscenario() {
|
||||||
return escenario;
|
return escenario;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ public class Object implements Runnable {
|
|||||||
*
|
*
|
||||||
* @return Returns an animation
|
* @return Returns an animation
|
||||||
*/
|
*/
|
||||||
public Animation getAnimation() {
|
protected Animation getAnimation() {
|
||||||
return animation;
|
return animation;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,7 +143,7 @@ public class Object implements Runnable {
|
|||||||
*
|
*
|
||||||
* @param animation The new animation
|
* @param animation The new animation
|
||||||
*/
|
*/
|
||||||
public void setAnimation(Animation animation) {
|
protected void setAnimation(Animation animation) {
|
||||||
this.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
|
* @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;
|
this.useOffset = useOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,7 +162,7 @@ public class Object implements Runnable {
|
|||||||
* @param path The path to the image
|
* @param path The path to the image
|
||||||
* @param character The character number
|
* @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);
|
Sheet characterSheet = new Sheet(path, 54, 39);
|
||||||
try {
|
try {
|
||||||
Animation animation = new Animation();
|
Animation animation = new Animation();
|
||||||
@ -217,7 +217,7 @@ public class Object implements Runnable {
|
|||||||
*
|
*
|
||||||
* @param celda The cell
|
* @param celda The cell
|
||||||
*/
|
*/
|
||||||
public void setCelda(Celda celda) {
|
protected void setCelda(Celda celda) {
|
||||||
this.celda = celda;
|
this.celda = celda;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,7 +226,7 @@ public class Object implements Runnable {
|
|||||||
*
|
*
|
||||||
* @return Returns a logger
|
* @return Returns a logger
|
||||||
*/
|
*/
|
||||||
public Logger getLogger() {
|
protected Logger getLogger() {
|
||||||
return logger;
|
return logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,7 +235,7 @@ public class Object implements Runnable {
|
|||||||
*
|
*
|
||||||
* @param logger The logger to set
|
* @param logger The logger to set
|
||||||
*/
|
*/
|
||||||
public void setLogger(Logger logger) {
|
protected void setLogger(Logger logger) {
|
||||||
this.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
|
* @return Returns true if the object is active or false otherwise
|
||||||
*/
|
*/
|
||||||
public boolean getActive() {
|
protected boolean getActive() {
|
||||||
return active;
|
return active;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ public class Player extends Object implements Constantes {
|
|||||||
/**
|
/**
|
||||||
* Objects that the player is carrying
|
* Objects that the player is carrying
|
||||||
*/
|
*/
|
||||||
private ArrayList<Object> carrying = new ArrayList<>();
|
private final ArrayList<Object> carrying = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the player
|
* Initialize the player
|
||||||
|
@ -29,12 +29,11 @@ public class Config extends JPanel implements Constantes {
|
|||||||
/**
|
/**
|
||||||
* The game panel to modify with the new configuration
|
* The game panel to modify with the new configuration
|
||||||
*/
|
*/
|
||||||
private Game gamePanel;
|
private final Game gamePanel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The logger
|
* The logger
|
||||||
*/
|
*/
|
||||||
private Logger logger;
|
private final Logger logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The game panel used to modify with the new config
|
* The game panel used to modify with the new config
|
||||||
|
@ -28,7 +28,7 @@ public class Game extends JPanel implements Constantes {
|
|||||||
/**
|
/**
|
||||||
* The canvas
|
* The canvas
|
||||||
*/
|
*/
|
||||||
private Lienzo canvas;
|
private final Lienzo canvas;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the game panel
|
* Initialize the game panel
|
||||||
|
@ -34,11 +34,11 @@ public class Sound implements Constantes {
|
|||||||
/**
|
/**
|
||||||
* The path to the sound
|
* The path to the sound
|
||||||
*/
|
*/
|
||||||
private String path;
|
private final String path;
|
||||||
/**
|
/**
|
||||||
* The logger
|
* The logger
|
||||||
*/
|
*/
|
||||||
private Logger logger;
|
private final Logger logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load the sound
|
* Load the sound
|
||||||
|
@ -48,11 +48,11 @@ public class Animation implements Cloneable, Constantes {
|
|||||||
/**
|
/**
|
||||||
* The collection of all the images that make up the object
|
* The collection of all the images that make up the object
|
||||||
*/
|
*/
|
||||||
private HashMap<Direction, ArrayList<BufferedImage>> imageHash;
|
private final HashMap<Direction, ArrayList<BufferedImage>> imageHash;
|
||||||
/**
|
/**
|
||||||
* The logger
|
* The logger
|
||||||
*/
|
*/
|
||||||
private Logger logger;
|
private final Logger logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the sprite
|
* Initialize the sprite
|
||||||
@ -70,7 +70,8 @@ public class Animation implements Cloneable, Constantes {
|
|||||||
* @param height The new height
|
* @param height The new height
|
||||||
* @return Returns the scaled image
|
* @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);
|
Image tmpImage = image.getScaledInstance(width, height, BufferedImage.SCALE_SMOOTH);
|
||||||
BufferedImage resized = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
BufferedImage resized = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
||||||
Graphics2D graphics2D = resized.createGraphics();
|
Graphics2D graphics2D = resized.createGraphics();
|
||||||
|
@ -24,13 +24,13 @@ import java.util.ArrayList;
|
|||||||
import java.util.logging.Logger;
|
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 {
|
public class Sheet implements Constantes {
|
||||||
/**
|
/**
|
||||||
* A list of all the textures in the collection
|
* A list of all the textures in the collection
|
||||||
*/
|
*/
|
||||||
private ArrayList<BufferedImage> images;
|
private final ArrayList<BufferedImage> images;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the texture collection
|
* Initialize the texture collection
|
||||||
|
Loading…
Reference in New Issue
Block a user