Original Post
for handling different gamestates in my applet, i have something like this:
interface GameState
{
public boolean onKeyDown ();
public boolean onKeyUp ();
public void run ( long curTime );
public void draw ( Graphics g );
};
Several gamestate classes are derived from this interface, and the applet stores an "GameState ActiveState;" variable somewhere, and just delegates all events to it.
my question is, would it be a bad coding technique to switch gamestates like in the following example, where i just switch the "global" ActiveState inside of another gamestate class:
public void run ( long curTime )
{
if ( Keys[KeyEvent.VK_ESCAPE] )
{ //back to the mainmenu...
ActiveState = new MenuGameState ();
return;
}
}
(in C++, ActiveState (the ''this'' pointer actually) would have to be deallocated first - a bit ugly but it would work.)
i hope you get the idea..