Hello, sorry for bad english.
I am working at small java game in slick2D. I have a problem with states. I’m adding them in main class like this:
public static final int map = 10;
public static final int recBack = 0;
public static final int recDiv = 1;
public static final int Prim = 2;
@Override
public void initStatesList(GameContainer gc) throws SlickException {
this.addState(new Level(recBack, new RecursiveBacktracking()));
this.addState(new Level(recDiv, new RecursiveDivision()));
this.addState(new Level(Prim, new PrimsAlg()));
this.addState(new Map(map));
this.enterState(recBack); ///<<<<-------------------------------------
// this.getState(recBack).init(gc, this);
// this.getState(recDiv).init(gc, this);
// this.getState(Prim).init(gc, this);
// this.getState(map).init(gc, this);
//
// this.enterState(recBack);
}
Whatever state I try to enter, it always starts with one with biggest stateID (excluding Map, which doesn’t have anything in init()).
Later in code of state, I try to enter other state if conditions are met, it just restarts the same level, but stateID changes:
if ((hero.getBlockX() == GridX - 1) && (hero.getBlockY() == GridY - 1) && (grid.getLockState())) {
if (state == (Main.getInstance().getStateCount() - 2)) {
nextstate = 0;
} else {
nextstate = state + 1;
}
//Main.getInstance().getState(state).leave(gc, sbg);
//Main.getInstance().getState(nextstate).init(gc, Main.getInstance());
//Main.getInstance().getState(nextstate).enter(gc, Main.getInstance());
Main.getInstance().enterState(nextstate); //<<<----------------------------------
initialized = false;
}
I’m quite stressed because this is part of my bachelor work, I really apreciate any help.
Full code of mentioned classes here:
Main: http://pastebin.com/i9kZTpN8 (I am using own method for current state because native one worked wierdly…)
Level (state): http://pastebin.com/Jyvva6Wt
Map: http://pastebin.com/7fhgpkir