Skip to content
Snippets Groups Projects
Commit c5e3de9d authored by Rebekka Aashaug Stangvik's avatar Rebekka Aashaug Stangvik
Browse files

Merge branch '34-make-statemanager-a-singleton-class' into 'main'

added singleton pattern to state manager

Closes #34

See merge request !25
parents 34bf64c5 68418c3b
No related branches found
No related tags found
1 merge request!25added singleton pattern to state manager
...@@ -28,7 +28,7 @@ public class WordBattle extends ApplicationAdapter { ...@@ -28,7 +28,7 @@ public class WordBattle extends ApplicationAdapter {
public void create() { public void create() {
_FBIC.SomeFunction(); _FBIC.SomeFunction();
batch = new SpriteBatch(); batch = new SpriteBatch();
stateManager = new StateManager(); stateManager = StateManager.getInstance();
// Make changes in assets/words.txt, and uncomment the two lines beneath to update database // Make changes in assets/words.txt, and uncomment the two lines beneath to update database
// CreateWords createWords = new CreateWords(_FBIC); // CreateWords createWords = new CreateWords(_FBIC);
// createWords.updateDB(); // createWords.updateDB();
......
...@@ -2,9 +2,11 @@ package com.wordbattle.game.states; ...@@ -2,9 +2,11 @@ package com.wordbattle.game.states;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public class StateManager { import java.security.SecureRandom;
public class StateManager {
private static StateManager instance;
private GameState currentState; private GameState currentState;
private GameState previousState; private GameState previousState;
...@@ -12,6 +14,12 @@ public class StateManager { ...@@ -12,6 +14,12 @@ public class StateManager {
} }
public static StateManager getInstance() {
if(instance == null){
instance = new StateManager();
}
return instance;
}
public void setState(GameState newState) { public void setState(GameState newState) {
if (currentState != null) { if (currentState != null) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment