Remove tests
Simplify audio Simplify and optimize random object generation Signed-off-by: Chris Cromer <chris@cromer.cl>
This commit is contained in:
parent
3662e40d74
commit
b9d3532fbc
@ -1,17 +0,0 @@
|
|||||||
<component name="libraryTable">
|
|
||||||
<library name="org.junit.jupiter:junit-jupiter:5.5.2" type="repository">
|
|
||||||
<properties maven-id="org.junit.jupiter:junit-jupiter:5.5.2" />
|
|
||||||
<CLASSES>
|
|
||||||
<root url="jar://$PROJECT_DIR$/lib/junit-jupiter-5.5.2.jar!/" />
|
|
||||||
<root url="jar://$PROJECT_DIR$/lib/junit-jupiter-api-5.5.2.jar!/" />
|
|
||||||
<root url="jar://$PROJECT_DIR$/lib/apiguardian-api-1.1.0.jar!/" />
|
|
||||||
<root url="jar://$PROJECT_DIR$/lib/opentest4j-1.2.0.jar!/" />
|
|
||||||
<root url="jar://$PROJECT_DIR$/lib/junit-platform-commons-1.5.2.jar!/" />
|
|
||||||
<root url="jar://$PROJECT_DIR$/lib/junit-jupiter-params-5.5.2.jar!/" />
|
|
||||||
<root url="jar://$PROJECT_DIR$/lib/junit-jupiter-engine-5.5.2.jar!/" />
|
|
||||||
<root url="jar://$PROJECT_DIR$/lib/junit-platform-engine-1.5.2.jar!/" />
|
|
||||||
</CLASSES>
|
|
||||||
<JAVADOC />
|
|
||||||
<SOURCES />
|
|
||||||
</library>
|
|
||||||
</component>
|
|
@ -17,6 +17,5 @@
|
|||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="library" name="com.google.code.gson:gson:2.8.5" level="project" />
|
<orderEntry type="library" name="com.google.code.gson:gson:2.8.5" level="project" />
|
||||||
<orderEntry type="library" name="org.junit.jupiter:junit-jupiter:5.5.2" level="project" />
|
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
@ -149,7 +149,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "cl.cromer.azaraka.object.Player",
|
"type": "null",
|
||||||
"textures": [
|
"textures": [
|
||||||
0
|
0
|
||||||
]
|
]
|
||||||
|
@ -126,7 +126,7 @@ public interface Constantes {
|
|||||||
/**
|
/**
|
||||||
* The default volume
|
* The default volume
|
||||||
*/
|
*/
|
||||||
int DEFAULT_VOLUME = 0;
|
int DEFAULT_VOLUME = 100;
|
||||||
/**
|
/**
|
||||||
* Generates the scene manually instead of from the JSON file if true
|
* Generates the scene manually instead of from the JSON file if true
|
||||||
*/
|
*/
|
||||||
|
@ -31,6 +31,8 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.concurrent.locks.Lock;
|
||||||
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -53,26 +55,6 @@ public class Escenario extends JComponent implements Constantes {
|
|||||||
* The cells of the game
|
* The cells of the game
|
||||||
*/
|
*/
|
||||||
private Celda[][] celdas;
|
private Celda[][] celdas;
|
||||||
/**
|
|
||||||
* The cell that contains the player
|
|
||||||
*/
|
|
||||||
private Celda player;
|
|
||||||
/**
|
|
||||||
* The magic portal
|
|
||||||
*/
|
|
||||||
private Celda portal;
|
|
||||||
/**
|
|
||||||
* The enemies
|
|
||||||
*/
|
|
||||||
private ArrayList<Celda> enemies = new ArrayList<>();
|
|
||||||
/**
|
|
||||||
* The chests
|
|
||||||
*/
|
|
||||||
private ArrayList<Celda> chests = new ArrayList<>();
|
|
||||||
/**
|
|
||||||
* The keys
|
|
||||||
*/
|
|
||||||
private ArrayList<Celda> keys = new ArrayList<>();
|
|
||||||
/**
|
/**
|
||||||
* A collection of tiles that can be used in the scene
|
* A collection of tiles that can be used in the scene
|
||||||
*/
|
*/
|
||||||
@ -122,8 +104,6 @@ public class Escenario extends JComponent implements Constantes {
|
|||||||
Json json = new Json();
|
Json json = new Json();
|
||||||
json.exportScene(celdas);
|
json.exportScene(celdas);
|
||||||
}
|
}
|
||||||
|
|
||||||
generateRandomObjects();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -142,7 +122,6 @@ public class Escenario extends JComponent implements Constantes {
|
|||||||
|
|
||||||
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]));
|
celdas[x][y].setObject(new Player(null, celdas[x][y]));
|
||||||
player = celdas[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));
|
celdas[x][y].setObject(new Enemy(null, celdas[x][y], null));
|
||||||
@ -177,91 +156,83 @@ public class Escenario extends JComponent implements Constantes {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate random objects in the scene
|
* Generate random objects in the scene
|
||||||
|
*
|
||||||
|
* @return Returns a list of objects that where generated
|
||||||
*/
|
*/
|
||||||
private void generateRandomObjects() {
|
public ArrayList<Object> generateRandomObjects() {
|
||||||
final int cells = (HORIZONTAL_CELLS * VERTICAL_CELLS);
|
final int cells = (HORIZONTAL_CELLS * VERTICAL_CELLS);
|
||||||
final int obstacles = (int) Math.floor((double) cells * 0.05);
|
final int obstacles = (int) Math.floor((double) cells * 0.05);
|
||||||
|
|
||||||
int random_x;
|
int[] random;
|
||||||
int random_y;
|
ArrayList<Object> objectArrayList = new ArrayList<>();
|
||||||
ArrayList<RandomPositionList> arrayList = new ArrayList<>();
|
|
||||||
|
// The player has a fixed position
|
||||||
|
celdas[2][1].setObject(new Player(this, celdas[2][1]));
|
||||||
|
objectArrayList.add(celdas[2][1].getObject());
|
||||||
|
|
||||||
|
final Lock lock = new ReentrantLock(true);
|
||||||
|
|
||||||
for (int i = 0; i < ENEMIES; i++) {
|
|
||||||
random_x = random(0, HORIZONTAL_CELLS - 1);
|
|
||||||
random_y = random(0, VERTICAL_CELLS - 1);
|
|
||||||
while (arrayList.contains(new RandomPositionList(random_x, random_y, new Enemy(null, celdas[random_x][random_y], null))) || celdas[random_x][random_y].getObject() != null) {
|
|
||||||
random_x = random(0, HORIZONTAL_CELLS - 1);
|
|
||||||
random_y = random(0, VERTICAL_CELLS - 1);
|
|
||||||
}
|
|
||||||
arrayList.add(new RandomPositionList(random_x, random_y, new Enemy(null, celdas[random_x][random_y], null)));
|
|
||||||
}
|
|
||||||
for (int i = 0; i < obstacles; i++) {
|
for (int i = 0; i < obstacles; i++) {
|
||||||
random_x = random(0, HORIZONTAL_CELLS - 1);
|
random = randomCoordinates();
|
||||||
random_y = random(0, VERTICAL_CELLS - 1);
|
celdas[random[0]][random[1]].setObject(new Obstacle(this, celdas[random[0]][random[1]]));
|
||||||
while (arrayList.contains(new RandomPositionList(random_x, random_y, new Obstacle(null, celdas[random_x][random_y]))) || celdas[random_x][random_y].getObject() != null) {
|
|
||||||
random_x = random(0, HORIZONTAL_CELLS - 1);
|
|
||||||
random_y = random(0, VERTICAL_CELLS - 1);
|
|
||||||
}
|
|
||||||
arrayList.add(new RandomPositionList(random_x, random_y, new Obstacle(null, celdas[random_x][random_y])));
|
|
||||||
}
|
|
||||||
|
|
||||||
random_x = random(0, HORIZONTAL_CELLS - 1);
|
|
||||||
random_y = random(0, VERTICAL_CELLS - 1);
|
|
||||||
while (arrayList.contains(new RandomPositionList(random_x, random_y, new Portal(null, celdas[random_x][random_y]))) || celdas[random_x][random_y].getObject() != null) {
|
|
||||||
random_x = random(0, HORIZONTAL_CELLS - 1);
|
|
||||||
random_y = random(0, VERTICAL_CELLS - 1);
|
|
||||||
}
|
|
||||||
arrayList.add(new RandomPositionList(random_x, random_y, new Portal(null, celdas[random_x][random_y])));
|
|
||||||
|
|
||||||
// Generate enough keys for the chests that will exist
|
|
||||||
for (int i = 0; i < CHESTS; i++) {
|
|
||||||
random_x = random(0, HORIZONTAL_CELLS - 1);
|
|
||||||
random_y = random(0, VERTICAL_CELLS - 1);
|
|
||||||
while (arrayList.contains(new RandomPositionList(random_x, random_y, new Key(null, celdas[random_x][random_y]))) || celdas[random_x][random_y].getObject() != null) {
|
|
||||||
random_x = random(0, HORIZONTAL_CELLS - 1);
|
|
||||||
random_y = random(0, VERTICAL_CELLS - 1);
|
|
||||||
}
|
|
||||||
arrayList.add(new RandomPositionList(random_x, random_y, new Key(null, celdas[random_x][random_y])));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Chests need to be last to make sure they are openable
|
|
||||||
for (int i = 0; i < CHESTS; i++) {
|
|
||||||
random_x = random(0, HORIZONTAL_CELLS - 1);
|
|
||||||
random_y = random(0, VERTICAL_CELLS - 1);
|
|
||||||
// Don't put a chest if it can't be opened
|
|
||||||
while (arrayList.contains(new RandomPositionList(random_x, random_y, new Chest(null, celdas[random_x][random_y]))) || arrayList.contains(new RandomPositionList(random_x, random_y + 1, new Chest(null, celdas[random_x][random_y]))) || celdas[random_x][random_y].getObject() != null || celdas[random_x][random_y + 1].getObject() != null || celdas[random_x][random_y - 1].getObject() != null) {
|
|
||||||
random_x = random(0, HORIZONTAL_CELLS - 1);
|
|
||||||
random_y = random(0, VERTICAL_CELLS - 1);
|
|
||||||
}
|
|
||||||
arrayList.add(new RandomPositionList(random_x, random_y, new Chest(null, celdas[random_x][random_y])));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (RandomPositionList randomList : arrayList) {
|
|
||||||
int x = randomList.getX();
|
|
||||||
int y = randomList.getY();
|
|
||||||
Object object = randomList.getObject();
|
|
||||||
celdas[x][y].setObject(object);
|
|
||||||
if (object instanceof Enemy) {
|
|
||||||
enemies.add(celdas[x][y]);
|
|
||||||
}
|
|
||||||
else if (object instanceof Chest) {
|
|
||||||
chests.add(celdas[x][y]);
|
|
||||||
}
|
|
||||||
else if (object instanceof Key) {
|
|
||||||
keys.add(celdas[x][y]);
|
|
||||||
}
|
|
||||||
else if (object instanceof Portal) {
|
|
||||||
portal = celdas[x][y];
|
|
||||||
}
|
|
||||||
else if (object instanceof Obstacle) {
|
|
||||||
try {
|
try {
|
||||||
celdas[x][y].addTexture(textureSheet.getTexture(30), 30);
|
celdas[random[0]][random[1]].addTexture(textureSheet.getTexture(30), 30);
|
||||||
}
|
}
|
||||||
catch (SheetException e) {
|
catch (SheetException e) {
|
||||||
logger.warning(e.getMessage());
|
logger.warning(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < ENEMIES; i++) {
|
||||||
|
random = randomCoordinates();
|
||||||
|
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();
|
||||||
|
celdas[random[0]][random[1]].setObject(new Portal(this, celdas[random[0]][random[1]]));
|
||||||
|
objectArrayList.add(celdas[random[0]][random[1]].getObject());
|
||||||
|
|
||||||
|
// Generate enough keys for the chests that will exist
|
||||||
|
for (int i = 0; i < CHESTS; i++) {
|
||||||
|
random = randomCoordinates();
|
||||||
|
celdas[random[0]][random[1]].setObject(new Key(this, celdas[random[0]][random[1]]));
|
||||||
|
objectArrayList.add(celdas[random[0]][random[1]].getObject());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Chests need to be last to make sure they are openable
|
||||||
|
for (int i = 0; i < CHESTS; i++) {
|
||||||
|
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].getObject() != null ||
|
||||||
|
celdas[random_x][random_y + 1].getObject() != null ||
|
||||||
|
celdas[random_x][random_y - 1].getObject() != null) {
|
||||||
|
random_x = random(0, HORIZONTAL_CELLS - 1);
|
||||||
|
random_y = random(0, VERTICAL_CELLS - 1);
|
||||||
|
}
|
||||||
|
celdas[random_x][random_y].setObject(new Chest(this, celdas[random_x][random_y]));
|
||||||
|
objectArrayList.add(celdas[random_x][random_y].getObject());
|
||||||
|
}
|
||||||
|
|
||||||
|
return objectArrayList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get random x and y coordinates
|
||||||
|
*
|
||||||
|
* @return Returns an array with the coordinates
|
||||||
|
*/
|
||||||
|
private int[] randomCoordinates() {
|
||||||
|
int[] random = new int[2];
|
||||||
|
random[0] = random(0, HORIZONTAL_CELLS - 1);
|
||||||
|
random[1] = random(0, VERTICAL_CELLS - 1);
|
||||||
|
while (celdas[random[0]][random[1]].getObject() != null) {
|
||||||
|
random[0] = random(0, HORIZONTAL_CELLS - 1);
|
||||||
|
random[1] = random(0, VERTICAL_CELLS - 1);
|
||||||
|
}
|
||||||
|
return random;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -281,7 +252,7 @@ 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(null, celdas[x][y]));
|
celdas[x][y].setObject(new Obstacle(this, celdas[x][y]));
|
||||||
try {
|
try {
|
||||||
celdas[x][y].addTexture(textureSheet.getTexture(33), 33);
|
celdas[x][y].addTexture(textureSheet.getTexture(33), 33);
|
||||||
}
|
}
|
||||||
@ -291,7 +262,7 @@ 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(null, celdas[x][y]));
|
celdas[x][y].setObject(new Obstacle(this, celdas[x][y]));
|
||||||
try {
|
try {
|
||||||
celdas[x][y].addTexture(textureSheet.getTexture(37), 37);
|
celdas[x][y].addTexture(textureSheet.getTexture(37), 37);
|
||||||
}
|
}
|
||||||
@ -301,7 +272,7 @@ 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(null, celdas[x][y]));
|
celdas[x][y].setObject(new Obstacle(this, celdas[x][y]));
|
||||||
try {
|
try {
|
||||||
celdas[x][y].addTexture(textureSheet.getTexture(97), 97);
|
celdas[x][y].addTexture(textureSheet.getTexture(97), 97);
|
||||||
}
|
}
|
||||||
@ -311,7 +282,7 @@ 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(null, celdas[x][y]));
|
celdas[x][y].setObject(new Obstacle(this, celdas[x][y]));
|
||||||
try {
|
try {
|
||||||
celdas[x][y].addTexture(textureSheet.getTexture(101), 101);
|
celdas[x][y].addTexture(textureSheet.getTexture(101), 101);
|
||||||
}
|
}
|
||||||
@ -321,7 +292,7 @@ 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(null, celdas[x][y]));
|
celdas[x][y].setObject(new Obstacle(this, celdas[x][y]));
|
||||||
if (x == 1) {
|
if (x == 1) {
|
||||||
// Left door frame
|
// Left door frame
|
||||||
try {
|
try {
|
||||||
@ -380,7 +351,7 @@ 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(null, celdas[x][y]));
|
celdas[x][y].setObject(new Obstacle(this, celdas[x][y]));
|
||||||
if (y % 2 == 0) {
|
if (y % 2 == 0) {
|
||||||
try {
|
try {
|
||||||
celdas[x][y].addTexture(textureSheet.getTexture(49), 49);
|
celdas[x][y].addTexture(textureSheet.getTexture(49), 49);
|
||||||
@ -401,7 +372,7 @@ 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(null, celdas[x][y]));
|
celdas[x][y].setObject(new Obstacle(this, celdas[x][y]));
|
||||||
if (y % 2 == 0) {
|
if (y % 2 == 0) {
|
||||||
try {
|
try {
|
||||||
celdas[x][y].addTexture(textureSheet.getTexture(53), 53);
|
celdas[x][y].addTexture(textureSheet.getTexture(53), 53);
|
||||||
@ -422,7 +393,7 @@ 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(null, celdas[x][y]));
|
celdas[x][y].setObject(new Obstacle(this, celdas[x][y]));
|
||||||
if (x % 2 == 0) {
|
if (x % 2 == 0) {
|
||||||
try {
|
try {
|
||||||
celdas[x][y].addTexture(textureSheet.getTexture(98), 98);
|
celdas[x][y].addTexture(textureSheet.getTexture(98), 98);
|
||||||
@ -443,10 +414,9 @@ public class Escenario extends JComponent implements Constantes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The player starts at the door
|
// The player starts at the door
|
||||||
if (x == 2 && y == 1) {
|
/*if (x == 2 && y == 1) {
|
||||||
celdas[x][y].setObject(new Player(null, celdas[x][y]));
|
celdas[x][y].setObject(new Player(this, celdas[x][y]));
|
||||||
player = celdas[x][y];
|
}*/
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -491,51 +461,6 @@ public class Escenario extends JComponent implements Constantes {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the player cell
|
|
||||||
*
|
|
||||||
* @return Returns a cell that contains the player
|
|
||||||
*/
|
|
||||||
public Celda getPlayer() {
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the portal
|
|
||||||
*
|
|
||||||
* @return Returns the cell contain the portal
|
|
||||||
*/
|
|
||||||
public Celda getPortal() {
|
|
||||||
return portal;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the enemies
|
|
||||||
*
|
|
||||||
* @return Returns an array list containing the enemies
|
|
||||||
*/
|
|
||||||
public ArrayList<Celda> getEnemies() {
|
|
||||||
return enemies;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the chests
|
|
||||||
*
|
|
||||||
* @return Returns an array list containing the chests
|
|
||||||
*/
|
|
||||||
public ArrayList<Celda> getChests() {
|
|
||||||
return chests;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the keys
|
|
||||||
*
|
|
||||||
* @return Returns an array list containing the keys
|
|
||||||
*/
|
|
||||||
public ArrayList<Celda> getKeys() {
|
|
||||||
return keys;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the parent canvas of this scene
|
* Get the parent canvas of this scene
|
||||||
* @return Returns the parent canvas
|
* @return Returns the parent canvas
|
||||||
|
@ -30,8 +30,6 @@ import java.awt.event.KeyEvent;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.locks.Lock;
|
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -139,28 +137,17 @@ public class Lienzo extends Canvas implements Constantes {
|
|||||||
setBackground(Color.black);
|
setBackground(Color.black);
|
||||||
setSize(escenario.width, escenario.height);
|
setSize(escenario.width, escenario.height);
|
||||||
|
|
||||||
addKeyListener(new KeyAdapter() {
|
|
||||||
@Override
|
|
||||||
public void keyPressed(KeyEvent event) {
|
|
||||||
super.keyPressed(event);
|
|
||||||
if (!gameOver) {
|
|
||||||
player.keyPressed(event);
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
player = new Player(escenario, escenario.getPlayer());
|
|
||||||
escenario.getPlayer().setObject(player);
|
|
||||||
threads.put(player, new Thread(player));
|
|
||||||
|
|
||||||
final Lock lock = new ReentrantLock(true);
|
|
||||||
|
|
||||||
Enemy.Direction enemyDirection = Enemy.Direction.DOWN;
|
Enemy.Direction enemyDirection = Enemy.Direction.DOWN;
|
||||||
for (Celda celda : escenario.getEnemies()) {
|
|
||||||
Enemy enemy = new Enemy(escenario, celda, lock);
|
ArrayList<Object> objectList = escenario.generateRandomObjects();
|
||||||
celda.setObject(enemy);
|
for (Object object : objectList) {
|
||||||
enemy.setDirection(enemyDirection);
|
object.getCelda().setObject(object);
|
||||||
|
if (object instanceof Player) {
|
||||||
|
player = (Player) object;
|
||||||
|
threads.put(object, new Thread(object));
|
||||||
|
}
|
||||||
|
else if (object instanceof Enemy) {
|
||||||
|
((Enemy) object).setDirection(enemyDirection);
|
||||||
if (enemyDirection == Enemy.Direction.UP) {
|
if (enemyDirection == Enemy.Direction.UP) {
|
||||||
enemyDirection = Enemy.Direction.DOWN;
|
enemyDirection = Enemy.Direction.DOWN;
|
||||||
}
|
}
|
||||||
@ -173,32 +160,38 @@ public class Lienzo extends Canvas implements Constantes {
|
|||||||
else {
|
else {
|
||||||
enemyDirection = Enemy.Direction.UP;
|
enemyDirection = Enemy.Direction.UP;
|
||||||
}
|
}
|
||||||
enemies.add(enemy);
|
enemies.add((Enemy) object);
|
||||||
threads.put(enemy, new Thread(enemy));
|
threads.put(object, new Thread(object));
|
||||||
}
|
}
|
||||||
|
else if (object instanceof Chest) {
|
||||||
for (Celda celda : escenario.getKeys()) {
|
chests.add((Chest) object);
|
||||||
Key key = new Key(escenario, celda);
|
threads.put(object, new Thread(object));
|
||||||
celda.setObject(key);
|
}
|
||||||
keys.add(key);
|
else if (object instanceof Key) {
|
||||||
threads.put(key, new Thread(key));
|
keys.add((Key) object);
|
||||||
|
threads.put(object, new Thread(object));
|
||||||
|
}
|
||||||
|
else if (object instanceof Portal) {
|
||||||
|
portal = (Portal) object;
|
||||||
|
threads.put(object, new Thread(object));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Celda celda : escenario.getChests()) {
|
|
||||||
Chest chest = new Chest(escenario, celda);
|
|
||||||
celda.setObject(chest);
|
|
||||||
chests.add(chest);
|
|
||||||
threads.put(chest, new Thread(chest));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
portal = new Portal(escenario, escenario.getPortal());
|
|
||||||
escenario.getPortal().setObject(portal);
|
|
||||||
threads.put(portal, new Thread(portal));
|
|
||||||
|
|
||||||
for (Map.Entry<Object, Thread> entry : threads.entrySet()) {
|
for (Map.Entry<Object, Thread> entry : threads.entrySet()) {
|
||||||
Thread thread = entry.getValue();
|
Thread thread = entry.getValue();
|
||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addKeyListener(new KeyAdapter() {
|
||||||
|
@Override
|
||||||
|
public void keyPressed(KeyEvent event) {
|
||||||
|
super.keyPressed(event);
|
||||||
|
if (!gameOver) {
|
||||||
|
player.keyPressed(event);
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -226,16 +219,14 @@ public class Lienzo extends Canvas implements Constantes {
|
|||||||
graphicBuffer.fillRect(0, 0, this.getWidth(), this.getHeight());
|
graphicBuffer.fillRect(0, 0, this.getWidth(), this.getHeight());
|
||||||
|
|
||||||
int xKey = LEFT_MARGIN;
|
int xKey = LEFT_MARGIN;
|
||||||
for (int i = 0; i < keys.size(); i++) {
|
for (Key key : keys) {
|
||||||
Key key = keys.get(i);
|
|
||||||
if (key.getState() == Key.State.HELD) {
|
if (key.getState() == Key.State.HELD) {
|
||||||
// Set a still frame of the key
|
|
||||||
//key.setAnimationFrame(4);
|
|
||||||
key.drawAnimation(graphicBuffer, xKey, 8);
|
key.drawAnimation(graphicBuffer, xKey, 8);
|
||||||
xKey = xKey + ((key.getAnimationWidth() + 5) * (i + 1));
|
xKey = xKey + 3 + (key.getAnimationWidth());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (player != null) {
|
||||||
int health = player.getHealth();
|
int health = player.getHealth();
|
||||||
if (health == 0) {
|
if (health == 0) {
|
||||||
gameOver = true;
|
gameOver = true;
|
||||||
@ -263,6 +254,7 @@ public class Lienzo extends Canvas implements Constantes {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (gameOver) {
|
if (gameOver) {
|
||||||
if (!gameOverRan) {
|
if (!gameOverRan) {
|
||||||
@ -442,13 +434,4 @@ public class Lienzo extends Canvas implements Constantes {
|
|||||||
public ArrayList<Chest> getChests() {
|
public ArrayList<Chest> getChests() {
|
||||||
return chests;
|
return chests;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the threads that have been created
|
|
||||||
*
|
|
||||||
* @return Returns the threads that run in the background
|
|
||||||
*/
|
|
||||||
public HashMap<Object, Thread> getThreads() {
|
|
||||||
return threads;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,90 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2019 Chris Cromer
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
package cl.cromer.azaraka;
|
|
||||||
|
|
||||||
import cl.cromer.azaraka.object.Object;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class is used to save locations of random cells for enemies, obstacles, chests, etc
|
|
||||||
*/
|
|
||||||
public class RandomPositionList {
|
|
||||||
/**
|
|
||||||
* The x position
|
|
||||||
*/
|
|
||||||
private int x;
|
|
||||||
/**
|
|
||||||
* The y position
|
|
||||||
*/
|
|
||||||
private int y;
|
|
||||||
/**
|
|
||||||
* The object
|
|
||||||
*/
|
|
||||||
private Object object;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize the position and type of the list
|
|
||||||
* @param x The x position
|
|
||||||
* @param y The y position
|
|
||||||
* @param object The object
|
|
||||||
*/
|
|
||||||
public RandomPositionList(int x, int y, Object object) {
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
this.object = object;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the x position
|
|
||||||
* @return Returns the x position
|
|
||||||
*/
|
|
||||||
public int getX() {
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the y position
|
|
||||||
*
|
|
||||||
* @return Returns the y position
|
|
||||||
*/
|
|
||||||
public int getY() {
|
|
||||||
return y;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the type of object that will be stored at the cell position
|
|
||||||
* @return Returns the cell type
|
|
||||||
*/
|
|
||||||
public Object getObject() {
|
|
||||||
return object;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Override the equals method so that we only compare the position and not the type
|
|
||||||
* @param o The object to compare
|
|
||||||
* @return Returns true if they are the same
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean equals(java.lang.Object o) {
|
|
||||||
if (this == o) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (o == null || getClass() != o.getClass()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
RandomPositionList that = (RandomPositionList) o;
|
|
||||||
return (x == that.x && y == that.y);
|
|
||||||
}
|
|
||||||
}
|
|
@ -176,6 +176,15 @@ public class Key extends Object implements Constantes {
|
|||||||
getEscenario().getCanvas().repaint();
|
getEscenario().getCanvas().repaint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// The thread was killed, set the animation to frame 4
|
||||||
|
try {
|
||||||
|
if (getAnimation().getCurrentFrame() != 4) {
|
||||||
|
getAnimation().setCurrentFrame(4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (AnimationException e) {
|
||||||
|
getLogger().warning(e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,33 +53,19 @@ public class Sound implements Constantes {
|
|||||||
if (inputStream == null) {
|
if (inputStream == null) {
|
||||||
throw new SoundException("Could not load sound: " + path);
|
throw new SoundException("Could not load sound: " + path);
|
||||||
}
|
}
|
||||||
AudioInputStream audioInputStream = null;
|
|
||||||
try {
|
try {
|
||||||
audioInputStream = AudioSystem.getAudioInputStream(new BufferedInputStream(inputStream));
|
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new BufferedInputStream(inputStream));
|
||||||
}
|
DataLine.Info info = new DataLine.Info(Clip.class, audioInputStream.getFormat());
|
||||||
catch (UnsupportedAudioFileException | IOException e) {
|
|
||||||
logger.warning(e.getMessage());
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
DataLine.Info info = null;
|
|
||||||
if (audioInputStream != null) {
|
|
||||||
info = new DataLine.Info(Clip.class, audioInputStream.getFormat());
|
|
||||||
}
|
|
||||||
sound = (Clip) AudioSystem.getLine(info);
|
sound = (Clip) AudioSystem.getLine(info);
|
||||||
|
sound.open(audioInputStream);
|
||||||
|
audioInputStream.close();
|
||||||
}
|
}
|
||||||
catch (LineUnavailableException e) {
|
catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
|
||||||
logger.warning(e.getMessage());
|
logger.warning(e.getMessage());
|
||||||
}
|
}
|
||||||
try {
|
finally {
|
||||||
if (audioInputStream != null) {
|
|
||||||
sound.open(audioInputStream);
|
|
||||||
sound.stop();
|
sound.stop();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (LineUnavailableException | IOException e) {
|
|
||||||
logger.warning(e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info("Opened sound: " + path);
|
logger.info("Opened sound: " + path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,72 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2019 Chris Cromer
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
package cl.cromer.azaraka.test;
|
|
||||||
|
|
||||||
import cl.cromer.azaraka.Celda;
|
|
||||||
import cl.cromer.azaraka.RandomPositionList;
|
|
||||||
import cl.cromer.azaraka.object.Player;
|
|
||||||
import org.junit.jupiter.api.AfterEach;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test the random position position list to make sure it has expected values
|
|
||||||
*/
|
|
||||||
class RandomPositionListTest {
|
|
||||||
private RandomPositionList randomPositionList;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a random position list
|
|
||||||
*/
|
|
||||||
@BeforeEach
|
|
||||||
void setUp() {
|
|
||||||
randomPositionList = new RandomPositionList(2, 3, new Player(null, new Celda(0, 0, 0, 0)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Destroy the random position list
|
|
||||||
*/
|
|
||||||
@AfterEach
|
|
||||||
void tearDown() {
|
|
||||||
randomPositionList = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the x position is correct
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
void getX() {
|
|
||||||
assertEquals(2, randomPositionList.getX(), "The position should be 2");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the y position is correct
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
void getY() {
|
|
||||||
assertEquals(3, randomPositionList.getY(), "The position should be 3");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the type is correct
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
void getType() {
|
|
||||||
assertEquals(Player.class.getName(), randomPositionList.getObject().getClass().getName(), "The type should be player");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,103 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2019 Chris Cromer
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
package cl.cromer.azaraka.test.object;
|
|
||||||
|
|
||||||
import cl.cromer.azaraka.Escenario;
|
|
||||||
import cl.cromer.azaraka.Lienzo;
|
|
||||||
import cl.cromer.azaraka.object.Player;
|
|
||||||
import org.junit.jupiter.api.AfterEach;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.event.KeyEvent;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test the playser object
|
|
||||||
*/
|
|
||||||
class PlayerTest {
|
|
||||||
/**
|
|
||||||
* A player object to test
|
|
||||||
*/
|
|
||||||
private Player player;
|
|
||||||
/**
|
|
||||||
* The canvas the scene is in
|
|
||||||
*/
|
|
||||||
private Lienzo lienzo;
|
|
||||||
/**
|
|
||||||
* The scene the player is in
|
|
||||||
*/
|
|
||||||
private Escenario escenario;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create the canvas, scene, and then the player
|
|
||||||
*/
|
|
||||||
@BeforeEach
|
|
||||||
void setUp() {
|
|
||||||
lienzo = new Lienzo();
|
|
||||||
lienzo.changeVolume(0);
|
|
||||||
escenario = new Escenario(lienzo);
|
|
||||||
player = new Player(escenario, escenario.getPlayer());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Destroy it all
|
|
||||||
*/
|
|
||||||
@AfterEach
|
|
||||||
void tearDown() {
|
|
||||||
player = null;
|
|
||||||
escenario = null;
|
|
||||||
lienzo = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test key press events and see if the player is where he should be
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
void keyPressed() {
|
|
||||||
int expected = 2;
|
|
||||||
if (escenario.getCeldas()[player.getX() - 1][player.getY()].getObject() == null) {
|
|
||||||
expected--;
|
|
||||||
}
|
|
||||||
player.keyPressed(new KeyEvent(new Component() {
|
|
||||||
}, 0, 0, 0, KeyEvent.VK_LEFT, KeyEvent.getKeyText(KeyEvent.VK_LEFT).charAt(0)));
|
|
||||||
assertEquals(expected, player.getX(), "The player should be at x = 1" + expected);
|
|
||||||
|
|
||||||
if (escenario.getCeldas()[player.getX() + 1][player.getY()].getObject() == null) {
|
|
||||||
expected++;
|
|
||||||
}
|
|
||||||
player.keyPressed(new KeyEvent(new Component() {
|
|
||||||
}, 0, 0, 0, KeyEvent.VK_RIGHT, KeyEvent.getKeyText(KeyEvent.VK_RIGHT).charAt(0)));
|
|
||||||
assertEquals(expected, player.getX(), "The player should be at x = 2" + expected);
|
|
||||||
|
|
||||||
expected = 1;
|
|
||||||
if (escenario.getCeldas()[player.getX()][player.getY() + 1].getObject() == null) {
|
|
||||||
expected++;
|
|
||||||
}
|
|
||||||
player.keyPressed(new KeyEvent(new Component() {
|
|
||||||
}, 0, 0, 0, KeyEvent.VK_DOWN, KeyEvent.getKeyText(KeyEvent.VK_DOWN).charAt(0)));
|
|
||||||
assertEquals(expected, player.getY(), "The player should be at y = " + expected);
|
|
||||||
|
|
||||||
if (escenario.getCeldas()[player.getX()][player.getY() - 1].getObject() == null) {
|
|
||||||
expected--;
|
|
||||||
}
|
|
||||||
player.keyPressed(new KeyEvent(new Component() {
|
|
||||||
}, 0, 0, 0, KeyEvent.VK_UP, KeyEvent.getKeyText(KeyEvent.VK_UP).charAt(0)));
|
|
||||||
assertEquals(expected, player.getY(), "The player should be at y = " + expected);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user