SystemList.java
上传用户:whhzxy
上传日期:2009-12-31
资源大小:269k
文件大小:3k
源码类别:

J2ME

开发平台:

Java

  1. import javax.microedition.lcdui.*;
  2. /**
  3.   * 系统菜单。
  4.   * @author 嘟嘟熊
  5.   * @version 1.0
  6.   */
  7. public class SystemList
  8.     extends List
  9.     implements CommandListener {
  10.   private KMRichMan richManObject;
  11.   private PlayCanvas playCanvas;
  12.   private String musicOn = "音乐[开]";
  13.   private String musicOff = "音乐[关]";
  14.   private String music = "音乐[";
  15.   private String lightOn = "背景灯[开]";
  16.   private String lightOff = "背景灯[关]";
  17.   private String gameSpeed = "游戏速度[";
  18.   /**
  19.  * 构造一个对象
  20.  */
  21.   public SystemList(KMRichMan kmrichman,PlayCanvas playCanvas) {
  22.     super("选项菜单", 3);
  23.     this.richManObject = kmrichman;
  24.     this.playCanvas = playCanvas;
  25.     if (this.playCanvas.isIsLightOn()) {
  26.       append(this.lightOn, null);
  27.     }
  28.     else {
  29.       append(this.lightOff, null);
  30.     }
  31.     if (this.playCanvas.isIsMusicOn()) {
  32.       append(this.musicOn, null);
  33.     }
  34.     else {
  35.       append(this.musicOff, null);
  36.     }
  37.     append(this.music + this.playCanvas.getMusic() +"]", null);
  38.     append(this.gameSpeed + this.playCanvas.getGameSpeed() +"]", null);
  39.     append("返回游戏", null);
  40.     append("退出游戏", null);
  41.     setCommandListener(this);
  42.   }
  43.   /**
  44.  * 处理按键
  45.  */
  46.   public void commandAction(Command command, Displayable displayable) {
  47.     switch (getSelectedIndex()) {
  48.       case 0: // 背景光开关
  49.         if (this.playCanvas.isIsLightOn()) {
  50.           this.set(0,this.lightOff, null);
  51.           this.playCanvas.setIsLightOn(false);
  52.         }
  53.         else {
  54.           this.set(0,this.lightOn, null);
  55.           this.playCanvas.setIsLightOn(true);
  56.         }
  57.         break;
  58.       case 1: // 音乐开关
  59.         if (this.playCanvas.isIsMusicOn()) {
  60.           this.set(1,this.musicOff, null);
  61.           this.playCanvas.setIsMusicOn(false);
  62.         }
  63.         else {
  64.           this.set(1,this.musicOn, null);
  65.           this.playCanvas.setIsMusicOn(true);
  66.         }
  67.         break;
  68.       case 2: // 音乐选择
  69.         if (this.playCanvas.getMusic() < 7) {
  70.           this.playCanvas.setIsMusicOn(false);
  71.           this.playCanvas.setMusic(this.playCanvas.getMusic() + 1);
  72.           this.playCanvas.setIsMusicOn(true);
  73.           this.set(1,this.musicOn, null);
  74.           this.set(2,this.music + this.playCanvas.getMusic() +"]", null);
  75.         }
  76.         else {
  77.           this.playCanvas.setIsMusicOn(false);
  78.           this.playCanvas.setMusic(1);
  79.           this.playCanvas.setIsMusicOn(true);
  80.           this.set(1,this.musicOn, null);
  81.           this.set(2,this.music + this.playCanvas.getMusic() +"]", null);
  82.         }
  83.         break;
  84.       case 3: //游戏速度
  85.         if (this.playCanvas.getGameSpeed() < 3) {
  86.           this.playCanvas.setGameSpeed(this.playCanvas.getGameSpeed() + 1);
  87.           this.set(3,this.gameSpeed + this.playCanvas.getGameSpeed() +"]", null);
  88.         }
  89.       else {
  90.         this.playCanvas.setGameSpeed(1);
  91.         this.set(3,this.gameSpeed + this.playCanvas.getGameSpeed() +"]", null);
  92.       }
  93.       break;
  94.       case 4: //返回
  95.         richManObject.setDisplayToPlayCanvas1();
  96.         break;
  97.       case 5: // 退出
  98.         this.playCanvas.autoSaveGame();
  99.         KMRichMan.exitGame();
  100.         break;
  101.     }
  102.   }
  103. }