I am currently learning java and would like to know how to control state in a OO way. I implemented a Pong app. If I wanted multiple states like gameplay and menu, and each one of these states had to execute start, stop and run how would I achieve this and how would I switch between these states.
I know I could simply throw in a big switch statement but what's the best way to implement this?
I want to be able to switch to the menu state in the gameplay state and vice versa.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Pong extends Applet implements Runnable, KeyListener{
public void start ()
{
setSize(screen);
setFocusable(true);
Thread th = new Thread (this);
th.start ();
}
public void stop()
{
}
//Etc..
}