Remove spanish class names

Implement restart
Make sure all objectives are reachable
Optimize code

Signed-off-by: Chris Cromer <chris@cromer.cl>
This commit is contained in:
Chris Cromer 2019-10-10 23:06:16 -03:00
parent 9f6d6853ad
commit f7adc8551e
23 changed files with 400 additions and 356 deletions

View File

@ -76,9 +76,13 @@ task createDocs {
} }
distributions { distributions {
//noinspection GroovyAssignabilityCheck
main { main {
//noinspection GrUnresolvedAccess
contents { contents {
//noinspection GrUnresolvedAccess
from(createDocs) { from(createDocs) {
//noinspection GrUnresolvedAccess
into 'docs' into 'docs'
} }
} }

View File

@ -21,18 +21,41 @@ import java.util.logging.Logger;
/** /**
* The main class of the game * The main class of the game
*/ */
public class Azaraka implements Constantes { public class Azaraka implements Constants {
/**
* The main window
*/
private MainWindow mainWindow;
/**
* The logger
*/
private final Logger logger;
/** /**
* Initialize the main class * The main game class
*/ */
private Azaraka() { private Azaraka() {
Logger logger = getLogger(this.getClass(), LogLevel.MAIN); logger = getLogger(this.getClass(), LogLevel.MAIN);
start();
}
/**
* Restart the game
*/
public void restart() {
mainWindow.removeAll();
mainWindow.dispose();
start();
}
/**
* Load the main game window to start
*/
private void start() {
logger.info("Load main window"); logger.info("Load main window");
VentanaPrincipal ventanaPrincipal = new VentanaPrincipal(); mainWindow = new MainWindow(this);
ventanaPrincipal.setVisible(true); mainWindow.setVisible(true);
ventanaPrincipal.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
} }
/** /**
@ -41,6 +64,15 @@ public class Azaraka implements Constantes {
* @param args The arguments passed to the application * @param args The arguments passed to the application
*/ */
public static void main(String[] args) { public static void main(String[] args) {
int validCells = (HORIZONTAL_CELLS - 2) * (VERTICAL_CELLS - 2);
validCells = validCells - ENEMIES;
validCells = validCells - (CHESTS * 2);
validCells = validCells - OBSTACLES;
if (validCells < 10) {
// This is to prevent a possible infinite loop
System.out.println("Not enough valid cells: " + validCells + "!");
System.exit(0);
}
new Azaraka(); new Azaraka();
} }

View File

@ -34,7 +34,11 @@ import java.util.logging.Logger;
/** /**
* This class extends the canvas to make drawing and listening easier * This class extends the canvas to make drawing and listening easier
*/ */
public class Lienzo extends Canvas implements Constantes { public class Canvas extends java.awt.Canvas implements Constants {
/**
* The main window
*/
private final Azaraka azaraka;
/** /**
* The current volume * The current volume
*/ */
@ -94,7 +98,7 @@ public class Lienzo extends Canvas implements Constantes {
/** /**
* The game scene * The game scene
*/ */
private Escenario escenario; private Scene scene;
/** /**
* The sound played when a key is picked up * The sound played when a key is picked up
*/ */
@ -155,11 +159,13 @@ public class Lienzo extends Canvas implements Constantes {
/** /**
* Initialize the canvas * Initialize the canvas
* *
* @param azaraka The main window
* @param width The width to set the canvas * @param width The width to set the canvas
* @param height The width to set the canvas * @param height The width to set the canvas
*/ */
public Lienzo(int width, int height) { public Canvas(Azaraka azaraka, int width, int height) {
logger = getLogger(this.getClass(), LogLevel.LIENZO); logger = getLogger(this.getClass(), LogLevel.LIENZO);
this.azaraka = azaraka;
setSize(width, height); setSize(width, height);
leftMargin = (width - CELL_PIXELS * HORIZONTAL_CELLS) / 2; leftMargin = (width - CELL_PIXELS * HORIZONTAL_CELLS) / 2;
@ -185,25 +191,25 @@ public class Lienzo extends Canvas implements Constantes {
gameOverAnimation = new Animation(); gameOverAnimation = new Animation();
gameOverAnimation.addImage(Animation.Direction.NONE, "/img/gameover/gameover.png"); gameOverAnimation.addImage(Animation.Direction.NONE, "/img/gameover/gameover.png");
escenario = new Escenario(this); scene = new Scene(this);
ArrayList<Object> objectList = escenario.generateRandomObjects(); ArrayList<Object> objectList = scene.generateRandomObjects();
while (objectList == null) { while (objectList == null) {
escenario = new Escenario(this); scene = new Scene(this);
objectList = escenario.generateRandomObjects(); objectList = scene.generateRandomObjects();
} }
escenario.setDoorSound(doorSound); scene.setDoorSound(doorSound);
setBackground(Color.black); setBackground(Color.black);
Enemy.Direction enemyDirection = Enemy.Direction.DOWN; Enemy.Direction enemyDirection = Enemy.Direction.DOWN;
// Create the gems and later place them in 2 of the chests // Create the gems and later place them in 2 of the chests
ArrayList<Gem> gems = new ArrayList<>(); ArrayList<Gem> gems = new ArrayList<>();
Gem lifeGem = new Gem(escenario, new Celda(0, 0, 0, 0)); Gem lifeGem = new Gem(scene, new Cell(0, 0, 0, 0));
lifeGem.setSound(getGemSound); lifeGem.setSound(getGemSound);
lifeGem.setType(Gem.Type.LIFE); lifeGem.setType(Gem.Type.LIFE);
Gem deathGem = new Gem(escenario, new Celda(0, 0, 0, 0)); Gem deathGem = new Gem(scene, new Cell(0, 0, 0, 0));
deathGem.setSound(getGemSound); deathGem.setSound(getGemSound);
deathGem.setType(Gem.Type.DEATH); deathGem.setType(Gem.Type.DEATH);
gems.add(lifeGem); gems.add(lifeGem);
@ -211,12 +217,12 @@ public class Lienzo extends Canvas implements Constantes {
for (Object object : objectList) { for (Object object : objectList) {
if (object instanceof Player) { if (object instanceof Player) {
object.getCelda().setObject(object); object.getCell().setObject(object);
player = (Player) object; player = (Player) object;
threads.put(object, new Thread(object)); threads.put(object, new Thread(object));
} }
else if (object instanceof Enemy) { else if (object instanceof Enemy) {
object.getCelda().setObject(object); object.getCell().setObject(object);
if (enemyDirection == Enemy.Direction.UP) { if (enemyDirection == Enemy.Direction.UP) {
enemyDirection = Enemy.Direction.DOWN; enemyDirection = Enemy.Direction.DOWN;
} }
@ -235,12 +241,12 @@ public class Lienzo extends Canvas implements Constantes {
threads.put(object, new Thread(object)); threads.put(object, new Thread(object));
} }
else if (object instanceof Chest) { else if (object instanceof Chest) {
object.getCelda().setObject(object); object.getCell().setObject(object);
((Chest) object).setSound(openChestSound); ((Chest) object).setSound(openChestSound);
if (gems.size() > 0) { if (gems.size() > 0) {
Gem gem = gems.get(0); Gem gem = gems.get(0);
// Place the gem in the cell above the chest, but don't add it to object2 until we are ready to draw it // Place the gem in the cell above the chest, but don't add it to object2 until we are ready to draw it
gem.setCelda(escenario.getCeldas()[object.getCelda().getX()][object.getCelda().getY() - 1]); gem.setCell(scene.getCells()[object.getCell().getX()][object.getCell().getY() - 1]);
threads.put(gem, new Thread(gem)); threads.put(gem, new Thread(gem));
((Chest) object).setGem(gem); ((Chest) object).setGem(gem);
gems.remove(gem); gems.remove(gem);
@ -249,13 +255,13 @@ public class Lienzo extends Canvas implements Constantes {
threads.put(object, new Thread(object)); threads.put(object, new Thread(object));
} }
else if (object instanceof Key) { else if (object instanceof Key) {
object.getCelda().setObjectOnBottom(object); object.getCell().setObjectOnBottom(object);
((Key) object).setSound(getKeySound); ((Key) object).setSound(getKeySound);
keys.add((Key) object); keys.add((Key) object);
threads.put(object, new Thread(object)); threads.put(object, new Thread(object));
} }
else if (object instanceof Portal) { else if (object instanceof Portal) {
object.getCelda().setObjectOnBottom(object); object.getCell().setObjectOnBottom(object);
portal = (Portal) object; portal = (Portal) object;
portal.setSound(portalSound); portal.setSound(portalSound);
threads.put(object, new Thread(object)); threads.put(object, new Thread(object));
@ -293,11 +299,11 @@ public class Lienzo extends Canvas implements Constantes {
// Shuffle the chests so that the AI doesn't open the correct chests on the first go // Shuffle the chests so that the AI doesn't open the correct chests on the first go
Collections.shuffle(chests, new Random(23)); Collections.shuffle(chests, new Random(23));
for (Chest chest : chests) { for (Chest chest : chests) {
player.getAi().addDestination(new State(chest.getCelda().getX(), chest.getCelda().getY() + 1, State.Type.CHEST, null, 1)); player.getAi().addDestination(new State(chest.getCell().getX(), chest.getCell().getY() + 1, State.Type.CHEST, null, 1));
} }
for (Key key : keys) { for (Key key : keys) {
player.getAi().addDestination(new State(key.getCelda().getX(), key.getCelda().getY(), State.Type.KEY, null, 0)); player.getAi().addDestination(new State(key.getCell().getX(), key.getCell().getY(), State.Type.KEY, null, 0));
} }
Thread thread = new Thread(player.getAi()); Thread thread = new Thread(player.getAi());
@ -376,6 +382,16 @@ public class Lienzo extends Canvas implements Constantes {
if (gameOver) { if (gameOver) {
if (!gameOverRan) { if (!gameOverRan) {
addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent event) {
super.keyPressed(event);
if (event.getKeyCode() == KeyEvent.VK_ENTER) {
azaraka.restart();
}
}
});
stopBackgroundMusic(); stopBackgroundMusic();
try { try {
@ -410,7 +426,7 @@ public class Lienzo extends Canvas implements Constantes {
} }
} }
else { else {
escenario.paintComponent(graphicBuffer); scene.paintComponent(graphicBuffer);
if (won) { if (won) {
int alpha = (255 * 75) / 100; // 75% transparent int alpha = (255 * 75) / 100; // 75% transparent
@ -427,6 +443,16 @@ public class Lienzo extends Canvas implements Constantes {
int x = rectangle.x + (rectangle.width - metrics.stringWidth(message)) / 2; int x = rectangle.x + (rectangle.width - metrics.stringWidth(message)) / 2;
int y = rectangle.y + ((rectangle.height - metrics.getHeight()) / 2) + metrics.getAscent(); int y = rectangle.y + ((rectangle.height - metrics.getHeight()) / 2) + metrics.getAscent();
graphicBuffer.drawString(message, x, y); graphicBuffer.drawString(message, x, y);
addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent event) {
super.keyPressed(event);
if (event.getKeyCode() == KeyEvent.VK_ENTER) {
System.exit(0);
}
}
});
} }
} }

View File

@ -27,7 +27,7 @@ import java.util.Map;
/** /**
* This class is a cell that will contain a game element such as a player, enemy, prize, etc * This class is a cell that will contain a game element such as a player, enemy, prize, etc
*/ */
public class Celda extends JComponent implements Constantes { public class Cell extends JComponent implements Constants {
/** /**
* The x graphical coordinate of the cell * The x graphical coordinate of the cell
*/ */
@ -69,7 +69,7 @@ public class Celda extends JComponent implements Constantes {
* @param x The x coordinate of the cell * @param x The x coordinate of the cell
* @param y The y coordinate of the cell * @param y The y coordinate of the cell
*/ */
public Celda(int xPixels, int yPixels, int x, int y) { public Cell(int xPixels, int yPixels, int x, int y) {
this.xPixels = xPixels; this.xPixels = xPixels;
this.yPixels = yPixels; this.yPixels = yPixels;
this.x = x; this.x = x;

View File

@ -29,7 +29,7 @@ import java.util.logging.Logger;
/** /**
* Constants used in the game * Constants used in the game
*/ */
public interface Constantes { public interface Constants {
/** /**
* The name of the game * The name of the game
*/ */
@ -37,7 +37,7 @@ public interface Constantes {
/** /**
* Whether or not the player should be controlled by AI * Whether or not the player should be controlled by AI
*/ */
boolean PLAYER_AI = false; boolean PLAYER_AI = true;
/** /**
* Make logs * Make logs
*/ */
@ -55,11 +55,11 @@ public interface Constantes {
*/ */
int CELL_PIXELS = 64; int CELL_PIXELS = 64;
/** /**
* The number of cells to draw horizontally, minimum 8 * The number of cells to draw horizontally
*/ */
int HORIZONTAL_CELLS = 16; int HORIZONTAL_CELLS = 16;
/** /**
* The number of cells to draw vertically, minimum 8 * The number of cells to draw vertically
*/ */
int VERTICAL_CELLS = 9; int VERTICAL_CELLS = 9;
/** /**

View File

@ -25,12 +25,14 @@ import java.util.logging.Logger;
/** /**
* The main window of the game * The main window of the game
*/ */
public class VentanaPrincipal extends JFrame implements Constantes { public class MainWindow extends JFrame implements Constants {
/** /**
* Initialize the main window * Initialize the main window
*
* @param azaraka The main game class
*/ */
public VentanaPrincipal() { public MainWindow(Azaraka azaraka) {
Logger logger = getLogger(this.getClass(), LogLevel.VENTANA_PRINCIPAL); Logger logger = getLogger(this.getClass(), LogLevel.VENTANA_PRINCIPAL);
logger.info("Create panels"); logger.info("Create panels");
@ -52,7 +54,7 @@ public class VentanaPrincipal extends JFrame implements Constantes {
logger.warning(e.getMessage()); logger.warning(e.getMessage());
} }
Lienzo canvas = new Lienzo(screenSize.width, screenSize.height - 50); Canvas canvas = new Canvas(azaraka, screenSize.width, screenSize.height - 50);
canvas.setFocusable(true); canvas.setFocusable(true);
canvas.requestFocus(); canvas.requestFocus();
add(canvas); add(canvas);

View File

@ -17,7 +17,6 @@ package cl.cromer.azaraka;
import cl.cromer.azaraka.ai.BreadthFirstSearch; import cl.cromer.azaraka.ai.BreadthFirstSearch;
import cl.cromer.azaraka.ai.State; import cl.cromer.azaraka.ai.State;
import cl.cromer.azaraka.json.Cell;
import cl.cromer.azaraka.json.Json; import cl.cromer.azaraka.json.Json;
import cl.cromer.azaraka.object.Object; import cl.cromer.azaraka.object.Object;
import cl.cromer.azaraka.object.*; import cl.cromer.azaraka.object.*;
@ -42,15 +41,15 @@ import java.util.logging.Logger;
/** /**
* The scene used for the game * The scene used for the game
*/ */
public class Escenario extends JComponent implements Constantes { public class Scene extends JComponent implements Constants {
/** /**
* The canvas * The canvas
*/ */
private final Lienzo canvas; private final Canvas canvas;
/** /**
* The cells of the game * The cells of the game
*/ */
private final Celda[][] celdas; private final Cell[][] cells;
/** /**
* The logger * The logger
*/ */
@ -67,22 +66,18 @@ public class Escenario extends JComponent implements Constantes {
* The sound the door makes * The sound the door makes
*/ */
private Sound doorSound; private Sound doorSound;
/**
* The amount of tries before giving up
*/
private int tries = 0;
/** /**
* Initialize the scene * Initialize the scene
* *
* @param canvas The canvas that this scene is in * @param canvas The canvas that this scene is in
*/ */
public Escenario(Lienzo canvas) { public Scene(Canvas canvas) {
logger = getLogger(this.getClass(), LogLevel.ESCENARIO); logger = getLogger(this.getClass(), LogLevel.ESCENARIO);
this.canvas = canvas; this.canvas = canvas;
loadTextures(); loadTextures();
celdas = new Celda[HORIZONTAL_CELLS][VERTICAL_CELLS]; cells = new Cell[HORIZONTAL_CELLS][VERTICAL_CELLS];
if (GENERATE_SCENE) { if (GENERATE_SCENE) {
generateScene(); generateScene();
@ -106,7 +101,7 @@ public class Escenario extends JComponent implements Constantes {
if (EXPORT_SCENE) { if (EXPORT_SCENE) {
Json json = new Json(); Json json = new Json();
json.exportScene(celdas); json.exportScene(cells);
} }
} }
@ -118,37 +113,37 @@ public class Escenario extends JComponent implements Constantes {
private void loadScene(String json) { private void loadScene(String json) {
GsonBuilder gsonBuilder = new GsonBuilder(); GsonBuilder gsonBuilder = new GsonBuilder();
Gson gson = gsonBuilder.create(); Gson gson = gsonBuilder.create();
Cell[][] cells = gson.fromJson(json, Cell[][].class); cl.cromer.azaraka.json.Cell[][] cells = gson.fromJson(json, cl.cromer.azaraka.json.Cell[][].class);
for (int x = 0; x < cells.length; x++) { for (int x = 0; x < cells.length; x++) {
for (int y = 0; y < cells[x].length; y++) { for (int y = 0; y < cells[x].length; y++) {
celdas[x][y] = new Celda((x * CELL_PIXELS) + canvas.getLeftMargin(), (y * CELL_PIXELS) + canvas.getTopMargin(), x, y); this.cells[x][y] = new Cell((x * CELL_PIXELS) + canvas.getLeftMargin(), (y * CELL_PIXELS) + canvas.getTopMargin(), x, y);
if (cells[x][y].type.equals(Player.class.getName())) { if (cells[x][y].type.equals(Player.class.getName())) {
celdas[x][y].setObject(new Player(null, celdas[x][y])); this.cells[x][y].setObject(new Player(null, this.cells[x][y]));
} }
else if (cells[x][y].type.equals(Enemy.class.getName())) { else if (cells[x][y].type.equals(Enemy.class.getName())) {
celdas[x][y].setObject(new Enemy(null, celdas[x][y], null)); this.cells[x][y].setObject(new Enemy(null, this.cells[x][y], null));
} }
else if (cells[x][y].type.equals(Chest.class.getName())) { else if (cells[x][y].type.equals(Chest.class.getName())) {
celdas[x][y].setObject(new Chest(null, celdas[x][y])); this.cells[x][y].setObject(new Chest(null, this.cells[x][y]));
} }
else if (cells[x][y].type.equals(Gem.class.getName())) { else if (cells[x][y].type.equals(Gem.class.getName())) {
celdas[x][y].setObject(new Gem(null, celdas[x][y])); this.cells[x][y].setObject(new Gem(null, this.cells[x][y]));
} }
else if (cells[x][y].type.equals(Key.class.getName())) { else if (cells[x][y].type.equals(Key.class.getName())) {
celdas[x][y].setObject(new Key(null, celdas[x][y])); this.cells[x][y].setObject(new Key(null, this.cells[x][y]));
} }
else if (cells[x][y].type.equals(Obstacle.class.getName())) { else if (cells[x][y].type.equals(Obstacle.class.getName())) {
celdas[x][y].setObject(new Obstacle(null, celdas[x][y])); this.cells[x][y].setObject(new Obstacle(null, this.cells[x][y]));
} }
else if (cells[x][y].type.equals(Portal.class.getName())) { else if (cells[x][y].type.equals(Portal.class.getName())) {
celdas[x][y].setObject(new Portal(null, celdas[x][y])); this.cells[x][y].setObject(new Portal(null, this.cells[x][y]));
} }
for (int k = 0; k < cells[x][y].textures.size(); k++) { for (int k = 0; k < cells[x][y].textures.size(); k++) {
try { try {
celdas[x][y].addTexture(textureSheet.getTexture(cells[x][y].textures.get(k)), cells[x][y].textures.get(k)); this.cells[x][y].addTexture(textureSheet.getTexture(cells[x][y].textures.get(k)), cells[x][y].textures.get(k));
} }
catch (SheetException e) { catch (SheetException e) {
logger.warning(e.getMessage()); logger.warning(e.getMessage());
@ -168,17 +163,15 @@ public class Escenario extends JComponent implements Constantes {
ArrayList<Object> objectArrayList = new ArrayList<>(); ArrayList<Object> objectArrayList = new ArrayList<>();
// The player has a fixed position // The player has a fixed position
celdas[2][1].setObject(new Player(this, celdas[2][1])); cells[2][1].setObject(new Player(this, cells[2][1]));
objectArrayList.add(celdas[2][1].getObject()); objectArrayList.add(cells[2][1].getObject());
for (int i = 0; i < OBSTACLES; i++) { for (int i = 0; i < OBSTACLES; i++) {
random = randomCoordinates(false); random = randomCoordinates();
if (random[0] == -1 || random[1] == -1) { cells[random[0]][random[1]].setObject(new Obstacle(this, cells[random[0]][random[1]]));
return null; objectArrayList.add(cells[random[0]][random[1]].getObject());
}
celdas[random[0]][random[1]].setObject(new Obstacle(this, celdas[random[0]][random[1]]));
try { try {
celdas[random[0]][random[1]].addTexture(textureSheet.getTexture(30), 30); cells[random[0]][random[1]].addTexture(textureSheet.getTexture(30), 30);
} }
catch (SheetException e) { catch (SheetException e) {
logger.warning(e.getMessage()); logger.warning(e.getMessage());
@ -187,105 +180,90 @@ public class Escenario extends JComponent implements Constantes {
final Lock lock = new ReentrantLock(true); final Lock lock = new ReentrantLock(true);
for (int i = 0; i < ENEMIES; i++) { for (int i = 0; i < ENEMIES; i++) {
random = randomCoordinates(true); random = randomCoordinates();
if (random[0] == -1 || random[1] == -1) { cells[random[0]][random[1]].setObject(new Enemy(this, cells[random[0]][random[1]], lock));
return null; objectArrayList.add(cells[random[0]][random[1]].getObject());
}
celdas[random[0]][random[1]].setObject(new Enemy(this, celdas[random[0]][random[1]], lock));
objectArrayList.add(celdas[random[0]][random[1]].getObject());
} }
random = randomCoordinates(true); random = randomCoordinates();
if (random[0] == -1 || random[1] == -1) { cells[random[0]][random[1]].setObjectOnBottom(new Portal(this, cells[random[0]][random[1]]));
return null; objectArrayList.add(cells[random[0]][random[1]].getObjectOnBottom());
}
celdas[random[0]][random[1]].setObjectOnBottom(new Portal(this, celdas[random[0]][random[1]]));
objectArrayList.add(celdas[random[0]][random[1]].getObjectOnBottom());
// Generate enough keys for the chests that will exist // Generate enough keys for the chests that will exist
for (int i = 0; i < CHESTS; i++) { for (int i = 0; i < CHESTS; i++) {
random = randomCoordinates(true); random = randomCoordinates();
if (random[0] == -1 || random[1] == -1) { cells[random[0]][random[1]].setObjectOnBottom(new Key(this, cells[random[0]][random[1]]));
return null; objectArrayList.add(cells[random[0]][random[1]].getObjectOnBottom());
}
celdas[random[0]][random[1]].setObjectOnBottom(new Key(this, celdas[random[0]][random[1]]));
objectArrayList.add(celdas[random[0]][random[1]].getObjectOnBottom());
} }
// Chests need to be last to make sure they are openable // Chests need to be last to make sure they are openable
for (int i = 0; i < CHESTS; i++) { for (int i = 0; i < CHESTS; i++) {
tries = 0;
int random_x = random(0, HORIZONTAL_CELLS - 1); int random_x = random(0, HORIZONTAL_CELLS - 1);
int random_y = random(0, VERTICAL_CELLS - 1); int random_y = random(0, VERTICAL_CELLS - 1);
// Don't put a chest if it can't be opened // Don't put a chest if it can't be opened
while (random_y + 1 == VERTICAL_CELLS || while (random_y + 1 == VERTICAL_CELLS ||
celdas[random_x][random_y].containsObject() || cells[random_x][random_y].containsObject() ||
celdas[random_x][random_y + 1].containsObject() || cells[random_x][random_y + 1].containsObject()) {
celdas[random_x][random_y - 1].containsObject() ||
checkBreadthFirst(random_x, random_y + 1)) {
random_x = random(0, HORIZONTAL_CELLS - 1); random_x = random(0, HORIZONTAL_CELLS - 1);
random_y = random(0, VERTICAL_CELLS - 1); random_y = random(0, VERTICAL_CELLS - 1);
tries++;
if (tries == HORIZONTAL_CELLS) {
random[0] = -1;
random[1] = -1;
break;
} }
cells[random_x][random_y].setObject(new Chest(this, cells[random_x][random_y]));
objectArrayList.add(cells[random_x][random_y].getObject());
} }
if (random[0] == -1 || random[1] == -1) {
for (Object object : objectArrayList) {
if (object instanceof Chest) {
int x = object.getCell().getX();
int y = object.getCell().getY();
if (pathInvalid(x, y + 1)) {
return null; return null;
} }
celdas[random_x][random_y].setObjectOnBottom(new Chest(this, celdas[random_x][random_y])); }
objectArrayList.add(celdas[random_x][random_y].getObjectOnBottom()); else if (object instanceof Portal || object instanceof Key) {
int x = object.getCell().getX();
int y = object.getCell().getY();
if (pathInvalid(x, y)) {
return null;
}
}
} }
return objectArrayList; return objectArrayList;
} }
/**
* Check if the path to the objective is valid
*
* @param x The x coordinate of the objective
* @param y The y coordinate of the objective
* @return Returns true if valid or false otherwise
*/
private boolean pathInvalid(int x, int y) {
BreadthFirstSearch breadthFirstSearch = new BreadthFirstSearch(this);
State playerState = new State(2, 1, State.Type.START, null, 0);
State objectiveState = new State(x, y, State.Type.EXIT, null, 0);
return !breadthFirstSearch.search(playerState, objectiveState);
}
/** /**
* Get random x and y coordinates * Get random x and y coordinates
* *
* @param checkPath Check if the path can be reached using AI
* @return Returns an array with the coordinates * @return Returns an array with the coordinates
*/ */
private int[] randomCoordinates(boolean checkPath) { private int[] randomCoordinates() {
tries = 0;
int[] random = new int[2]; int[] random = new int[2];
random[0] = random(0, HORIZONTAL_CELLS - 1); random[0] = random(0, HORIZONTAL_CELLS - 1);
random[1] = random(0, VERTICAL_CELLS - 1); random[1] = random(0, VERTICAL_CELLS - 1);
// If the cell is not empty look for another // If the cell is not empty look for another
// If the cell is not reachable by the player look for another // If the cell is not reachable by the player look for another
// If the player can't reach the bottom right corner look for another // If the player can't reach the bottom right corner look for another
while (celdas[random[0]][random[1]].containsObject() || (checkPath && checkBreadthFirst(random[0], random[1]))) { while (cells[random[0]][random[1]].containsObject()) {
random[0] = random(0, HORIZONTAL_CELLS - 1); random[0] = random(0, HORIZONTAL_CELLS - 1);
random[1] = random(0, VERTICAL_CELLS - 1); random[1] = random(0, VERTICAL_CELLS - 1);
tries++;
if (tries == VERTICAL_CELLS) {
random[0] = -1;
random[1] = -1;
break;
}
} }
return random; return random;
} }
/**
* Check the path using BreadFirst-Search
*
* @param x The x position to check
* @param y The y position to check
* @return Returns true if the object is reachable or false otherwise
*/
private boolean checkBreadthFirst(int x, int y) {
BreadthFirstSearch breadthFirstSearch = new BreadthFirstSearch(this);
return (!breadthFirstSearch.search(
new State(2, 1, State.Type.START, null, 0),
new State(x, y, State.Type.EXIT, null, 0)) ||
!breadthFirstSearch.search(
new State(2, 1, State.Type.START, null, 0),
new State(HORIZONTAL_CELLS - 2, VERTICAL_CELLS - 2, State.Type.EXIT, null, 0)));
}
/** /**
* Generate the scene manually without the JSON file * Generate the scene manually without the JSON file
*/ */
@ -293,9 +271,9 @@ public class Escenario extends JComponent implements Constantes {
for (int x = 0; x < HORIZONTAL_CELLS; x++) { for (int x = 0; x < HORIZONTAL_CELLS; x++) {
for (int y = 0; y < VERTICAL_CELLS; y++) { for (int y = 0; y < VERTICAL_CELLS; y++) {
logger.info("Generate cell x: " + x + " y: " + y + " manually"); logger.info("Generate cell x: " + x + " y: " + y + " manually");
celdas[x][y] = new Celda((x * CELL_PIXELS) + canvas.getLeftMargin(), (y * CELL_PIXELS) + canvas.getTopMargin(), x, y); cells[x][y] = new Cell((x * CELL_PIXELS) + canvas.getLeftMargin(), (y * CELL_PIXELS) + canvas.getTopMargin(), x, y);
try { try {
celdas[x][y].addTexture(textureSheet.getTexture(0), 0); cells[x][y].addTexture(textureSheet.getTexture(0), 0);
} }
catch (SheetException e) { catch (SheetException e) {
logger.warning(e.getMessage()); logger.warning(e.getMessage());
@ -303,9 +281,9 @@ public class Escenario extends JComponent implements Constantes {
if (x == 0 && y == 0) { if (x == 0 && y == 0) {
// Top left corner // Top left corner
celdas[x][y].setObject(new Obstacle(this, celdas[x][y])); cells[x][y].setObject(new Obstacle(this, cells[x][y]));
try { try {
celdas[x][y].addTexture(textureSheet.getTexture(33), 33); cells[x][y].addTexture(textureSheet.getTexture(33), 33);
} }
catch (SheetException e) { catch (SheetException e) {
logger.warning(e.getMessage()); logger.warning(e.getMessage());
@ -313,9 +291,9 @@ public class Escenario extends JComponent implements Constantes {
} }
else if (x == HORIZONTAL_CELLS - 1 && y == 0) { else if (x == HORIZONTAL_CELLS - 1 && y == 0) {
// Top right corner // Top right corner
celdas[x][y].setObject(new Obstacle(this, celdas[x][y])); cells[x][y].setObject(new Obstacle(this, cells[x][y]));
try { try {
celdas[x][y].addTexture(textureSheet.getTexture(37), 37); cells[x][y].addTexture(textureSheet.getTexture(37), 37);
} }
catch (SheetException e) { catch (SheetException e) {
logger.warning(e.getMessage()); logger.warning(e.getMessage());
@ -323,9 +301,9 @@ public class Escenario extends JComponent implements Constantes {
} }
else if (x == 0 && y == VERTICAL_CELLS - 1) { else if (x == 0 && y == VERTICAL_CELLS - 1) {
// Bottom left corner // Bottom left corner
celdas[x][y].setObject(new Obstacle(this, celdas[x][y])); cells[x][y].setObject(new Obstacle(this, cells[x][y]));
try { try {
celdas[x][y].addTexture(textureSheet.getTexture(97), 97); cells[x][y].addTexture(textureSheet.getTexture(97), 97);
} }
catch (SheetException e) { catch (SheetException e) {
logger.warning(e.getMessage()); logger.warning(e.getMessage());
@ -333,9 +311,9 @@ public class Escenario extends JComponent implements Constantes {
} }
else if (x == HORIZONTAL_CELLS - 1 && y == VERTICAL_CELLS - 1) { else if (x == HORIZONTAL_CELLS - 1 && y == VERTICAL_CELLS - 1) {
// Bottom right corner // Bottom right corner
celdas[x][y].setObject(new Obstacle(this, celdas[x][y])); cells[x][y].setObject(new Obstacle(this, cells[x][y]));
try { try {
celdas[x][y].addTexture(textureSheet.getTexture(101), 101); cells[x][y].addTexture(textureSheet.getTexture(101), 101);
} }
catch (SheetException e) { catch (SheetException e) {
logger.warning(e.getMessage()); logger.warning(e.getMessage());
@ -343,12 +321,12 @@ public class Escenario extends JComponent implements Constantes {
} }
else if (y == 0) { else if (y == 0) {
// Top wall // Top wall
celdas[x][y].setObject(new Obstacle(this, celdas[x][y])); cells[x][y].setObject(new Obstacle(this, cells[x][y]));
if (x == 1) { if (x == 1) {
// Left door frame // Left door frame
try { try {
celdas[x][y].addTexture(textureSheet.getTexture(144), 144); cells[x][y].addTexture(textureSheet.getTexture(144), 144);
celdas[x][y].addTexture(textureSheet.getTexture(192), 192); cells[x][y].addTexture(textureSheet.getTexture(192), 192);
} }
catch (SheetException e) { catch (SheetException e) {
logger.warning(e.getMessage()); logger.warning(e.getMessage());
@ -357,7 +335,7 @@ public class Escenario extends JComponent implements Constantes {
else if (x == 2) { else if (x == 2) {
// Door // Door
try { try {
celdas[x][y].addTexture(textureSheet.getTexture(145), 145); cells[x][y].addTexture(textureSheet.getTexture(145), 145);
} }
catch (SheetException e) { catch (SheetException e) {
logger.warning(e.getMessage()); logger.warning(e.getMessage());
@ -366,8 +344,8 @@ public class Escenario extends JComponent implements Constantes {
else if (x == 3) { else if (x == 3) {
// Right door frame // Right door frame
try { try {
celdas[x][y].addTexture(textureSheet.getTexture(146), 146); cells[x][y].addTexture(textureSheet.getTexture(146), 146);
celdas[x][y].addTexture(textureSheet.getTexture(194), 194); cells[x][y].addTexture(textureSheet.getTexture(194), 194);
} }
catch (SheetException e) { catch (SheetException e) {
logger.warning(e.getMessage()); logger.warning(e.getMessage());
@ -376,7 +354,7 @@ public class Escenario extends JComponent implements Constantes {
else if (x == 8) { else if (x == 8) {
// Broken wall piece // Broken wall piece
try { try {
celdas[x][y].addTexture(textureSheet.getTexture(105), 105); cells[x][y].addTexture(textureSheet.getTexture(105), 105);
} }
catch (SheetException e) { catch (SheetException e) {
logger.warning(e.getMessage()); logger.warning(e.getMessage());
@ -384,8 +362,8 @@ public class Escenario extends JComponent implements Constantes {
} }
else if (x % 2 == 0) { else if (x % 2 == 0) {
try { try {
celdas[x][y].addTexture(textureSheet.getTexture(34), 34); cells[x][y].addTexture(textureSheet.getTexture(34), 34);
celdas[x][y].addTexture(textureSheet.getTexture(222), 222); cells[x][y].addTexture(textureSheet.getTexture(222), 222);
} }
catch (SheetException e) { catch (SheetException e) {
logger.warning(e.getMessage()); logger.warning(e.getMessage());
@ -393,7 +371,7 @@ public class Escenario extends JComponent implements Constantes {
} }
else { else {
try { try {
celdas[x][y].addTexture(textureSheet.getTexture(35), 35); cells[x][y].addTexture(textureSheet.getTexture(35), 35);
} }
catch (SheetException e) { catch (SheetException e) {
logger.warning(e.getMessage()); logger.warning(e.getMessage());
@ -402,11 +380,11 @@ public class Escenario extends JComponent implements Constantes {
} }
else if (x == 0) { else if (x == 0) {
// Left wall // Left wall
celdas[x][y].setObject(new Obstacle(this, celdas[x][y])); cells[x][y].setObject(new Obstacle(this, cells[x][y]));
if (y % 2 == 0) { if (y % 2 == 0) {
try { try {
celdas[x][y].addTexture(textureSheet.getTexture(49), 49); cells[x][y].addTexture(textureSheet.getTexture(49), 49);
celdas[x][y].addTexture(textureSheet.getTexture(255), 255); cells[x][y].addTexture(textureSheet.getTexture(255), 255);
} }
catch (SheetException e) { catch (SheetException e) {
logger.warning(e.getMessage()); logger.warning(e.getMessage());
@ -414,7 +392,7 @@ public class Escenario extends JComponent implements Constantes {
} }
else { else {
try { try {
celdas[x][y].addTexture(textureSheet.getTexture(65), 65); cells[x][y].addTexture(textureSheet.getTexture(65), 65);
} }
catch (SheetException e) { catch (SheetException e) {
logger.warning(e.getMessage()); logger.warning(e.getMessage());
@ -423,11 +401,11 @@ public class Escenario extends JComponent implements Constantes {
} }
else if (x == HORIZONTAL_CELLS - 1) { else if (x == HORIZONTAL_CELLS - 1) {
// Right wall // Right wall
celdas[x][y].setObject(new Obstacle(this, celdas[x][y])); cells[x][y].setObject(new Obstacle(this, cells[x][y]));
if (y % 2 == 0) { if (y % 2 == 0) {
try { try {
celdas[x][y].addTexture(textureSheet.getTexture(53), 53); cells[x][y].addTexture(textureSheet.getTexture(53), 53);
celdas[x][y].addTexture(textureSheet.getTexture(238), 238); cells[x][y].addTexture(textureSheet.getTexture(238), 238);
} }
catch (SheetException e) { catch (SheetException e) {
logger.warning(e.getMessage()); logger.warning(e.getMessage());
@ -435,7 +413,7 @@ public class Escenario extends JComponent implements Constantes {
} }
else { else {
try { try {
celdas[x][y].addTexture(textureSheet.getTexture(69), 69); cells[x][y].addTexture(textureSheet.getTexture(69), 69);
} }
catch (SheetException e) { catch (SheetException e) {
logger.warning(e.getMessage()); logger.warning(e.getMessage());
@ -444,11 +422,11 @@ public class Escenario extends JComponent implements Constantes {
} }
else if (y == VERTICAL_CELLS - 1) { else if (y == VERTICAL_CELLS - 1) {
// Bottom wall // Bottom wall
celdas[x][y].setObject(new Obstacle(this, celdas[x][y])); cells[x][y].setObject(new Obstacle(this, cells[x][y]));
if (x % 2 == 0) { if (x % 2 == 0) {
try { try {
celdas[x][y].addTexture(textureSheet.getTexture(98), 98); cells[x][y].addTexture(textureSheet.getTexture(98), 98);
celdas[x][y].addTexture(textureSheet.getTexture(207), 207); cells[x][y].addTexture(textureSheet.getTexture(207), 207);
} }
catch (SheetException e) { catch (SheetException e) {
logger.warning(e.getMessage()); logger.warning(e.getMessage());
@ -456,7 +434,7 @@ public class Escenario extends JComponent implements Constantes {
} }
else { else {
try { try {
celdas[x][y].addTexture(textureSheet.getTexture(99), 99); cells[x][y].addTexture(textureSheet.getTexture(99), 99);
} }
catch (SheetException e) { catch (SheetException e) {
logger.warning(e.getMessage()); logger.warning(e.getMessage());
@ -484,8 +462,8 @@ public class Escenario extends JComponent implements Constantes {
* *
* @return Returns a matrix of the cells of the game * @return Returns a matrix of the cells of the game
*/ */
public Celda[][] getCeldas() { public Cell[][] getCells() {
return celdas; return cells;
} }
/** /**
@ -507,7 +485,7 @@ public class Escenario extends JComponent implements Constantes {
public void update(Graphics g) { public void update(Graphics g) {
for (int i = 0; i < HORIZONTAL_CELLS; i++) { for (int i = 0; i < HORIZONTAL_CELLS; i++) {
for (int j = 0; j < VERTICAL_CELLS; j++) { for (int j = 0; j < VERTICAL_CELLS; j++) {
celdas[i][j].paintComponent(g); cells[i][j].paintComponent(g);
} }
} }
} }
@ -517,7 +495,7 @@ public class Escenario extends JComponent implements Constantes {
* *
* @return Returns the parent canvas * @return Returns the parent canvas
*/ */
public Lienzo getCanvas() { public Canvas getCanvas() {
return canvas; return canvas;
} }
@ -559,9 +537,9 @@ public class Escenario extends JComponent implements Constantes {
*/ */
public void openDoor(boolean doorOpen) { public void openDoor(boolean doorOpen) {
if (!doorOpen && isDoorOpen()) { if (!doorOpen && isDoorOpen()) {
celdas[2][0].setObject(new Obstacle(this, celdas[2][0])); cells[2][0].setObject(new Obstacle(this, cells[2][0]));
try { try {
celdas[2][0].addTexture(textureSheet.getTexture(193), 193); cells[2][0].addTexture(textureSheet.getTexture(193), 193);
} }
catch (SheetException e) { catch (SheetException e) {
logger.warning(e.getMessage()); logger.warning(e.getMessage());
@ -570,8 +548,8 @@ public class Escenario extends JComponent implements Constantes {
playDoorSound(); playDoorSound();
} }
else if (doorOpen && !isDoorOpen()) { else if (doorOpen && !isDoorOpen()) {
celdas[2][0].removeTexture(193); cells[2][0].removeTexture(193);
celdas[2][0].setObject(null); cells[2][0].setObject(null);
this.doorOpen = true; this.doorOpen = true;
playDoorSound(); playDoorSound();
} }

View File

@ -15,7 +15,7 @@
package cl.cromer.azaraka.ai; package cl.cromer.azaraka.ai;
import cl.cromer.azaraka.Escenario; import cl.cromer.azaraka.Scene;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -26,7 +26,7 @@ public class AI implements Runnable {
/** /**
* The scene of the game * The scene of the game
*/ */
private final Escenario escenario; private final Scene scene;
/** /**
* The logger * The logger
*/ */
@ -39,10 +39,10 @@ public class AI implements Runnable {
/** /**
* Initialize the AI * Initialize the AI
* *
* @param escenario The scene of the game * @param scene The scene of the game
*/ */
protected AI(Escenario escenario) { protected AI(Scene scene) {
this.escenario = escenario; this.scene = scene;
} }
/** /**
@ -50,8 +50,8 @@ public class AI implements Runnable {
* *
* @return Returns the scene * @return Returns the scene
*/ */
protected Escenario getEscenario() { protected Scene getScene() {
return escenario; return scene;
} }
/** /**

View File

@ -15,8 +15,8 @@
package cl.cromer.azaraka.ai; package cl.cromer.azaraka.ai;
import cl.cromer.azaraka.Constantes; import cl.cromer.azaraka.Constants;
import cl.cromer.azaraka.Escenario; import cl.cromer.azaraka.Scene;
import java.awt.geom.Point2D; import java.awt.geom.Point2D;
import java.util.ArrayList; import java.util.ArrayList;
@ -24,7 +24,7 @@ import java.util.ArrayList;
/** /**
* This is an implementation of the Breadth-First search algorithm with multiple objectives * This is an implementation of the Breadth-First search algorithm with multiple objectives
*/ */
public class BreadthFirstSearch extends AI implements Constantes { public class BreadthFirstSearch extends AI implements Constants {
/** /**
* The queued states to check * The queued states to check
*/ */
@ -57,10 +57,10 @@ public class BreadthFirstSearch extends AI implements Constantes {
/** /**
* Initialize the algorithm * Initialize the algorithm
* *
* @param escenario The scene the AI is in * @param scene The scene the AI is in
*/ */
public BreadthFirstSearch(Escenario escenario) { public BreadthFirstSearch(Scene scene) {
super(escenario); super(scene);
setLogger(getLogger(this.getClass(), LogLevel.AI)); setLogger(getLogger(this.getClass(), LogLevel.AI));
} }
@ -99,6 +99,8 @@ public class BreadthFirstSearch extends AI implements Constantes {
} }
} }
// TODO: remove escenario from the algorithm
/** /**
* Move up if possible * Move up if possible
* *
@ -106,7 +108,7 @@ public class BreadthFirstSearch extends AI implements Constantes {
*/ */
private void moveUp(State state) { private void moveUp(State state) {
if (state.getY() > 0) { if (state.getY() > 0) {
if (getEscenario().getCeldas()[state.getX()][state.getY() - 1].getObject() == null) { if (getScene().getCells()[state.getX()][state.getY() - 1].getObject() == null) {
State up = new State(state.getX(), state.getY() - 1, State.Type.UP, state, state.getImportance()); State up = new State(state.getX(), state.getY() - 1, State.Type.UP, state, state.getImportance());
if (!history.contains(up)) { if (!history.contains(up)) {
queuedStates.add(up); queuedStates.add(up);
@ -128,7 +130,7 @@ public class BreadthFirstSearch extends AI implements Constantes {
*/ */
private void moveDown(State state) { private void moveDown(State state) {
if (state.getY() < VERTICAL_CELLS - 1) { if (state.getY() < VERTICAL_CELLS - 1) {
if (getEscenario().getCeldas()[state.getX()][state.getY() + 1].getObject() == null) { if (getScene().getCells()[state.getX()][state.getY() + 1].getObject() == null) {
State down = new State(state.getX(), state.getY() + 1, State.Type.DOWN, state, state.getImportance()); State down = new State(state.getX(), state.getY() + 1, State.Type.DOWN, state, state.getImportance());
if (!history.contains(down)) { if (!history.contains(down)) {
queuedStates.add(down); queuedStates.add(down);
@ -150,7 +152,7 @@ public class BreadthFirstSearch extends AI implements Constantes {
*/ */
private void moveLeft(State state) { private void moveLeft(State state) {
if (state.getX() > 0) { if (state.getX() > 0) {
if (getEscenario().getCeldas()[state.getX() - 1][state.getY()].getObject() == null) { if (getScene().getCells()[state.getX() - 1][state.getY()].getObject() == null) {
State left = new State(state.getX() - 1, state.getY(), State.Type.LEFT, state, state.getImportance()); State left = new State(state.getX() - 1, state.getY(), State.Type.LEFT, state, state.getImportance());
if (!history.contains(left)) { if (!history.contains(left)) {
queuedStates.add(left); queuedStates.add(left);
@ -172,7 +174,7 @@ public class BreadthFirstSearch extends AI implements Constantes {
*/ */
private void moveRight(State state) { private void moveRight(State state) {
if (state.getX() < HORIZONTAL_CELLS - 1) { if (state.getX() < HORIZONTAL_CELLS - 1) {
if (getEscenario().getCeldas()[state.getX() + 1][state.getY()].getObject() == null) { if (getScene().getCells()[state.getX() + 1][state.getY()].getObject() == null) {
State right = new State(state.getX() + 1, state.getY(), State.Type.RIGHT, state, state.getImportance()); State right = new State(state.getX() + 1, state.getY(), State.Type.RIGHT, state, state.getImportance());
if (!history.contains(right)) { if (!history.contains(right)) {
queuedStates.add(right); queuedStates.add(right);

View File

@ -15,7 +15,7 @@
package cl.cromer.azaraka.ai; package cl.cromer.azaraka.ai;
import cl.cromer.azaraka.Escenario; import cl.cromer.azaraka.Scene;
import cl.cromer.azaraka.object.Player; import cl.cromer.azaraka.object.Player;
import cl.cromer.azaraka.object.Portal; import cl.cromer.azaraka.object.Portal;
import cl.cromer.azaraka.sprite.Animation; import cl.cromer.azaraka.sprite.Animation;
@ -34,11 +34,11 @@ public class PlayerAI extends BreadthFirstSearch {
/** /**
* Initialize the algorithm * Initialize the algorithm
* *
* @param escenario The scene the AI is in * @param scene The scene the AI is in
* @param player The player controlled by the AI * @param player The player controlled by the AI
*/ */
public PlayerAI(Escenario escenario, Player player) { public PlayerAI(Scene scene, Player player) {
super(escenario); super(scene);
this.player = player; this.player = player;
} }
@ -57,9 +57,9 @@ public class PlayerAI extends BreadthFirstSearch {
player.keyPressed(KeyEvent.VK_UP); player.keyPressed(KeyEvent.VK_UP);
} }
player.interact(); player.interact();
Portal portal = getEscenario().getCanvas().getPortal(); Portal portal = getScene().getCanvas().getPortal();
if (portal.getState() == Portal.State.ACTIVE) { if (portal.getState() == Portal.State.ACTIVE) {
addDestination(new State(portal.getCelda().getX(), portal.getCelda().getY(), State.Type.PORTAL, null, 2)); addDestination(new State(portal.getCell().getX(), portal.getCell().getY(), State.Type.PORTAL, null, 2));
} }
return true; return true;
} }
@ -70,7 +70,7 @@ public class PlayerAI extends BreadthFirstSearch {
case KEY: case KEY:
return true; return true;
case PORTAL: case PORTAL:
if (player.hasTaintedGem() && getEscenario().getCanvas().getPortal().getState() == Portal.State.ACTIVE) { if (player.hasTaintedGem() && getScene().getCanvas().getPortal().getState() == Portal.State.ACTIVE) {
return true; return true;
} }
break; break;
@ -101,13 +101,13 @@ public class PlayerAI extends BreadthFirstSearch {
break; break;
case PORTAL: case PORTAL:
// If the portal is active head towards it // If the portal is active head towards it
if (player.hasTaintedGem() && getEscenario().getCanvas().getPortal().getState() == Portal.State.ACTIVE) { if (player.hasTaintedGem() && getScene().getCanvas().getPortal().getState() == Portal.State.ACTIVE) {
return true; return true;
} }
break; break;
case EXIT: case EXIT:
// If the door is open head to it // If the door is open head to it
if (getEscenario().isDoorOpen()) { if (getScene().isDoorOpen()) {
return true; return true;
} }
break; break;
@ -137,7 +137,7 @@ public class PlayerAI extends BreadthFirstSearch {
} }
} }
getEscenario().getCanvas().repaint(); getScene().getCanvas().repaint();
} }
/** /**
@ -145,6 +145,6 @@ public class PlayerAI extends BreadthFirstSearch {
*/ */
@Override @Override
public void getNewInitial() { public void getNewInitial() {
setInitial(new State(player.getCelda().getX(), player.getCelda().getY(), State.Type.START, null, 0)); setInitial(new State(player.getCell().getX(), player.getCell().getY(), State.Type.START, null, 0));
} }
} }

View File

@ -38,7 +38,7 @@ public class State {
/** /**
* The importance of the objective, higher is more important * The importance of the objective, higher is more important
*/ */
private int importance; private final int importance;
/** /**
* Initialize the state * Initialize the state

View File

@ -15,8 +15,8 @@
package cl.cromer.azaraka.json; package cl.cromer.azaraka.json;
import cl.cromer.azaraka.Celda; import cl.cromer.azaraka.Cell;
import cl.cromer.azaraka.Constantes; import cl.cromer.azaraka.Constants;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
@ -28,7 +28,7 @@ import java.util.logging.Logger;
/** /**
* This class handles reading and writing of JSON objects * This class handles reading and writing of JSON objects
*/ */
public class Json implements Constantes { public class Json implements Constants {
/** /**
* The logger * The logger
*/ */
@ -46,11 +46,11 @@ public class Json implements Constantes {
* *
* @param celdas The cells of the scene to export * @param celdas The cells of the scene to export
*/ */
public void exportScene(Celda[][] celdas) { public void exportScene(Cell[][] celdas) {
Cell[][] cells = new Cell[celdas.length][celdas[0].length]; cl.cromer.azaraka.json.Cell[][] cells = new cl.cromer.azaraka.json.Cell[celdas.length][celdas[0].length];
for (int x = 0; x < celdas.length; x++) { for (int x = 0; x < celdas.length; x++) {
for (int y = 0; y < celdas[x].length; y++) { for (int y = 0; y < celdas[x].length; y++) {
cells[x][y] = new Cell(); cells[x][y] = new cl.cromer.azaraka.json.Cell();
if (celdas[x][y].getObject() != null) { if (celdas[x][y].getObject() != null) {
cells[x][y].type = celdas[x][y].getObject().getClass().getName(); cells[x][y].type = celdas[x][y].getObject().getClass().getName();
} }
@ -68,7 +68,7 @@ public class Json implements Constantes {
* *
* @param cells The JSON cells object * @param cells The JSON cells object
*/ */
private void writeScene(Cell[][] cells) { private void writeScene(cl.cromer.azaraka.json.Cell[][] cells) {
GsonBuilder gsonBuilder; GsonBuilder gsonBuilder;
if (PRETTY_JSON) { if (PRETTY_JSON) {
gsonBuilder = new GsonBuilder().setPrettyPrinting(); gsonBuilder = new GsonBuilder().setPrettyPrinting();

View File

@ -15,9 +15,9 @@
package cl.cromer.azaraka.object; package cl.cromer.azaraka.object;
import cl.cromer.azaraka.Celda; import cl.cromer.azaraka.Cell;
import cl.cromer.azaraka.Constantes; import cl.cromer.azaraka.Constants;
import cl.cromer.azaraka.Escenario; import cl.cromer.azaraka.Scene;
import cl.cromer.azaraka.sound.Sound; import cl.cromer.azaraka.sound.Sound;
import cl.cromer.azaraka.sound.SoundException; import cl.cromer.azaraka.sound.SoundException;
import cl.cromer.azaraka.sprite.Animation; import cl.cromer.azaraka.sprite.Animation;
@ -28,7 +28,7 @@ import cl.cromer.azaraka.sprite.SheetException;
/** /**
* This class handles the chests * This class handles the chests
*/ */
public class Chest extends Object implements Constantes { public class Chest extends Object implements Constants {
/** /**
* The current state of the chest * The current state of the chest
*/ */
@ -49,11 +49,11 @@ public class Chest extends Object implements Constantes {
/** /**
* Initialize the chest * Initialize the chest
* *
* @param escenario The scene the chest is in * @param scene The scene the chest is in
* @param celda The cell that contains the chest * @param cell The cell that contains the chest
*/ */
public Chest(Escenario escenario, Celda celda) { public Chest(Scene scene, Cell cell) {
super(escenario, celda); super(scene, cell);
setLogger(getLogger(this.getClass(), LogLevel.CHEST)); setLogger(getLogger(this.getClass(), LogLevel.CHEST));
loadChestAnimation(); loadChestAnimation();
@ -109,7 +109,7 @@ public class Chest extends Object implements Constantes {
catch (AnimationException e) { catch (AnimationException e) {
getLogger().warning(e.getMessage()); getLogger().warning(e.getMessage());
} }
getEscenario().getCanvas().repaint(); getScene().getCanvas().repaint();
} }
} }
@ -136,7 +136,7 @@ public class Chest extends Object implements Constantes {
*/ */
private void playChestOpenSound() { private void playChestOpenSound() {
try { try {
sound.setVolume(getEscenario().getCanvas().getVolume()); sound.setVolume(getScene().getCanvas().getVolume());
sound.play(); sound.play();
} }
catch (SoundException e) { catch (SoundException e) {
@ -188,19 +188,19 @@ public class Chest extends Object implements Constantes {
gemLoops--; gemLoops--;
} }
else if (gemLoops == 0) { else if (gemLoops == 0) {
gem.getCelda().setObjectOnTop(null); gem.getCell().setObjectOnTop(null);
gem.setYScale(24); gem.setYScale(24);
gem.setXScale(24); gem.setXScale(24);
gem.setUseOffset(false); gem.setUseOffset(false);
getEscenario().getCanvas().getPlayer().addInventory(gem); getScene().getCanvas().getPlayer().addInventory(gem);
getEscenario().getCanvas().getPortal().setState(Portal.State.ACTIVE); getScene().getCanvas().getPortal().setState(Portal.State.ACTIVE);
gemLoops--; gemLoops--;
} }
} }
} }
else if (state == State.OPENING) { else if (state == State.OPENING) {
animate(); animate();
getEscenario().getCanvas().repaint(); getScene().getCanvas().repaint();
} }
} }
} }

View File

@ -15,9 +15,9 @@
package cl.cromer.azaraka.object; package cl.cromer.azaraka.object;
import cl.cromer.azaraka.Celda; import cl.cromer.azaraka.Cell;
import cl.cromer.azaraka.Constantes; import cl.cromer.azaraka.Constants;
import cl.cromer.azaraka.Escenario; import cl.cromer.azaraka.Scene;
import cl.cromer.azaraka.sound.Sound; import cl.cromer.azaraka.sound.Sound;
import cl.cromer.azaraka.sound.SoundException; import cl.cromer.azaraka.sound.SoundException;
import cl.cromer.azaraka.sprite.Animation; import cl.cromer.azaraka.sprite.Animation;
@ -29,7 +29,7 @@ import java.util.concurrent.locks.Lock;
/** /**
* This class handles the enemy object * This class handles the enemy object
*/ */
public class Enemy extends Object implements Constantes { public class Enemy extends Object implements Constants {
/** /**
* The lock helps prevent race conditions when checking positioning * The lock helps prevent race conditions when checking positioning
*/ */
@ -46,12 +46,12 @@ public class Enemy extends Object implements Constantes {
/** /**
* Initialize the enemy * Initialize the enemy
* *
* @param escenario The scene the enemy is in * @param scene The scene the enemy is in
* @param celda The cell this enemy is in * @param cell The cell this enemy is in
* @param lock The lock used to prevent the threads from conflicting * @param lock The lock used to prevent the threads from conflicting
*/ */
public Enemy(Escenario escenario, Celda celda, Lock lock) { public Enemy(Scene scene, Cell cell, Lock lock) {
super(escenario, celda); super(scene, cell);
setLogger(getLogger(this.getClass(), LogLevel.ENEMY)); setLogger(getLogger(this.getClass(), LogLevel.ENEMY));
this.lock = lock; this.lock = lock;
loadEnemyAnimation(); loadEnemyAnimation();
@ -78,7 +78,7 @@ public class Enemy extends Object implements Constantes {
*/ */
private void playAttackSound() { private void playAttackSound() {
try { try {
sound.setVolume(getEscenario().getCanvas().getVolume()); sound.setVolume(getScene().getCanvas().getVolume());
sound.play(); sound.play();
} }
catch (SoundException e) { catch (SoundException e) {
@ -114,10 +114,10 @@ public class Enemy extends Object implements Constantes {
int x = getX(); int x = getX();
int y = getY(); int y = getY();
if (direction == Direction.LEFT) { if (direction == Direction.LEFT) {
if (x > 0 && getEscenario().getCeldas()[x - 1][y].getObject() == null) { if (x > 0 && getScene().getCells()[x - 1][y].getObject() == null) {
getCelda().setObject(null); getCell().setObject(null);
setCelda(getEscenario().getCeldas()[x - 1][y]); setCell(getScene().getCells()[x - 1][y]);
getCelda().setObject(this); getCell().setObject(this);
try { try {
getAnimation().getNextFrame(); getAnimation().getNextFrame();
@ -128,7 +128,7 @@ public class Enemy extends Object implements Constantes {
setX(getX() - 1); setX(getX() - 1);
getLogger().info("Move left to x: " + x + " y: " + y); getLogger().info("Move left to x: " + x + " y: " + y);
} }
else if (x > 0 && getEscenario().getCeldas()[x - 1][y].getObject() instanceof Player) { else if (x > 0 && getScene().getCells()[x - 1][y].getObject() instanceof Player) {
attackPlayer(x - 1, y); attackPlayer(x - 1, y);
} }
else { else {
@ -138,10 +138,10 @@ public class Enemy extends Object implements Constantes {
} }
} }
else if (direction == Direction.RIGHT) { else if (direction == Direction.RIGHT) {
if (x < (HORIZONTAL_CELLS - 1) && getEscenario().getCeldas()[x + 1][y].getObject() == null) { if (x < (HORIZONTAL_CELLS - 1) && getScene().getCells()[x + 1][y].getObject() == null) {
getCelda().setObject(null); getCell().setObject(null);
setCelda(getEscenario().getCeldas()[x + 1][y]); setCell(getScene().getCells()[x + 1][y]);
getCelda().setObject(this); getCell().setObject(this);
try { try {
getAnimation().getNextFrame(); getAnimation().getNextFrame();
@ -152,7 +152,7 @@ public class Enemy extends Object implements Constantes {
setX(getX() + 1); setX(getX() + 1);
getLogger().info("Move right to x: " + x + " y: " + y); getLogger().info("Move right to x: " + x + " y: " + y);
} }
else if (x < (HORIZONTAL_CELLS - 1) && getEscenario().getCeldas()[x + 1][y].getObject() instanceof Player) { else if (x < (HORIZONTAL_CELLS - 1) && getScene().getCells()[x + 1][y].getObject() instanceof Player) {
attackPlayer(x + 1, y); attackPlayer(x + 1, y);
} }
else { else {
@ -162,10 +162,10 @@ public class Enemy extends Object implements Constantes {
} }
} }
else if (direction == Direction.DOWN) { else if (direction == Direction.DOWN) {
if (y < (VERTICAL_CELLS) - 1 && getEscenario().getCeldas()[x][y + 1].getObject() == null) { if (y < (VERTICAL_CELLS) - 1 && getScene().getCells()[x][y + 1].getObject() == null) {
getCelda().setObject(null); getCell().setObject(null);
setCelda(getEscenario().getCeldas()[x][y + 1]); setCell(getScene().getCells()[x][y + 1]);
getCelda().setObject(this); getCell().setObject(this);
try { try {
getAnimation().getNextFrame(); getAnimation().getNextFrame();
@ -176,7 +176,7 @@ public class Enemy extends Object implements Constantes {
setY(getY() + 1); setY(getY() + 1);
getLogger().info("Move down to x: " + x + " y: " + y); getLogger().info("Move down to x: " + x + " y: " + y);
} }
else if (y < (VERTICAL_CELLS - 1) && getEscenario().getCeldas()[x][y + 1].getObject() instanceof Player) { else if (y < (VERTICAL_CELLS - 1) && getScene().getCells()[x][y + 1].getObject() instanceof Player) {
attackPlayer(x, y + 1); attackPlayer(x, y + 1);
} }
else { else {
@ -186,10 +186,10 @@ public class Enemy extends Object implements Constantes {
} }
} }
else if (direction == Direction.UP) { else if (direction == Direction.UP) {
if (y > 0 && getEscenario().getCeldas()[x][y - 1].getObject() == null) { if (y > 0 && getScene().getCells()[x][y - 1].getObject() == null) {
getCelda().setObject(null); getCell().setObject(null);
setCelda(getEscenario().getCeldas()[x][y - 1]); setCell(getScene().getCells()[x][y - 1]);
getCelda().setObject(this); getCell().setObject(this);
try { try {
getAnimation().getNextFrame(); getAnimation().getNextFrame();
@ -200,7 +200,7 @@ public class Enemy extends Object implements Constantes {
setY(getY() - 1); setY(getY() - 1);
getLogger().info("Move up to x: " + x + " y: " + y); getLogger().info("Move up to x: " + x + " y: " + y);
} }
else if (y > 0 && getEscenario().getCeldas()[x][y - 1].getObject() instanceof Player) { else if (y > 0 && getScene().getCells()[x][y - 1].getObject() instanceof Player) {
attackPlayer(x, y - 1); attackPlayer(x, y - 1);
} }
else { else {
@ -218,20 +218,20 @@ public class Enemy extends Object implements Constantes {
* @param y The y position of the player * @param y The y position of the player
*/ */
private void attackPlayer(int x, int y) { private void attackPlayer(int x, int y) {
if (getEscenario().getCanvas().getPlayer().getHealth() > 0) { if (getScene().getCanvas().getPlayer().getHealth() > 0) {
getLogger().info("Attacked player at x: " + x + " y: " + y); getLogger().info("Attacked player at x: " + x + " y: " + y);
playAttackSound(); playAttackSound();
getEscenario().getCanvas().getPlayer().loseHealth(2); getScene().getCanvas().getPlayer().loseHealth(2);
try { try {
getEscenario().getCeldas()[x][y].addTexture(getEscenario().getTextureSheet().getTexture(12), 12); getScene().getCells()[x][y].addTexture(getScene().getTextureSheet().getTexture(12), 12);
} }
catch (SheetException e) { catch (SheetException e) {
getLogger().warning(e.getMessage()); getLogger().warning(e.getMessage());
} }
getEscenario().getCanvas().getPlayer().attacked(); getScene().getCanvas().getPlayer().attacked();
if (direction == Direction.UP) { if (direction == Direction.UP) {
getAnimation().setCurrentDirection(Animation.Direction.LEFT); getAnimation().setCurrentDirection(Animation.Direction.LEFT);
@ -267,7 +267,7 @@ public class Enemy extends Object implements Constantes {
synchronized (this) { synchronized (this) {
lock.lock(); lock.lock();
move(); move();
getEscenario().getCanvas().repaint(); getScene().getCanvas().repaint();
lock.unlock(); lock.unlock();
} }
} }

View File

@ -15,8 +15,8 @@
package cl.cromer.azaraka.object; package cl.cromer.azaraka.object;
import cl.cromer.azaraka.Celda; import cl.cromer.azaraka.Cell;
import cl.cromer.azaraka.Escenario; import cl.cromer.azaraka.Scene;
import cl.cromer.azaraka.sound.Sound; import cl.cromer.azaraka.sound.Sound;
import cl.cromer.azaraka.sound.SoundException; import cl.cromer.azaraka.sound.SoundException;
import cl.cromer.azaraka.sprite.Animation; import cl.cromer.azaraka.sprite.Animation;
@ -46,11 +46,11 @@ public class Gem extends Object {
/** /**
* Initialize the gem object * Initialize the gem object
* *
* @param escenario The scene the gem is in * @param scene The scene the gem is in
* @param celda The cell the gem is in * @param cell The cell the gem is in
*/ */
public Gem(Escenario escenario, Celda celda) { public Gem(Scene scene, Cell cell) {
super(escenario, celda); super(scene, cell);
setLogger(getLogger(this.getClass(), LogLevel.GEM)); setLogger(getLogger(this.getClass(), LogLevel.GEM));
loadGemAnimation(null); loadGemAnimation(null);
setAnimation(taintedAnimation); setAnimation(taintedAnimation);
@ -119,7 +119,7 @@ public class Gem extends Object {
*/ */
public void playGemSound() { public void playGemSound() {
try { try {
sound.setVolume(getEscenario().getCanvas().getVolume()); sound.setVolume(getScene().getCanvas().getVolume());
sound.play(); sound.play();
} }
catch (SoundException e) { catch (SoundException e) {
@ -201,7 +201,7 @@ public class Gem extends Object {
} }
synchronized (this) { synchronized (this) {
animate(); animate();
getEscenario().getCanvas().repaint(); getScene().getCanvas().repaint();
} }
} }
} }

View File

@ -15,9 +15,9 @@
package cl.cromer.azaraka.object; package cl.cromer.azaraka.object;
import cl.cromer.azaraka.Celda; import cl.cromer.azaraka.Cell;
import cl.cromer.azaraka.Constantes; import cl.cromer.azaraka.Constants;
import cl.cromer.azaraka.Escenario; import cl.cromer.azaraka.Scene;
import cl.cromer.azaraka.sound.Sound; import cl.cromer.azaraka.sound.Sound;
import cl.cromer.azaraka.sound.SoundException; import cl.cromer.azaraka.sound.SoundException;
import cl.cromer.azaraka.sprite.Animation; import cl.cromer.azaraka.sprite.Animation;
@ -28,7 +28,7 @@ import cl.cromer.azaraka.sprite.SheetException;
/** /**
* This class contains the key * This class contains the key
*/ */
public class Key extends Object implements Constantes { public class Key extends Object implements Constants {
/** /**
* The current state of the key * The current state of the key
*/ */
@ -41,11 +41,11 @@ public class Key extends Object implements Constantes {
/** /**
* Initialize the key * Initialize the key
* *
* @param escenario The scene the key is in * @param scene The scene the key is in
* @param celda The cell the key is in * @param cell The cell the key is in
*/ */
public Key(Escenario escenario, Celda celda) { public Key(Scene scene, Cell cell) {
super(escenario, celda); super(scene, cell);
setLogger(getLogger(this.getClass(), LogLevel.KEY)); setLogger(getLogger(this.getClass(), LogLevel.KEY));
loadKeyAnimation(); loadKeyAnimation();
} }
@ -92,7 +92,7 @@ public class Key extends Object implements Constantes {
*/ */
public void playGetKeySound() { public void playGetKeySound() {
try { try {
sound.setVolume(getEscenario().getCanvas().getVolume()); sound.setVolume(getScene().getCanvas().getVolume());
sound.play(); sound.play();
} }
catch (SoundException e) { catch (SoundException e) {
@ -114,7 +114,7 @@ public class Key extends Object implements Constantes {
*/ */
public void getKey() { public void getKey() {
// Remove the key from the cell // Remove the key from the cell
getCelda().setObjectOnBottom(null); getCell().setObjectOnBottom(null);
setState(State.HELD); setState(State.HELD);
} }
@ -169,7 +169,7 @@ public class Key extends Object implements Constantes {
} }
synchronized (this) { synchronized (this) {
animate(); animate();
getEscenario().getCanvas().repaint(); getScene().getCanvas().repaint();
} }
} }
// The thread was killed, set the animation to frame 4 // The thread was killed, set the animation to frame 4

View File

@ -15,9 +15,9 @@
package cl.cromer.azaraka.object; package cl.cromer.azaraka.object;
import cl.cromer.azaraka.Celda; import cl.cromer.azaraka.Cell;
import cl.cromer.azaraka.Constantes; import cl.cromer.azaraka.Constants;
import cl.cromer.azaraka.Escenario; import cl.cromer.azaraka.Scene;
import cl.cromer.azaraka.sprite.Animation; import cl.cromer.azaraka.sprite.Animation;
import cl.cromer.azaraka.sprite.AnimationException; import cl.cromer.azaraka.sprite.AnimationException;
import cl.cromer.azaraka.sprite.Sheet; import cl.cromer.azaraka.sprite.Sheet;
@ -30,11 +30,11 @@ import java.util.logging.Logger;
/** /**
* All game objects extend this class * All game objects extend this class
*/ */
public class Object implements Runnable, Constantes { public class Object implements Runnable, Constants {
/** /**
* The scene the object is in * The scene the object is in
*/ */
private final Escenario escenario; private final Scene scene;
/** /**
* The current x position of the object * The current x position of the object
*/ */
@ -46,7 +46,7 @@ public class Object implements Runnable, Constantes {
/** /**
* The cell the object is in * The cell the object is in
*/ */
private Celda celda; private Cell cell;
/** /**
* The animation of the object * The animation of the object
*/ */
@ -75,14 +75,14 @@ public class Object implements Runnable, Constantes {
/** /**
* Initialize the object * Initialize the object
* *
* @param escenario The scene the object is in * @param scene The scene the object is in
* @param celda The cell the object is in * @param cell The cell the object is in
*/ */
protected Object(Escenario escenario, Celda celda) { protected Object(Scene scene, Cell cell) {
this.escenario = escenario; this.scene = scene;
this.celda = celda; this.cell = cell;
this.x = celda.getX(); this.x = cell.getX();
this.y = celda.getY(); this.y = cell.getY();
} }
/** /**
@ -144,8 +144,8 @@ public class Object implements Runnable, Constantes {
* *
* @return Returns the scene * @return Returns the scene
*/ */
protected Escenario getEscenario() { protected Scene getScene() {
return escenario; return scene;
} }
/** /**
@ -153,17 +153,17 @@ public class Object implements Runnable, Constantes {
* *
* @return Returns the cell * @return Returns the cell
*/ */
public Celda getCelda() { public Cell getCell() {
return celda; return cell;
} }
/** /**
* Get the cell the object is in * Get the cell the object is in
* *
* @param celda The cell * @param cell The cell
*/ */
public void setCelda(Celda celda) { public void setCell(Cell cell) {
this.celda = celda; this.cell = cell;
} }
/** /**

View File

@ -15,8 +15,8 @@
package cl.cromer.azaraka.object; package cl.cromer.azaraka.object;
import cl.cromer.azaraka.Celda; import cl.cromer.azaraka.Cell;
import cl.cromer.azaraka.Escenario; import cl.cromer.azaraka.Scene;
/** /**
* This class handles the obstacles * This class handles the obstacles
@ -25,10 +25,10 @@ public class Obstacle extends Object {
/** /**
* Initialize the obstacle * Initialize the obstacle
* *
* @param escenario The scene the object is in * @param scene The scene the object is in
* @param celda The cell the object is in * @param cell The cell the object is in
*/ */
public Obstacle(Escenario escenario, Celda celda) { public Obstacle(Scene scene, Cell cell) {
super(escenario, celda); super(scene, cell);
} }
} }

View File

@ -15,9 +15,9 @@
package cl.cromer.azaraka.object; package cl.cromer.azaraka.object;
import cl.cromer.azaraka.Celda; import cl.cromer.azaraka.Cell;
import cl.cromer.azaraka.Constantes; import cl.cromer.azaraka.Constants;
import cl.cromer.azaraka.Escenario; import cl.cromer.azaraka.Scene;
import cl.cromer.azaraka.ai.PlayerAI; import cl.cromer.azaraka.ai.PlayerAI;
import cl.cromer.azaraka.sprite.Animation; import cl.cromer.azaraka.sprite.Animation;
import cl.cromer.azaraka.sprite.AnimationException; import cl.cromer.azaraka.sprite.AnimationException;
@ -28,7 +28,7 @@ import java.util.ArrayList;
/** /**
* This class contains the player * This class contains the player
*/ */
public class Player extends Object implements Constantes { public class Player extends Object implements Constants {
/** /**
* The maximum health of the player * The maximum health of the player
*/ */
@ -49,14 +49,14 @@ public class Player extends Object implements Constantes {
/** /**
* Initialize the player * Initialize the player
* *
* @param escenario The scene the player is in * @param scene The scene the player is in
* @param celda The cell the player is in * @param cell The cell the player is in
*/ */
public Player(Escenario escenario, Celda celda) { public Player(Scene scene, Cell cell) {
super(escenario, celda); super(scene, cell);
setLogger(getLogger(this.getClass(), LogLevel.PLAYER)); setLogger(getLogger(this.getClass(), LogLevel.PLAYER));
loadPlayerAnimation(); loadPlayerAnimation();
ai = new PlayerAI(escenario, this); ai = new PlayerAI(scene, this);
} }
/** /**
@ -81,15 +81,15 @@ public class Player extends Object implements Constantes {
* @param keyCode The key code to handle * @param keyCode The key code to handle
*/ */
public void keyPressed(int keyCode) { public void keyPressed(int keyCode) {
if (getEscenario().isDoorOpen()) { if (getScene().isDoorOpen()) {
ArrayList<Gem> gems = getInventoryGems(); ArrayList<Gem> gems = getInventoryGems();
if (gems.size() < 2) { if (gems.size() < 2) {
getEscenario().openDoor(false); getScene().openDoor(false);
} }
else { else {
for (Gem gem : gems) { for (Gem gem : gems) {
if (gem.getState() == Gem.State.TAINTED) { if (gem.getState() == Gem.State.TAINTED) {
getEscenario().openDoor(false); getScene().openDoor(false);
} }
} }
} }
@ -125,14 +125,14 @@ public class Player extends Object implements Constantes {
int y = getY(); int y = getY();
getLogger().info("Up key pressed"); getLogger().info("Up key pressed");
if (x == 2 && y == 0) { if (x == 2 && y == 0) {
getEscenario().getCanvas().win(); getScene().getCanvas().win();
} }
else if (y > 0) { else if (y > 0) {
Object type = getEscenario().getCeldas()[x][y - 1].getObject(); Object type = getScene().getCells()[x][y - 1].getObject();
if (type == null) { if (type == null) {
Object typeBottom = getEscenario().getCeldas()[x][y - 1].getObjectOnBottom(); Object typeBottom = getScene().getCells()[x][y - 1].getObjectOnBottom();
if (typeBottom instanceof Key) { if (typeBottom instanceof Key) {
for (Key key : getEscenario().getCanvas().getKeys()) { for (Key key : getScene().getCanvas().getKeys()) {
if (key.checkPosition(x, y - 1)) { if (key.checkPosition(x, y - 1)) {
// Get the key // Get the key
getKey(key); getKey(key);
@ -141,12 +141,12 @@ public class Player extends Object implements Constantes {
} }
} }
else if (typeBottom instanceof Portal) { else if (typeBottom instanceof Portal) {
getEscenario().getCanvas().getPortal().purifyGems(); getScene().getCanvas().getPortal().purifyGems();
} }
getCelda().setObject(null); getCell().setObject(null);
setCelda(getEscenario().getCeldas()[x][y - 1]); setCell(getScene().getCells()[x][y - 1]);
getCelda().setObject(this); getCell().setObject(this);
if (changeDirection(Animation.Direction.UP)) { if (changeDirection(Animation.Direction.UP)) {
try { try {
@ -190,11 +190,11 @@ public class Player extends Object implements Constantes {
int y = getY(); int y = getY();
getLogger().info("Down key pressed"); getLogger().info("Down key pressed");
if (y < (VERTICAL_CELLS - 1)) { if (y < (VERTICAL_CELLS - 1)) {
Object type = getEscenario().getCeldas()[x][y + 1].getObject(); Object type = getScene().getCells()[x][y + 1].getObject();
if (type == null) { if (type == null) {
Object typeBottom = getEscenario().getCeldas()[x][y + 1].getObjectOnBottom(); Object typeBottom = getScene().getCells()[x][y + 1].getObjectOnBottom();
if (typeBottom instanceof Key) { if (typeBottom instanceof Key) {
for (Key key : getEscenario().getCanvas().getKeys()) { for (Key key : getScene().getCanvas().getKeys()) {
if (key.checkPosition(x, y + 1)) { if (key.checkPosition(x, y + 1)) {
// Get the key // Get the key
getKey(key); getKey(key);
@ -203,12 +203,12 @@ public class Player extends Object implements Constantes {
} }
} }
else if (typeBottom instanceof Portal) { else if (typeBottom instanceof Portal) {
getEscenario().getCanvas().getPortal().purifyGems(); getScene().getCanvas().getPortal().purifyGems();
} }
getCelda().setObject(null); getCell().setObject(null);
setCelda(getEscenario().getCeldas()[x][y + 1]); setCell(getScene().getCells()[x][y + 1]);
getCelda().setObject(this); getCell().setObject(this);
if (changeDirection(Animation.Direction.DOWN)) { if (changeDirection(Animation.Direction.DOWN)) {
try { try {
@ -252,11 +252,11 @@ public class Player extends Object implements Constantes {
int y = getY(); int y = getY();
getLogger().info("Left key pressed"); getLogger().info("Left key pressed");
if (x > 0) { if (x > 0) {
Object type = getEscenario().getCeldas()[x - 1][y].getObject(); Object type = getScene().getCells()[x - 1][y].getObject();
if (type == null) { if (type == null) {
Object typeBottom = getEscenario().getCeldas()[x - 1][y].getObjectOnBottom(); Object typeBottom = getScene().getCells()[x - 1][y].getObjectOnBottom();
if (typeBottom instanceof Key) { if (typeBottom instanceof Key) {
for (Key key : getEscenario().getCanvas().getKeys()) { for (Key key : getScene().getCanvas().getKeys()) {
if (key.checkPosition(x - 1, y)) { if (key.checkPosition(x - 1, y)) {
// Get the key // Get the key
getKey(key); getKey(key);
@ -265,12 +265,12 @@ public class Player extends Object implements Constantes {
} }
} }
else if (typeBottom instanceof Portal) { else if (typeBottom instanceof Portal) {
getEscenario().getCanvas().getPortal().purifyGems(); getScene().getCanvas().getPortal().purifyGems();
} }
getCelda().setObject(null); getCell().setObject(null);
setCelda(getEscenario().getCeldas()[x - 1][y]); setCell(getScene().getCells()[x - 1][y]);
getCelda().setObject(this); getCell().setObject(this);
if (changeDirection(Animation.Direction.LEFT)) { if (changeDirection(Animation.Direction.LEFT)) {
try { try {
@ -314,11 +314,11 @@ public class Player extends Object implements Constantes {
int y = getY(); int y = getY();
getLogger().info("Right key pressed"); getLogger().info("Right key pressed");
if (x < (HORIZONTAL_CELLS - 1)) { if (x < (HORIZONTAL_CELLS - 1)) {
Object type = getEscenario().getCeldas()[x + 1][y].getObject(); Object type = getScene().getCells()[x + 1][y].getObject();
if (type == null) { if (type == null) {
Object typeBottom = getEscenario().getCeldas()[x + 1][y].getObjectOnBottom(); Object typeBottom = getScene().getCells()[x + 1][y].getObjectOnBottom();
if (typeBottom instanceof Key) { if (typeBottom instanceof Key) {
for (Key key : getEscenario().getCanvas().getKeys()) { for (Key key : getScene().getCanvas().getKeys()) {
if (key.checkPosition(x + 1, y)) { if (key.checkPosition(x + 1, y)) {
// Get the key // Get the key
getKey(key); getKey(key);
@ -327,12 +327,12 @@ public class Player extends Object implements Constantes {
} }
} }
else if (typeBottom instanceof Portal) { else if (typeBottom instanceof Portal) {
getEscenario().getCanvas().getPortal().purifyGems(); getScene().getCanvas().getPortal().purifyGems();
} }
getCelda().setObject(null); getCell().setObject(null);
setCelda(getEscenario().getCeldas()[x + 1][y]); setCell(getScene().getCells()[x + 1][y]);
getCelda().setObject(this); getCell().setObject(this);
if (changeDirection(Animation.Direction.RIGHT)) { if (changeDirection(Animation.Direction.RIGHT)) {
try { try {
@ -407,21 +407,21 @@ public class Player extends Object implements Constantes {
int y = getY(); int y = getY();
getLogger().info("Space bar pressed"); getLogger().info("Space bar pressed");
if (getAnimation().getCurrentDirection() == Animation.Direction.UP) { if (getAnimation().getCurrentDirection() == Animation.Direction.UP) {
if (getEscenario().getCeldas()[x][y - 1].getObject() instanceof Chest) { if (getScene().getCells()[x][y - 1].getObject() instanceof Chest) {
if (hasKey()) { if (hasKey()) {
getLogger().info("Player opened chest"); getLogger().info("Player opened chest");
gainHealth(2); gainHealth(2);
for (Chest chest : getEscenario().getCanvas().getChests()) { for (Chest chest : getScene().getCanvas().getChests()) {
if (chest.checkPosition(x, y - 1)) { if (chest.checkPosition(x, y - 1)) {
if (chest.getState() == Chest.State.CLOSED) { if (chest.getState() == Chest.State.CLOSED) {
chest.setState(Chest.State.OPENING); chest.setState(Chest.State.OPENING);
Gem gem = chest.getGem(); Gem gem = chest.getGem();
if (gem != null) { if (gem != null) {
gem.playGemSound(); gem.playGemSound();
gem.getCelda().setObjectOnTop(gem); gem.getCell().setObjectOnTop(gem);
getEscenario().getCanvas().getPortal().setState(Portal.State.ACTIVE); getScene().getCanvas().getPortal().setState(Portal.State.ACTIVE);
} }
useKey(); useKey();
break; break;
@ -591,7 +591,7 @@ public class Player extends Object implements Constantes {
synchronized (this) { synchronized (this) {
if (health > 0) { if (health > 0) {
loseHealth(1); loseHealth(1);
getEscenario().getCanvas().repaint(); getScene().getCanvas().repaint();
} }
else { else {
setActive(false); setActive(false);

View File

@ -15,9 +15,9 @@
package cl.cromer.azaraka.object; package cl.cromer.azaraka.object;
import cl.cromer.azaraka.Celda; import cl.cromer.azaraka.Cell;
import cl.cromer.azaraka.Constantes; import cl.cromer.azaraka.Constants;
import cl.cromer.azaraka.Escenario; import cl.cromer.azaraka.Scene;
import cl.cromer.azaraka.sound.Sound; import cl.cromer.azaraka.sound.Sound;
import cl.cromer.azaraka.sound.SoundException; import cl.cromer.azaraka.sound.SoundException;
import cl.cromer.azaraka.sprite.Animation; import cl.cromer.azaraka.sprite.Animation;
@ -28,7 +28,7 @@ import java.util.ArrayList;
/** /**
* This class handles the portal functionality * This class handles the portal functionality
*/ */
public class Portal extends Object implements Constantes { public class Portal extends Object implements Constants {
/** /**
* The current state of the portal * The current state of the portal
*/ */
@ -49,11 +49,11 @@ public class Portal extends Object implements Constantes {
/** /**
* Initialize the portal * Initialize the portal
* *
* @param escenario The scene that contains the portal * @param scene The scene that contains the portal
* @param celda The cell the portal is in * @param cell The cell the portal is in
*/ */
public Portal(Escenario escenario, Celda celda) { public Portal(Scene scene, Cell cell) {
super(escenario, celda); super(scene, cell);
setLogger(getLogger(this.getClass(), LogLevel.PORTAL)); setLogger(getLogger(this.getClass(), LogLevel.PORTAL));
loadPortalAnimations(); loadPortalAnimations();
} }
@ -92,17 +92,17 @@ public class Portal extends Object implements Constantes {
*/ */
public void purifyGems() { public void purifyGems() {
if (state == State.ACTIVE) { if (state == State.ACTIVE) {
ArrayList<Gem> gems = getEscenario().getCanvas().getPlayer().getInventoryGems(); ArrayList<Gem> gems = getScene().getCanvas().getPlayer().getInventoryGems();
for (Gem gem : gems) { for (Gem gem : gems) {
if (gem.getState() == Gem.State.TAINTED) { if (gem.getState() == Gem.State.TAINTED) {
gem.setState(Gem.State.PURIFIED); gem.setState(Gem.State.PURIFIED);
getEscenario().getCanvas().getPlayer().gainHealth(2); getScene().getCanvas().getPlayer().gainHealth(2);
} }
} }
setState(State.INACTIVE); setState(State.INACTIVE);
playPortalSound(); playPortalSound();
if (gems.size() == 2) { if (gems.size() == 2) {
getEscenario().openDoor(true); getScene().openDoor(true);
} }
} }
} }
@ -121,7 +121,7 @@ public class Portal extends Object implements Constantes {
*/ */
private void playPortalSound() { private void playPortalSound() {
try { try {
sound.setVolume(getEscenario().getCanvas().getVolume()); sound.setVolume(getScene().getCanvas().getVolume());
sound.play(); sound.play();
} }
catch (SoundException e) { catch (SoundException e) {
@ -203,7 +203,7 @@ public class Portal extends Object implements Constantes {
} }
synchronized (this) { synchronized (this) {
animate(); animate();
getEscenario().getCanvas().repaint(); getScene().getCanvas().repaint();
} }
} }
} }

View File

@ -15,7 +15,7 @@
package cl.cromer.azaraka.sound; package cl.cromer.azaraka.sound;
import cl.cromer.azaraka.Constantes; import cl.cromer.azaraka.Constants;
import javax.sound.sampled.*; import javax.sound.sampled.*;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
@ -26,7 +26,7 @@ import java.util.logging.Logger;
/** /**
* This class handles sound * This class handles sound
*/ */
public class Sound implements Constantes { public class Sound implements Constants {
/** /**
* The path to the sound * The path to the sound
*/ */

View File

@ -15,7 +15,7 @@
package cl.cromer.azaraka.sprite; package cl.cromer.azaraka.sprite;
import cl.cromer.azaraka.Constantes; import cl.cromer.azaraka.Constants;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import java.awt.*; import java.awt.*;
@ -28,7 +28,7 @@ import java.util.logging.Logger;
/** /**
* This class handles loading the images and animating the sprite * This class handles loading the images and animating the sprite
*/ */
public class Animation implements Cloneable, Constantes { public class Animation implements Cloneable, Constants {
/** /**
* The collection of all the images that make up the object * The collection of all the images that make up the object
*/ */

View File

@ -15,7 +15,7 @@
package cl.cromer.azaraka.sprite; package cl.cromer.azaraka.sprite;
import cl.cromer.azaraka.Constantes; import cl.cromer.azaraka.Constants;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
@ -26,7 +26,7 @@ import java.util.logging.Logger;
/** /**
* This class handles loading the images and sub-images * This class handles loading the images and sub-images
*/ */
public class Sheet implements Constantes { public class Sheet implements Constants {
/** /**
* A list of all the textures in the collection * A list of all the textures in the collection
*/ */