Reimplement singleton classes and update copyrights

Signed-off-by: Chris Cromer <chris@cromer.cl>
This commit is contained in:
Chris Cromer 2020-02-26 19:12:21 -03:00
parent 18a04d2d07
commit 6c2665b1c5
40 changed files with 103 additions and 43 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2019 Chris Cromer * Copyright 2020 Chris Cromer
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* *

View File

@ -1,5 +1,5 @@
# #
# Copyright 2019 Chris Cromer # Copyright 2020 Chris Cromer
# #
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: # Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
# #

View File

@ -1,5 +1,5 @@
# #
# Copyright 2019 Chris Cromer # Copyright 2020 Chris Cromer
# #
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: # Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
# #

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2019 Chris Cromer * Copyright 2020 Chris Cromer
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* *

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2019 Chris Cromer * Copyright 2020 Chris Cromer
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* *

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2019 Chris Cromer * Copyright 2020 Chris Cromer
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* *
@ -514,6 +514,8 @@ public class Canvas extends java.awt.Canvas implements Constants {
public void keyPressed(KeyEvent event) { public void keyPressed(KeyEvent event) {
super.keyPressed(event); super.keyPressed(event);
if (event.getKeyCode() == KeyEvent.VK_ENTER) { if (event.getKeyCode() == KeyEvent.VK_ENTER) {
player.deleteInstance();
portal.deleteInstance();
azaraka.restart(); azaraka.restart();
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2019 Chris Cromer * Copyright 2020 Chris Cromer
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* *

View File

@ -41,7 +41,7 @@ public interface Constants {
/** /**
* Which type of AI to use * Which type of AI to use
*/ */
PlayerAIType PLAYER_AI = PlayerAIType.ASTAR; PlayerAIType PLAYER_AI = PlayerAIType.HUMAN;
/** /**
* Whether or not the enemies should be controlled by AI * Whether or not the enemies should be controlled by AI
*/ */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2019 Chris Cromer * Copyright 2020 Chris Cromer
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* *

View File

@ -135,7 +135,7 @@ public class Scene extends JComponent implements Constants {
cells.get(x).add(cell); cells.get(x).add(cell);
if (jsonCells[x][y].type.equals(Player.class.getName())) { if (jsonCells[x][y].type.equals(Player.class.getName())) {
cells.get(x).get(y).setObject(new Player(null, cells.get(x).get(y))); cells.get(x).get(y).setObject(Player.getInstance(null, cells.get(x).get(y)));
} }
else if (jsonCells[x][y].type.equals(Enemy.class.getName())) { else if (jsonCells[x][y].type.equals(Enemy.class.getName())) {
cells.get(x).get(y).setObject(new Enemy(null, cells.get(x).get(y), null)); cells.get(x).get(y).setObject(new Enemy(null, cells.get(x).get(y), null));
@ -153,7 +153,7 @@ public class Scene extends JComponent implements Constants {
cells.get(x).get(y).setObject(new Obstacle(null, cells.get(x).get(y))); cells.get(x).get(y).setObject(new Obstacle(null, cells.get(x).get(y)));
} }
else if (jsonCells[x][y].type.equals(Portal.class.getName())) { else if (jsonCells[x][y].type.equals(Portal.class.getName())) {
cells.get(x).get(y).setObject(new Portal(null, cells.get(x).get(y))); cells.get(x).get(y).setObject(Portal.getInstance(null, cells.get(x).get(y)));
} }
for (int k = 0; k < jsonCells[x][y].textures.size(); k++) { for (int k = 0; k < jsonCells[x][y].textures.size(); k++) {
@ -178,7 +178,7 @@ public class Scene extends JComponent implements Constants {
List<Object> objectArrayList = new ArrayList<>(); List<Object> objectArrayList = new ArrayList<>();
// The player has a fixed position // The player has a fixed position
cells.get(2).get(1).setObject(new Player(this, cells.get(2).get(1))); cells.get(2).get(1).setObject(Player.getInstance(this, cells.get(2).get(1)));
objectArrayList.add(cells.get(2).get(1).getObject()); objectArrayList.add(cells.get(2).get(1).getObject());
for (int i = 0; i < OBSTACLES; i++) { for (int i = 0; i < OBSTACLES; i++) {
@ -201,7 +201,7 @@ public class Scene extends JComponent implements Constants {
} }
random = randomCoordinates(); random = randomCoordinates();
cells.get(random[0]).get(random[1]).setObjectOnBottom(new Portal(this, cells.get(random[0]).get(random[1]))); cells.get(random[0]).get(random[1]).setObjectOnBottom(Portal.getInstance(this, cells.get(random[0]).get(random[1])));
objectArrayList.add(cells.get(random[0]).get(random[1]).getObjectOnBottom()); objectArrayList.add(cells.get(random[0]).get(random[1]).getObjectOnBottom());
// Generate enough keys for the chests that will exist // Generate enough keys for the chests that will exist

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2019 Chris Cromer * Copyright 2020 Chris Cromer
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* *

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2019 Chris Cromer * Copyright 2020 Chris Cromer
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* *

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2019 Chris Cromer * Copyright 2020 Chris Cromer
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* *

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2019 Chris Cromer * Copyright 2020 Chris Cromer
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* *

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2019 Chris Cromer * Copyright 2020 Chris Cromer
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* *

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2019 Chris Cromer * Copyright 2020 Chris Cromer
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* *

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2019 Chris Cromer * Copyright 2020 Chris Cromer
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* *

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2019 Chris Cromer * Copyright 2020 Chris Cromer
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* *

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2019 Chris Cromer * Copyright 2020 Chris Cromer
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* *

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2019 Chris Cromer * Copyright 2020 Chris Cromer
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* *

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2019 Chris Cromer * Copyright 2020 Chris Cromer
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* *

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2019 Chris Cromer * Copyright 2020 Chris Cromer
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* *

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2019 Chris Cromer * Copyright 2020 Chris Cromer
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* *

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2019 Chris Cromer * Copyright 2020 Chris Cromer
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* *

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2019 Chris Cromer * Copyright 2020 Chris Cromer
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* *

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2019 Chris Cromer * Copyright 2020 Chris Cromer
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* *

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2019 Chris Cromer * Copyright 2020 Chris Cromer
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* *

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2019 Chris Cromer * Copyright 2020 Chris Cromer
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* *

View File

@ -48,6 +48,10 @@ public class Player extends Object implements Constants {
* The current health of the player * The current health of the player
*/ */
private int health = MAX_HEALTH; private int health = MAX_HEALTH;
/**
* The Player instance
*/
private static Player instance;
/** /**
* Initialize the player * Initialize the player
@ -55,7 +59,7 @@ public class Player extends Object implements Constants {
* @param scene The scene the player is in * @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) { private Player(Scene scene, Cell cell) {
super(scene, cell); super(scene, cell);
setLogger(getLogger(this.getClass(), LogLevel.PLAYER)); setLogger(getLogger(this.getClass(), LogLevel.PLAYER));
loadPlayerAnimation(); loadPlayerAnimation();
@ -72,6 +76,31 @@ public class Player extends Object implements Constants {
} }
} }
/**
* Create the Player instance
*
* @param scene The scene the player is in
* @param cell The cell the player is in
* @return Returns the instance
*/
public static Player getInstance(Scene scene, Cell cell) {
if (instance == null) {
synchronized (Player.class) {
if (instance == null) {
instance = new Player(scene, cell);
}
}
}
return instance;
}
/**
* Delete the Player instance
*/
public void deleteInstance() {
instance = null;
}
/** /**
* Load the player animation * Load the player animation
*/ */

View File

@ -45,6 +45,10 @@ public class Portal extends Object implements Constants {
* The portal sound when a gem is purified * The portal sound when a gem is purified
*/ */
private Sound sound; private Sound sound;
/**
* The Portal instance
*/
private static Portal instance;
/** /**
* Initialize the portal * Initialize the portal
@ -52,12 +56,37 @@ public class Portal extends Object implements Constants {
* @param scene The scene that contains 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) { private Portal(Scene scene, Cell cell) {
super(scene, cell); super(scene, cell);
setLogger(getLogger(this.getClass(), LogLevel.PORTAL)); setLogger(getLogger(this.getClass(), LogLevel.PORTAL));
loadPortalAnimations(); loadPortalAnimations();
} }
/**
* Create an instance of the portal
*
* @param scene The scene the portal is in
* @param cell The cell the portal is in
* @return Returns the Portal instance
*/
public static Portal getInstance(Scene scene, Cell cell) {
if (instance == null) {
synchronized (Portal.class) {
if (instance == null) {
instance = new Portal(scene, cell);
}
}
}
return instance;
}
/**
* Delete the Portal instance
*/
public void deleteInstance() {
instance = null;
}
/** /**
* Load the portal animation * Load the portal animation
*/ */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2019 Chris Cromer * Copyright 2020 Chris Cromer
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* *

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2019 Chris Cromer * Copyright 2020 Chris Cromer
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* *

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2019 Chris Cromer * Copyright 2020 Chris Cromer
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* *

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2019 Chris Cromer * Copyright 2020 Chris Cromer
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* *

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2019 Chris Cromer * Copyright 2020 Chris Cromer
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* *

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2019 Chris Cromer * Copyright 2020 Chris Cromer
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* *

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2019 Chris Cromer * Copyright 2020 Chris Cromer
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* *

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2019 Chris Cromer * Copyright 2020 Chris Cromer
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* *

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2019 Chris Cromer * Copyright 2020 Chris Cromer
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* *

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2019 Chris Cromer * Copyright 2020 Chris Cromer
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* *