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 {
//noinspection GroovyAssignabilityCheck
main {
//noinspection GrUnresolvedAccess
contents {
//noinspection GrUnresolvedAccess
from(createDocs) {
//noinspection GrUnresolvedAccess
into 'docs'
}
}

View File

@ -21,18 +21,41 @@ import java.util.logging.Logger;
/**
* 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() {
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");
VentanaPrincipal ventanaPrincipal = new VentanaPrincipal();
ventanaPrincipal.setVisible(true);
ventanaPrincipal.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainWindow = new MainWindow(this);
mainWindow.setVisible(true);
mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
/**
@ -41,6 +64,15 @@ public class Azaraka implements Constantes {
* @param args The arguments passed to the application
*/
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();
}

View File

@ -34,7 +34,11 @@ import java.util.logging.Logger;
/**
* 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
*/
@ -94,7 +98,7 @@ public class Lienzo extends Canvas implements Constantes {
/**
* The game scene
*/
private Escenario escenario;
private Scene scene;
/**
* The sound played when a key is picked up
*/
@ -155,11 +159,13 @@ public class Lienzo extends Canvas implements Constantes {
/**
* Initialize the canvas
*
* @param azaraka The main window
* @param width 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);
this.azaraka = azaraka;
setSize(width, height);
leftMargin = (width - CELL_PIXELS * HORIZONTAL_CELLS) / 2;
@ -185,25 +191,25 @@ public class Lienzo extends Canvas implements Constantes {
gameOverAnimation = new Animation();
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) {
escenario = new Escenario(this);
objectList = escenario.generateRandomObjects();
scene = new Scene(this);
objectList = scene.generateRandomObjects();
}
escenario.setDoorSound(doorSound);
scene.setDoorSound(doorSound);
setBackground(Color.black);
Enemy.Direction enemyDirection = Enemy.Direction.DOWN;
// Create the gems and later place them in 2 of the chests
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.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.setType(Gem.Type.DEATH);
gems.add(lifeGem);
@ -211,12 +217,12 @@ public class Lienzo extends Canvas implements Constantes {
for (Object object : objectList) {
if (object instanceof Player) {
object.getCelda().setObject(object);
object.getCell().setObject(object);
player = (Player) object;
threads.put(object, new Thread(object));
}
else if (object instanceof Enemy) {
object.getCelda().setObject(object);
object.getCell().setObject(object);
if (enemyDirection == Enemy.Direction.UP) {
enemyDirection = Enemy.Direction.DOWN;
}
@ -235,12 +241,12 @@ public class Lienzo extends Canvas implements Constantes {
threads.put(object, new Thread(object));
}
else if (object instanceof Chest) {
object.getCelda().setObject(object);
object.getCell().setObject(object);
((Chest) object).setSound(openChestSound);
if (gems.size() > 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
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));
((Chest) object).setGem(gem);
gems.remove(gem);
@ -249,13 +255,13 @@ public class Lienzo extends Canvas implements Constantes {
threads.put(object, new Thread(object));
}
else if (object instanceof Key) {
object.getCelda().setObjectOnBottom(object);
object.getCell().setObjectOnBottom(object);
((Key) object).setSound(getKeySound);
keys.add((Key) object);
threads.put(object, new Thread(object));
}
else if (object instanceof Portal) {
object.getCelda().setObjectOnBottom(object);
object.getCell().setObjectOnBottom(object);
portal = (Portal) object;
portal.setSound(portalSound);
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
Collections.shuffle(chests, new Random(23));
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) {
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());
@ -376,6 +382,16 @@ public class Lienzo extends Canvas implements Constantes {
if (gameOver) {
if (!gameOverRan) {
addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent event) {
super.keyPressed(event);
if (event.getKeyCode() == KeyEvent.VK_ENTER) {
azaraka.restart();
}
}
});
stopBackgroundMusic();
try {
@ -410,7 +426,7 @@ public class Lienzo extends Canvas implements Constantes {
}
}
else {
escenario.paintComponent(graphicBuffer);
scene.paintComponent(graphicBuffer);
if (won) {
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 y = rectangle.y + ((rectangle.height - metrics.getHeight()) / 2) + metrics.getAscent();
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
*/
public class Celda extends JComponent implements Constantes {
public class Cell extends JComponent implements Constants {
/**
* 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 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.yPixels = yPixels;
this.x = x;

View File

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

View File

@ -25,12 +25,14 @@ import java.util.logging.Logger;
/**
* The main window of the game
*/
public class VentanaPrincipal extends JFrame implements Constantes {
public class MainWindow extends JFrame implements Constants {
/**
* 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.info("Create panels");
@ -52,7 +54,7 @@ public class VentanaPrincipal extends JFrame implements Constantes {
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.requestFocus();
add(canvas);

View File

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

View File

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

View File

@ -15,8 +15,8 @@
package cl.cromer.azaraka.ai;
import cl.cromer.azaraka.Constantes;
import cl.cromer.azaraka.Escenario;
import cl.cromer.azaraka.Constants;
import cl.cromer.azaraka.Scene;
import java.awt.geom.Point2D;
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
*/
public class BreadthFirstSearch extends AI implements Constantes {
public class BreadthFirstSearch extends AI implements Constants {
/**
* The queued states to check
*/
@ -57,10 +57,10 @@ public class BreadthFirstSearch extends AI implements Constantes {
/**
* Initialize the algorithm
*
* @param escenario The scene the AI is in
* @param scene The scene the AI is in
*/
public BreadthFirstSearch(Escenario escenario) {
super(escenario);
public BreadthFirstSearch(Scene scene) {
super(scene);
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
*
@ -106,7 +108,7 @@ public class BreadthFirstSearch extends AI implements Constantes {
*/
private void moveUp(State state) {
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());
if (!history.contains(up)) {
queuedStates.add(up);
@ -128,7 +130,7 @@ public class BreadthFirstSearch extends AI implements Constantes {
*/
private void moveDown(State state) {
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());
if (!history.contains(down)) {
queuedStates.add(down);
@ -150,7 +152,7 @@ public class BreadthFirstSearch extends AI implements Constantes {
*/
private void moveLeft(State state) {
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());
if (!history.contains(left)) {
queuedStates.add(left);
@ -172,7 +174,7 @@ public class BreadthFirstSearch extends AI implements Constantes {
*/
private void moveRight(State state) {
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());
if (!history.contains(right)) {
queuedStates.add(right);

View File

@ -15,7 +15,7 @@
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.Portal;
import cl.cromer.azaraka.sprite.Animation;
@ -34,11 +34,11 @@ public class PlayerAI extends BreadthFirstSearch {
/**
* 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
*/
public PlayerAI(Escenario escenario, Player player) {
super(escenario);
public PlayerAI(Scene scene, Player player) {
super(scene);
this.player = player;
}
@ -57,9 +57,9 @@ public class PlayerAI extends BreadthFirstSearch {
player.keyPressed(KeyEvent.VK_UP);
}
player.interact();
Portal portal = getEscenario().getCanvas().getPortal();
Portal portal = getScene().getCanvas().getPortal();
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;
}
@ -70,7 +70,7 @@ public class PlayerAI extends BreadthFirstSearch {
case KEY:
return true;
case PORTAL:
if (player.hasTaintedGem() && getEscenario().getCanvas().getPortal().getState() == Portal.State.ACTIVE) {
if (player.hasTaintedGem() && getScene().getCanvas().getPortal().getState() == Portal.State.ACTIVE) {
return true;
}
break;
@ -101,13 +101,13 @@ public class PlayerAI extends BreadthFirstSearch {
break;
case PORTAL:
// 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;
}
break;
case EXIT:
// If the door is open head to it
if (getEscenario().isDoorOpen()) {
if (getScene().isDoorOpen()) {
return true;
}
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
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
*/
private int importance;
private final int importance;
/**
* Initialize the state

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -15,7 +15,7 @@
package cl.cromer.azaraka.sprite;
import cl.cromer.azaraka.Constantes;
import cl.cromer.azaraka.Constants;
import javax.imageio.ImageIO;
import java.awt.*;
@ -28,7 +28,7 @@ import java.util.logging.Logger;
/**
* 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
*/

View File

@ -15,7 +15,7 @@
package cl.cromer.azaraka.sprite;
import cl.cromer.azaraka.Constantes;
import cl.cromer.azaraka.Constants;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
@ -26,7 +26,7 @@ import java.util.logging.Logger;
/**
* 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
*/