This document summarizes code for a basic game menu structure and implementation in Java ME for mobile devices.
The document includes 5 sections:
1. It introduces a basic main menu screen class with options like New Game, Settings, High Scores, Help and About.
2. It provides code for submenu screens like settings, high scores, help and about screens.
3. It includes code for a scrolling terrain background layer.
4. It provides an example player sprite class with methods for movement.
5. The main midlet class integrates the menu and subscreens.
8. Eliminator: Game Menu, EliminatorSubMenu (2)
High Score Screen Source Code:
import javax.microedition.lcdui.*;
public class HighScoreScreen extends Form implements CommandListener {
private Eliminator midlet;
private Command backCommand = new Command("Back", Command.BACK,1);
private Command resetCommand = new Command("Rest", Command.SCREEN,1);
public HighScoreScreen (Eliminator midlet) {
super("High Score");
this.midlet = midlet;
StringItem stringItem = new StringItem(null,"JL 100nJL 50nJL 10");
append(stringItem);
addCommand(backCommand);
addCommand(resetCommand); setCommandListener(this); }
public void commandAction(Command c, Displayable d) {
if (c == backCommand) {
midlet.mainMenuScreenShow();
return;
}if (c == resetCommand) { // not implemented yet
System.out.println("Reset High Scores Not Implemented Yet");
}}}
8
9. Eliminator: Game Menu, EliminatorSubMenu (3)
Help Screen Source Code:
import javax.microedition.lcdui.*;
public class HelpScreen extends Form implements CommandListener {
private Eliminator midlet;
private Command backCommand = new Command("Back", Command.BACK, 1);
public HelpScreen (Eliminator midlet) {
super("Help");
this.midlet = midlet;
StringItem stringItem = new StringItem(null,"It is the year 3023, many things have changed over
the years " +
…………
);
append(stringItem); addCommand(backCommand);
setCommandListener(this); }
public void commandAction(Command c, Displayable d) {
if (c == backCommand) {
midlet.mainMenuScreenShow();
return;
}}}
9
10. Eliminator: Game Menu, EliminatorSubMenu (4)
About Screen Source Code:
import javax.microedition.lcdui.*;
public class AboutScreen extends Form implements CommandListener {
private Eliminator midlet;
private Command backCommand = new Command("Back", Command.BACK, 1);
public AboutScreen (Eliminator midlet) {
super("About");
this.midlet = midlet;
StringItem stringItem = new StringItem(null,"EliminatornVersion 1.0.0nBy Jason Lam");
append(stringItem);
addCommand(backCommand); setCommandListener(this);
}
public void commandAction(Command c, Displayable d) {
if (c == backCommand) {
midlet.mainMenuScreenShow();
return;
}}}
10