Cleanup code

Signed-off-by: Chris Cromer <chris@cromer.cl>
This commit is contained in:
Chris Cromer 2019-10-11 14:08:22 -03:00
parent 81432f3243
commit 000a5e1fde
13 changed files with 62 additions and 64 deletions

View File

@ -12,8 +12,6 @@
# 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.
#
#
#Thu Oct 03 19:38:30 CLST 2019
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists

View File

@ -22,14 +22,14 @@ import java.util.logging.Logger;
* The main class of the game
*/
public class Azaraka implements Constants {
/**
* The main window
*/
private MainWindow mainWindow;
/**
* The logger
*/
private final Logger logger;
/**
* The main window
*/
private MainWindow mainWindow;
/**
* The main game class
@ -39,6 +39,24 @@ public class Azaraka implements Constants {
start();
}
/**
* Open the main window
*
* @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();
}
/**
* Restart the game
*/
@ -58,22 +76,4 @@ public class Azaraka implements Constants {
mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
/**
* Open the main window
*
* @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

@ -80,6 +80,18 @@ public class Canvas extends java.awt.Canvas implements Constants {
* The game over animation
*/
private final Animation gameOverAnimation;
/**
* The left margin of the game
*/
private final int leftMargin;
/**
* The top margin of the game
*/
private final int topMargin;
/**
* The threads that control AI
*/
private final HashMap<AI, Thread> aiThreads = new HashMap<>();
/**
* The graphics buffer
*/
@ -100,14 +112,6 @@ public class Canvas extends java.awt.Canvas implements Constants {
* The hearts animation
*/
private Animation heartAnimation;
/**
* The left margin of the game
*/
private final int leftMargin;
/**
* The top margin of the game
*/
private final int topMargin;
/**
* The game scene
*/
@ -152,10 +156,6 @@ public class Canvas extends java.awt.Canvas implements Constants {
* The sound of the door opening or closing
*/
private Sound doorSound;
/**
* The threads that control AI
*/
private final HashMap<AI, Thread> aiThreads = new HashMap<>();
/**
* The sound when a gem is received
*/
@ -173,8 +173,8 @@ public class Canvas extends java.awt.Canvas implements Constants {
* Initialize the canvas
*
* @param azaraka The main window
* @param width The width to set the canvas
* @param height The width to set the canvas
* @param width The width to set the canvas
* @param height The width to set the canvas
*/
public Canvas(Azaraka azaraka, int width, int height) {
logger = getLogger(this.getClass(), LogLevel.LIENZO);

View File

@ -60,7 +60,7 @@ public class BreadthFirstSearch extends AI {
/**
* Find a path to the objective
*
* @param searchInitial The start point
* @param searchInitial The start point
* @param searchObjective The objective
* @return Returns true if a path was found or false otherwise
*/
@ -217,8 +217,8 @@ public class BreadthFirstSearch extends AI {
* This method is called when the player arrives at a destination
*
* @param objective The objective the player arrived at
* @throws AIException Thrown if the method is called via super
* @return Returns true if the destination condition is valid or false otherwise
* @throws AIException Thrown if the method is called via super
*/
protected boolean destinationArrived(State objective) throws AIException {
String methodName = new Throwable().getStackTrace()[0].getMethodName();

View File

@ -39,8 +39,8 @@ public class PlayerAI extends BreadthFirstSearch implements Constants {
/**
* Initialize the algorithm
*
* @param scene The scene the AI is in
* @param player The player controlled by the AI
* @param scene The scene the AI is in
* @param player The player controlled by the AI
*/
public PlayerAI(Scene scene, Player player) {
super();

View File

@ -50,7 +50,7 @@ public class Chest extends Object implements Constants {
* Initialize the chest
*
* @param scene The scene the chest is in
* @param cell The cell that contains the chest
* @param cell The cell that contains the chest
*/
public Chest(Scene scene, Cell cell) {
super(scene, cell);

View File

@ -47,8 +47,8 @@ public class Enemy extends Object implements Constants {
* Initialize the enemy
*
* @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
* @param cell The cell this enemy is in
* @param lock The lock used to prevent the threads from conflicting
*/
public Enemy(Scene scene, Cell cell, Lock lock) {
super(scene, cell);

View File

@ -47,7 +47,7 @@ public class Gem extends Object {
* Initialize the gem object
*
* @param scene The scene the gem is in
* @param cell The cell the gem is in
* @param cell The cell the gem is in
*/
public Gem(Scene scene, Cell cell) {
super(scene, cell);

View File

@ -42,7 +42,7 @@ public class Key extends Object implements Constants {
* Initialize the key
*
* @param scene The scene the key is in
* @param cell The cell the key is in
* @param cell The cell the key is in
*/
public Key(Scene scene, Cell cell) {
super(scene, cell);

View File

@ -76,7 +76,7 @@ public class Object implements Runnable, Constants {
* Initialize the object
*
* @param scene The scene the object is in
* @param cell The cell the object is in
* @param cell The cell the object is in
*/
protected Object(Scene scene, Cell cell) {
this.scene = scene;

View File

@ -26,7 +26,7 @@ public class Obstacle extends Object {
* Initialize the obstacle
*
* @param scene The scene the object is in
* @param cell The cell the object is in
* @param cell The cell the object is in
*/
public Obstacle(Scene scene, Cell cell) {
super(scene, cell);

View File

@ -37,20 +37,20 @@ public class Player extends Object implements Constants {
* Objects that the player is carrying
*/
private final ArrayList<Object> carrying = new ArrayList<>();
/**
* The current health of the player
*/
private int health = MAX_HEALTH;
/**
* The artificial intelligence of the player
*/
private final PlayerAI ai;
/**
* The current health of the player
*/
private int health = MAX_HEALTH;
/**
* Initialize the player
*
* @param scene The scene the player is in
* @param cell The cell the player is in
* @param cell The cell the player is in
*/
public Player(Scene scene, Cell cell) {
super(scene, cell);

View File

@ -50,7 +50,7 @@ public class Portal extends Object implements Constants {
* Initialize the portal
*
* @param scene The scene that contains the portal
* @param cell The cell the portal is in
* @param cell The cell the portal is in
*/
public Portal(Scene scene, Cell cell) {
super(scene, cell);
@ -141,6 +141,15 @@ public class Portal extends Object implements Constants {
}
}
/**
* Get the current state of the portal
*
* @return Returns the state of the portal
*/
public State getState() {
return state;
}
/**
* Sets a new status for the portal
*
@ -179,15 +188,6 @@ public class Portal extends Object implements Constants {
}
}
/**
* Get the current state of the portal
*
* @return Returns the state of the portal
*/
public State getState() {
return state;
}
/**
* This method is run when the thread starts
*/