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

📄 jmp.java

📁 一个j2me的滑雪游戏
💻 JAVA
字号:
//import com.nttdocomo.ui.*;

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

import com.lm.nttdocomo.ui.Display;
import com.lm.nttdocomo.ui.IApplication;

import com.massp.util.SettingsTracking;
import com.massp.util.StringResourceReader;


/**
 * The main entry into the application.
 *
 * @author <a href="mailto:xp@livingmobile.net">Xavier Palau</a>
 * @version $Revision: 1.8.2.12 $
 * @changed $Author: xavier $ $Date: 2004/02/19 11:33:21 $
 */

public class JMP extends IApplication implements Runnable, CommandListener {
    
	boolean started = false;
  private JMPS canv;  
  
  private String locale;
  public static StringResourceReader txt;
  
  private List menu;  
  private String nick;
  
  private boolean isMenu;
    
  private SettingsTracking tracker;  
  public boolean sound = true;
  //public boolean vibra = true;
  //private boolean light = true;
  
  
  public void start()
  {
    if (started) return;
    boolean started = true;
    
    txt = new StringResourceReader();
    
    try {
      locale = System.getProperty("microedition.locale");
      locale = (locale != null && locale.length() >= 2 ? locale.substring(0, 2).toLowerCase() : "en");      
      if (!txt.load(this, "/text__" + locale + ".bin")) {
        locale = "en";
        txt.load(this, "/text.bin");
      }
    } catch (Exception e) {}
    
    
    // 1 LANGUAGE ONLY
    //locale = "de";
    //try { txt.load(this, "/text/" + locale + ".bin"); }
    //catch (Exception e) {}
    
    //System.out.println("Loading JMPS class");
    canv = new JMPS();
    //System.out.println("JMPS class loaded");
    
    tracker = new SettingsTracking(this, new int[] { 0, 1, 2 });
    sound = (tracker.getSetting(0, (byte) 1) == 0 ? false : true);
    //vibra = (tracker.getSetting(1, (byte) 1) == 0 ? false : true);
    //light = (tracker.getSetting(2, (byte) 1) == 0 ? false : true);
    
    //if (light) device.setDeviceActive(DeviceControl.BACK_LIGHT, true);    
        
    String[] content = txt.getBundle("frmMenu");
    menu = new List(content[0], List.IMPLICIT);
    
    try {
      for (int i = 1; i < content.length; i++)
        menu.append(content[i], Image.createImage("/images/icon_" + i + ".png"));
    } catch (Exception e) { }
    
    menu.addCommand(new Command(txt.getBundle("cmdBack")[0], Command.BACK, 1));
    menu.addCommand(new Command(txt.getBundle("cmdOK")[0], Command.OK, 1));
    menu.setCommandListener(this);
    isMenu = false;
	  Display.setCurrent(canv);
    
    canv.initAll();
    Thread runner = new Thread(this);
    runner.start();
  }

  public void notifyGameOver() {
    menu.setSelectedIndex(1, true);
    commandAction(List.SELECT_COMMAND, menu);
  }
  
  public void notifyMenu() {
    isMenu = true;
    Display.setCurrent(menu);
  }
    

  public void run() {
    int K = 0;
	  long lt = System.currentTimeMillis();
	  int c = 0;
      
	  for(;;) {      
      try {
        Thread.sleep(10);
        if (!canv.visible || isMenu || canv.isPaused) {
          Thread.sleep(50);
          continue;
        }
        
	  	  K |= canv.getKeypadState();

		    c = (int)( System.currentTimeMillis() - lt ) / 100;

		    if (c > 0)  {        
			    canv.ProEvent(K);
			    lt += c * 100; //System.currentTimeMillis();
			    K = 0;
        }
      }
      catch (Exception e) {}		  
	  }
  }

  public void commandAction(Command c, Displayable d) {
    String lbl = c.getLabel();
    
    if (c == List.SELECT_COMMAND
        || (lbl.equals(txt.getBundle("cmdOK")[0]) && d == menu)) {
      int index = menu.getSelectedIndex();
      
      Form f = null;
      String[] content = null;
      switch (index) {
        case 0: 
          isMenu = false;
          Display.setCurrent(canv);
          canv.startTutorial();
          break;
        case 1:
          isMenu = false;
          Display.setCurrent(canv);
          canv.startScores();          
          break;
        case 2:
          content = txt.getBundle("frmOptions");          
          List l = new List(content[0], List.MULTIPLE);          
          for (int i = 1; i < content.length; i++) l.append(content[i], null);
          
          boolean vibra = false, light = false;
          l.setSelectedFlags(new boolean[] {sound, vibra, light} );
          //l.setSelectedFlags(new boolean[] {sound} );
          
          l.addCommand(new Command(txt.getBundle("cmdBack")[0], Command.BACK, 1));          
          l.setCommandListener(this);
          Display.setCurrent(l);
          break;
        case 3:
          content = txt.getBundle("frmInstructions");
          f = new Form(content[0]);
          f.append(content[1]);
          f.addCommand(new Command(txt.getBundle("cmdBack")[0], Command.BACK, 1));
          f.setCommandListener(this);
          Display.setCurrent(f);
          break;
        case 4:
          content = txt.getBundle("frmAbout", new String[] { "app.locale" },
                                  new String[] { locale });          
          f = new Form(content[0]);
          for (int i = 1; i < content.length; i++) {
            f.append(content[i] + "\n");
          }
          f.addCommand(new Command(txt.getBundle("cmdBack")[0], Command.BACK, 1));
          f.setCommandListener(this);
          Display.setCurrent(f);
          break;
      }
    } else if (lbl.equals(txt.getBundle("cmdBack")[0])) {      
      if (d == menu) {
        isMenu = false;
        canv.notifyTitle();
        Display.setCurrent(canv);
      } else {
        if (d instanceof List) {
          List l = (List) d;
          boolean[] flags = new boolean[3];

          l.getSelectedFlags(flags);
          
          sound = flags[0];
          //vibra = flags[1];
          //light = flags[2];
          
          //if (light) device.setDeviceActive(DeviceControl.BACK_LIGHT, true);            
          //else device.setDeviceActive(DeviceControl.BACK_LIGHT, false);

          tracker.setSetting(0, (byte) (sound ? 1 : 0));
          //tracker.setSetting(1, (byte) (vibra ? 1 : 0));
          //tracker.setSetting(2, (byte) (light ? 1 : 0));
        }
        isMenu = true;
        Display.setCurrent(menu);
      }
    } else if (lbl.equals(txt.getBundle("cmdExit")[0])) terminate();
  }
  
}

⌨️ 快捷键说明

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