📄 tukmidp.java
字号:
import com.nokia.mid.ui.FullCanvas;
import java.io.PrintStream;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Gauge;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.List;
import javax.microedition.lcdui.Screen;
import javax.microedition.midlet.MIDlet;
public class TukMIDP extends MIDlet
implements Runnable
{
private Display display;
private TukCanvas canvas;
private TukMIDP.FirstCanvas firstCanvas;
private TukMIDP.TitleCanvas titleCanvas;
private Command backCommand;
private Command selectCommand;
private Command okCommand;
private Command startCommand;
private Command settingCommand;
private Command highScoreCommand;
private Command helpCommand;
private Form helpScreen = new Form("Help");
private List menu;
private List settingMenu;
private List carMenu;
private List gearMenu;
private List speedMenu;
private List peopleMenu;
private int speed = 450;
private int people = 5;
private boolean isAutoRun = true;
private Image icon;
private Form progressForm;
private Gauge progressGauge;
private Thread thread;
public TukMIDP()
{
this.display = Display.getDisplay(this);
this.firstCanvas = new TukMIDP.FirstCanvas(this);
this.titleCanvas = new TukMIDP.TitleCanvas(this);
this.startCommand = new Command("Start Game", 1, 1);
this.settingCommand = new Command("Setting", 1, 1);
this.helpCommand = new Command("Help", 1, 1);
this.highScoreCommand = new Command("High Score", 1, 1);
this.backCommand = new Command("Back", 1, 2);
this.selectCommand = new Command("Select", 1, 1);
this.okCommand = new Command("OK", 1, 1);
this.titleCanvas.addCommand(this.startCommand);
this.titleCanvas.addCommand(this.settingCommand);
this.titleCanvas.addCommand(this.helpCommand);
this.titleCanvas.setCommandListener(new TukMIDP.CommandHandler(this));
}
public void startApp()
{
try
{
this.icon = Image.createImage("/icon.png");
} catch (Exception ex) {
System.out.println("Error while load icon.");
}
try
{
TukMIDP.CommandHandler handler = new TukMIDP.CommandHandler(this);
this.settingMenu = new List("Setting", 3);
this.settingMenu.append("Speed", this.icon);
this.settingMenu.append("People", this.icon);
this.settingMenu.addCommand(this.selectCommand);
this.settingMenu.addCommand(this.backCommand);
this.settingMenu.setCommandListener(handler);
this.speedMenu = new List("Speed Setting", 1);
this.speedMenu.append("Slow", null);
this.speedMenu.append("Medium", null);
this.speedMenu.append("Fast", null);
this.speedMenu.addCommand(this.okCommand);
this.speedMenu.addCommand(this.backCommand);
this.speedMenu.setCommandListener(handler);
this.peopleMenu = new List("People Setting", 1);
this.peopleMenu.append("3", null);
this.peopleMenu.append("5", null);
this.peopleMenu.append("7", null);
this.peopleMenu.append("10", null);
this.peopleMenu.addCommand(this.okCommand);
this.peopleMenu.addCommand(this.backCommand);
this.peopleMenu.setCommandListener(handler);
String helpStr = "- Instruction - \n You are now a Tuk-Tuk driver.Your job is to find commuters and transport them to their destinations. While you drive around looking fora commuter,your gas level will decrease continously.Therfore, you should look for the shortest path way to find a commuter.\n- Trick -\n - You can view a map by press 1 but you will be deducted 5 bath.\n - A Tuk-Tuk fee is based on a time you use to deliver a commuter";
this.helpScreen.append(helpStr);
this.helpScreen.addCommand(this.backCommand);
this.helpScreen.setCommandListener(handler);
this.display.setCurrent(this.firstCanvas);
for (i = 0; i < 5; ++i)
this.firstCanvas.repaint();
try
{
Thread.sleep(2000L);
} catch (Exception i) {
}
this.display.setCurrent(this.titleCanvas);
}
catch (Exception handler) {
System.out.println(" error menu".concat(String.valueOf(String.valueOf(ex))));
}
}
public void startGame() {
this.display.setCurrent(genProgress());
this.thread = new Thread(this);
this.thread.start(); }
public void run() {
this.canvas = new TukCanvas(this, this.people, this.speed);
Thread t = new Thread(this.canvas);
t.start();
for (int i = 0; i < 10; ++i) {
this.progressGauge.setValue(i % 10);
try {
Thread.sleep(200L);
} catch (Exception localException) {
}
}
this.display.setCurrent(this.canvas);
}
public void pauseApp()
{
}
public void destroyApp(boolean unconditional)
{
}
public void closeApp()
{
destroyApp(false);
super.notifyDestroyed();
}
private Screen genProgress() {
String name = "loading..";
if (this.progressForm == null) {
this.progressForm = new Form(name);
this.progressGauge = new Gauge("Game Loading ...", false, 10, 0);
this.progressForm.append(this.progressGauge);
} else {
this.progressGauge.setValue(0);
this.progressForm.setTitle(name);
}
return this.progressForm;
}
static int access$9(TukMIDP x$0, int x$1)
{
return (x$0.people = x$1); }
static int access$8(TukMIDP x$0, int x$1) { return (x$0.speed = x$1); }
static List access$6(TukMIDP x$0) { return x$0.peopleMenu; }
static List access$5(TukMIDP x$0) { return x$0.speedMenu; }
static List access$3(TukMIDP x$0) { return x$0.settingMenu; }
static Form access$11(TukMIDP x$0) { return x$0.helpScreen; }
static Command access$13(TukMIDP x$0) { return x$0.helpCommand; }
static Command access$1(TukMIDP x$0) { return x$0.settingCommand; }
static Command access$0(TukMIDP x$0) { return x$0.startCommand; }
static Command access$7(TukMIDP x$0) { return x$0.okCommand; }
static Command access$4(TukMIDP x$0) { return x$0.selectCommand; }
static Command access$10(TukMIDP x$0) { return x$0.backCommand; }
static TukMIDP.TitleCanvas access$12(TukMIDP x$0) { return x$0.titleCanvas; }
static Display access$2(TukMIDP x$0) { return x$0.display;
}
class CommandHandler
implements CommandListener
{
private final TukMIDP this$0;
CommandHandler()
{
this.this$0 = this$0; }
public void commandAction(, Displayable s) {
int index = 0;
if (s instanceof List)
index = ((List)s).getSelectedIndex();
if (c == TukMIDP.access$0(this.this$0))
this.this$0.startGame();
else if (c == TukMIDP.access$1(this.this$0))
TukMIDP.access$2(this.this$0).setCurrent(TukMIDP.access$3(this.this$0));
else if (c == TukMIDP.access$4(this.this$0))
if (s == TukMIDP.access$3(this.this$0))
if (index == 0)
TukMIDP.access$2(this.this$0).setCurrent(TukMIDP.access$5(this.this$0));
else if (index == 1)
TukMIDP.access$2(this.this$0).setCurrent(TukMIDP.access$6(this.this$0));
else if (c == TukMIDP.access$7(this.this$0))
if (s == TukMIDP.access$5(this.this$0)) {
if (index == 0) {
TukMIDP.access$8(this.this$0, 550);
TukMIDP.access$5(this.this$0).setSelectedIndex(0, true);
TukMIDP.access$5(this.this$0).setSelectedIndex(1, false);
TukMIDP.access$5(this.this$0).setSelectedIndex(2, false);
} else if (index == 1) {
TukMIDP.access$8(this.this$0, 450);
TukMIDP.access$5(this.this$0).setSelectedIndex(0, false);
TukMIDP.access$5(this.this$0).setSelectedIndex(1, true);
TukMIDP.access$5(this.this$0).setSelectedIndex(2, false);
} else if (index == 2) {
TukMIDP.access$8(this.this$0, 350);
TukMIDP.access$5(this.this$0).setSelectedIndex(0, false);
TukMIDP.access$5(this.this$0).setSelectedIndex(1, false);
TukMIDP.access$5(this.this$0).setSelectedIndex(2, true);
}
TukMIDP.access$2(this.this$0).setCurrent(TukMIDP.access$3(this.this$0));
} else if (s == TukMIDP.access$6(this.this$0)) {
if (index == 0) {
TukMIDP.access$9(this.this$0, 3);
TukMIDP.access$6(this.this$0).setSelectedIndex(0, true);
TukMIDP.access$6(this.this$0).setSelectedIndex(1, false);
TukMIDP.access$6(this.this$0).setSelectedIndex(2, false);
TukMIDP.access$6(this.this$0).setSelectedIndex(3, false);
} else if (index == 1) {
TukMIDP.access$9(this.this$0, 5);
TukMIDP.access$6(this.this$0).setSelectedIndex(0, false);
TukMIDP.access$6(this.this$0).setSelectedIndex(1, true);
TukMIDP.access$6(this.this$0).setSelectedIndex(2, false);
TukMIDP.access$6(this.this$0).setSelectedIndex(3, false);
} else if (index == 2) {
TukMIDP.access$9(this.this$0, 7);
TukMIDP.access$6(this.this$0).setSelectedIndex(0, false);
TukMIDP.access$6(this.this$0).setSelectedIndex(1, false);
TukMIDP.access$6(this.this$0).setSelectedIndex(2, true);
TukMIDP.access$6(this.this$0).setSelectedIndex(3, false);
} else if (index == 3) {
TukMIDP.access$9(this.this$0, 10);
TukMIDP.access$6(this.this$0).setSelectedIndex(0, false);
TukMIDP.access$6(this.this$0).setSelectedIndex(1, false);
TukMIDP.access$6(this.this$0).setSelectedIndex(2, false);
TukMIDP.access$6(this.this$0).setSelectedIndex(3, true);
}
TukMIDP.access$2(this.this$0).setCurrent(TukMIDP.access$3(this.this$0));
}
else if (c == TukMIDP.access$10(this.this$0))
if ((s == TukMIDP.access$3(this.this$0)) || (s == TukMIDP.access$11(this.this$0)))
TukMIDP.access$2(this.this$0).setCurrent(TukMIDP.access$12(this.this$0));
else if ((s == TukMIDP.access$5(this.this$0)) || (s == TukMIDP.access$6(this.this$0)))
TukMIDP.access$2(this.this$0).setCurrent(TukMIDP.access$3(this.this$0));
else if (c == TukMIDP.access$13(this.this$0))
TukMIDP.access$2(this.this$0).setCurrent(TukMIDP.access$11(this.this$0));
}
}
class TitleCanvas extends Canvas
{
Image imgTitle;
public TitleCanvas()
{
try
{
this.imgTitle = Image.createImage("/title.png");
} catch (Exception ex) {
System.out.println("Could not load title image");
}
}
public void paint() {
g.drawImage(this.imgTitle, 0, 0, 20);
}
}
class FirstCanvas extends FullCanvas
{
int width;
int height;
Image imgLogo;
public FirstCanvas()
{
this.width = getWidth();
this.height = getHeight();
try
{
this.imgLogo = Image.createImage("/logo.png");
} catch (Exception ex) {
System.out.println("Could not load logo image");
}
}
public void paint() {
g.setColor(0, 0, 0);
g.fillRect(0, 0, this.width, this.height);
g.setColor(255, 255, 255);
g.setFont(Font.getFont(0, 1, 16));
g.drawImage(this.imgLogo, this.width / 2 - this.imgLogo.getWidth() / 2, this.height / 2 - this.imgLogo.getHeight() / 2, 20);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -