⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 foundmidlet.java

📁 用Kjava写的一个简单的小游戏!供初学者研究研究
💻 JAVA
字号:
package found;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class FoundMIDlet
    extends MIDlet implements CommandListener {
  public static FoundMIDlet instance;
  private FoundCanvas canvas;
  public Display display;
  Command exitCommand = new Command("Exit", Command.EXIT, 0);
  Command aboutCommand = new Command("About", Command.SCREEN, 1);
  Command highScoreCommand = new Command("HighScore", Command.SCREEN, 2);
  Command restartCommand = new Command("Start/Restart", Command.OK, 0);
  Command helpCommand = new Command("Help", Command.SCREEN, 0);
  public FoundMIDlet() {
    instance = this;
  }

  public void startApp() {
    if (canvas == null) {
      canvas = new FoundCanvas(Display.getDisplay(this));
      canvas.addCommand(exitCommand);
      canvas.addCommand(aboutCommand);
      canvas.addCommand(highScoreCommand);
      canvas.addCommand(restartCommand);
	  canvas.addCommand(helpCommand);
      canvas.setCommandListener(this);
    }

    canvas.start();

  }

  public void pauseApp() {}

  public void destroyApp(boolean unconditional) {
    canvas.stop();
  }

  public static void quitApp() {
    instance.destroyApp(true);
    instance.notifyDestroyed();
    instance = null;
  }

  public void commandAction(Command c, Displayable s) {
    if (c.getCommandType() == Command.EXIT) {
      destroyApp(true);
      notifyDestroyed();
    }
    if (c == aboutCommand) {
      showMessage("提示", "制作小组名单:" + '\n'
                  + "南昌大学软件学院 YRST 小组" + '\n'
                  + "妖娆盛唐 www.tangrao.cn 邮箱:yrst@live.com" + '\n'
				  + "小水 www.cocowater.cn" + '\n'
				  + "欢迎下载,欢迎交流" + '\n',
                  0);
      canvas.stop();
    }
    if (c == highScoreCommand) {
      //canvas.readHiScores();
      showMessage("最高分", "高分列表" + '\n'
                  + "   第一名  :   " + Integer.toString(canvas.highScores[0]) + '\n'
                  + "   第二名  :   " + Integer.toString(canvas.highScores[1]) + '\n'
                  + "   第三名  :   " + Integer.toString(canvas.highScores[2]) + '\n'
                  + "   第四名  :   " + Integer.toString(canvas.highScores[3]) + '\n'
                  + "   第五名  :   " + Integer.toString(canvas.highScores[4]) + '\n',
                  0);
      canvas.stop();
    }
    if (c == restartCommand) {
      canvas.start();
    }
	 if (c == helpCommand) {
        showMessage("提示","一个简单的寻宝游戏,碰上黄色的宝石加5分,红色宝石加10分。大象和小鸟会追你,被它们攻击会减血,分数超过100,大魔王会出现。",0);
      canvas.stop();
    }

  }

  private void showMessage(String TitleStr, String message, int type) {
    Command yesCmd = new Command("是", Command.OK, 1);
    Command noCmd = new Command("否", Command.SCREEN, 1);
    Image logo = FoundMIDlet.loadImage("/res/HEROClan.png");
    Alert aboutAlert = new Alert(TitleStr, message, logo,
                                 AlertType.INFO);
    if (type == 0) {
      aboutAlert.setTimeout(3000);
    }
    else {
      aboutAlert.setTimeout(Alert.FOREVER);
      aboutAlert.addCommand(yesCmd);
      aboutAlert.addCommand(noCmd);
      aboutAlert.setCommandListener(this);
    }
    Display.getDisplay(FoundMIDlet.instance).setCurrent(aboutAlert);
  }

  public static Image loadImage(String path) {
    Image img = null;
    try {
      img = Image.createImage(path);
    }
    catch (java.io.IOException ioe) {
      System.out.println("Erroe loading Image!" + path);
    }
    return img;
  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -