package gameapi1;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

public class SimpleGame extends MIDlet {

    private Display display;
    private SimpleGameCanvas game;
    private Command exitCom;
    
    public SimpleGame() {
        game = new SimpleGameCanvas();
        exitCom = new Command("Exit", Command.EXIT, 1);
        game.addCommand(exitCom);
        
        game.setCommandListener(new CommandListener() {
            public void commandAction(Command c, Displayable d) {
                if(c == exitCom) {
                    try {
                        destroyApp(true);
                        notifyDestroyed();
                    } catch (MIDletStateChangeException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
    }

    protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
        // TODO Auto-generated method stub

    }

    protected void pauseApp() {
        game.stop();

    }

    protected void startApp() throws MIDletStateChangeException {
        if(display == null) {
            display = Display.getDisplay(this);
            display.setCurrent(game);
        }
        game.start();

    }

}
