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

📄 menu.java~2~

📁 手机版泡泡龙游戏
💻 JAVA~2~
字号:
package paopao;import javax.microedition.lcdui.*;import com.nokia.mid.ui.*;public class Menu    extends FullCanvas implements Runnable {  int state;//主菜单  final int screenw = getWidth();  final int screenh = getHeight();  final int paintw = 168;  final int painth = 182;  final int midx = paintw / 2;  final int midy = painth / 2;  final int orgx = (screenw - paintw) / 2;  final int orgy = (screenh - painth) / 2;  final int MENU_INIT = 0;  final int MENU_SELECT = 1000;  final int MENU_LOADING = 2000;  final int MENU_SETKEY = 3000;  final int MENU_HELP_RANK = 4000;  final int MENU_HELP = 5000;  final int MENU_RANK = 6000;  Image[] img = new Image[8];  final int helpStrHeight = -150;//主选择菜单  int fingerCount;  int selectNum;//this is loading  int progress;//this is setkey  boolean isSettingKey = false;  int nowKey;//this is help and rank  boolean isHelp = true;//this is help  int helpStrY; //帮助的起始y坐标  final int minHelpTop = -300; //帮助的y坐标上限  int heightPerLine = 20;//this is rank//this is thread  Thread thread = null;  int interval = 50;  boolean killThread = false;  int pressedKeyCode = 10000;  static final String DIR = "/resource/";  public Menu() {    Resource.initrecord();    Resource.init(16);    state = MENU_INIT;  }  protected void keyPressed(int KeyCode) {    pressedKeyCode = KeyCode;    System.out.println("" + KeyCode);  }  protected void doKeyEvent(int keyCode) {    if (keyCode == 10000)      return;    else      switch (state) {        case MENU_INIT:          return;        case MENU_SELECT:          if (keyCode == Resource.KEY_UP) {            selectNum--;            selectNum = (selectNum < 0 ? 3 : selectNum);          }          else if (keyCode == Resource.KEY_DOWN) {            selectNum++;            selectNum %= 4;          }          else if (keyCode == Resource.KEY_FIRE) {            switch (selectNum) {              case 0:                state = MENU_LOADING;                break;              case 1:                state = MENU_SETKEY;                break;              case 2:                state = MENU_HELP_RANK;                break;              case 3:                PaoPao.quitApp();                break;            }          }          break;        case MENU_LOADING:          break;        case MENU_SETKEY:          if (!isSettingKey) {            if (keyCode == Resource.KEY_UP) {              nowKey++;              nowKey = (nowKey > Resource.setupKeyNum ? 0 : nowKey);            }            if (keyCode == Resource.KEY_DOWN) {              nowKey--;              nowKey = (nowKey < 0 ? Resource.setupKeyNum : nowKey);            }            if (nowKey > 0 && keyCode == Resource.KEY_LS) {              isSettingKey = true;              Resource.key[nowKey - 1] = 0;            }            if (nowKey == 0 && keyCode == Resource.KEY_LS)              Resource.isSoundOn = !Resource.isSoundOn;            if (keyCode == Resource.KEY_RS) {              this.serviceRepaints();              state = MENU_HELP_RANK;              repaint();              Resource.saveOption();            }          }          else {            if (Resource.GetUserKeyName(keyCode) != " ") {              Resource.key[nowKey - 1] = (byte) keyCode;              isSettingKey = false;            }          }          break;        case MENU_HELP_RANK://选择进入帮助或者排行榜          if (keyCode == Resource.KEY_DOWN || keyCode == Resource.KEY_UP)//选择好            isHelp = !isHelp;          else if (keyCode == Resource.KEY_LS || keyCode == Resource.KEY_FIRE) {            if (isHelp)              state = MENU_HELP;            else              state = MENU_RANK;          }          else if (keyCode == Resource.KEY_RS)            state = MENU_SELECT;          break;        case MENU_HELP:          if (keyCode == Resource.KEY_UP) {            helpStrY += 100;            if (helpStrY > 0)              helpStrY = 0;          }          else if (keyCode == Resource.KEY_DOWN) {            helpStrY -= 100;            if (helpStrY < helpStrHeight) helpStrY = helpStrHeight;          }          else if (keyCode == Resource.KEY_RS) {            this.serviceRepaints();            state = MENU_HELP_RANK;            repaint();          }          break;        case MENU_RANK:          if (keyCode == Resource.KEY_RIGHT || keyCode == Resource.KEY_FIRE)            state = MENU_HELP_RANK;          break;      }    pressedKeyCode = 10000;  }  protected void show() {    if (thread == null) {      thread = new Thread(this);      thread.start();    }  }  protected void paint(Graphics g) {    g.setColor(0, 0, 0);    g.fillRect(0, 0, screenw, screenh);    g.translate(orgx, orgy);    g.setClip(0, 0, paintw, painth);    g.fillRect(0, 0, paintw, painth);    switch (state) {      case MENU_INIT:        g.setColor(0, 0, 0);        g.fillRect(0, 0, paintw, painth);        break;      case MENU_SELECT:        g.setColor(0, 0, 0);        g.fillRect(0, 0, paintw, painth);        g.drawImage(img[0], midx, 0, Graphics.TOP | Graphics.HCENTER);        g.drawImage(img[1], midx, 130, Graphics.VCENTER | Graphics.HCENTER);        g.drawImage(img[2 + fingerCount], 18, 103 + selectNum * 18,                    Graphics.VCENTER | Graphics.HCENTER);        break;      case MENU_LOADING:        g.drawImage(img[6], midx, 15, Graphics.TOP | Graphics.HCENTER);        g.drawImage(img[7], midx, 150, Graphics.TOP | Graphics.HCENTER);        g.setColor(162, 28, 50);        g.fillRect(45, 151, progress * 7, 4);        break;      case MENU_SETKEY:        g.setColor(255, 255, 255);        g.setFont(Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_PLAIN,                               Font.SIZE_SMALL));        g.drawString("音效:" + (Resource.isSoundOn ? "开" : "关"), 10, 10,                     g.TOP | g.LEFT);        for (int i = 0; i < Resource.setupKeyNum; i++)          g.drawString(Resource.keyDes[i] +                       Resource.GetUserKeyName(Resource.key[i]), 10,                       25 + i * 15, 20);        g.drawRect(7, 9 + 15 * nowKey, paintw - 14, 14);        g.setColor(248, 248, 53);        if (!isSettingKey) {          g.drawString("请按左软件修改设置", paintw / 2, 90, g.TOP | g.HCENTER);          g.drawImage(img[4], paintw - 5, painth - 5, g.RIGHT | g.BOTTOM);        }        else          g.drawString("请按下要设置的按键", paintw / 2, 90, g.TOP | g.HCENTER);        break;      case MENU_HELP_RANK:        drawFrame(g);        g.setColor(175, 165, 52);        if (isHelp)          g.fillRect(0, 10, paintw, 15);        else          g.fillRect(0, 25, paintw, 15);        g.setColor(255, 255, 255);        g.setFont(Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_PLAIN,                               Font.SIZE_SMALL));        g.drawString("帮助信息", 10, 10, g.TOP | g.LEFT);        g.drawString("本地排行", 10, 25, g.TOP | g.LEFT);        break;      case MENU_HELP:        drawFrame(g);        g.setFont(Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_PLAIN,                               Font.SIZE_SMALL));        g.setClip(5, 5, paintw - 10, painth - 10);        g.setColor(255, 255, 255);        drawHelpString(g, Resource.helpStr, 8, helpStrY + 6);        g.setClip(0, 0, paintw, painth);        //g.drawImage(img[4],paintw-5,painth-5,g.RIGHT  |g.BOTTOM );        break;      case MENU_RANK:        drawFrame(g);        g.setColor(255, 255, 255);        g.setFont(Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_PLAIN,                               Font.SIZE_SMALL));        g.drawString("本地分数排行", paintw / 2, 10, g.HCENTER | g.TOP);        for (int i = 0; i < 5; i++) {          g.drawString( (i + 1) + ".", 10, 30 + i * 15, g.TOP | g.LEFT);        }        //  g.drawImage(img[4],paintw - 5,painth - 5,g.RIGHT | g.BOTTOM );        break;      default:        break;    }  }  public void run() {    /*     while(!killThread)       {         switch(state)          {       case MENU_INIT:              try          {          img[0] = Image.createImage(Resource.DIR + "logo.png");          img[1] = Image.createImage(Resource.DIR + "select.png");          img[2] = Image.createImage(Resource.DIR + "finger0.png");          img[3] = Image.createImage(Resource.DIR + "finger1.png");          img[4] = Image.createImage(Resource.DIR + "finger2.png");          img[5] = Image.createImage(Resource.DIR + "finger3.png");          img[6] = Image.createImage(Resource.DIR + "boy.png");          img[7] = Image.createImage(Resource.DIR + "progress.png");        }        catch(Exception ex)        {        System.out.println("Error int create new img!");        }        state = MENU_SELECT;              break;          case MENU_SELECT:          //this is for lover circle act           fingerCount ++;           fingerCount %= 4;           break;           case MENU_LOADING:            Resource.setImage(Resource.PLAYER,Resource.DIR + "player.png");            progress += 1;            repaint();            Resource.setImage(Resource.BOARD,Resource.DIR + "board.png");            progress += 2;            repaint();            Resource.setImage(Resource.BG,Resource.DIR + "bg.png");            Resource.setImage(Resource.PH,Resource.DIR + "ph.png");     Resource.setImage(Resource.WALL_LEFT,Resource.DIR + "wall_left.png");            progress += 2;            repaint();            Resource.setImage(Resource.TOOTH,Resource.DIR + "tooth.png");            Resource.setImage(Resource.LOGO,Resource.DIR + "logo.png");            progress += 2;            repaint();            Resource.setImage(Resource.SELECT,Resource.DIR + "select.png");            Resource.setImage(Resource.FINGER0,Resource.DIR + "finger0.png");            Resource.setImage(Resource.FINGER1,Resource.DIR + "finger1.png");            Resource.setImage(Resource.FINGER2,Resource.DIR + "finger2.png");            Resource.setImage(Resource.FINGER3,Resource.DIR + "finger3.png");            progress += 1;            repaint();            Resource.setImage(Resource.BOY,Resource.DIR + "boy.png");            Resource.setImage(Resource.PROGRESS,Resource.DIR + "progress.png");     Resource.setImage(Resource.WALL_RIGHT,Resource.DIR + "wall_right.png");            progress += 2;            repaint();            Resource.setImage(Resource.OVER,Resource.DIR + "over.png");            progress += 1;            repaint();            killThread = true;           break;          case MENU_SETKEY:            break;          case MENU_HELP_RANK:            break;          case MENU_HELP:            break;          case MENU_RANK:            break;          }                      //switch(state)        try        {        this.doKeyEvent(pressedKeyCode);        repaint();        thread.sleep(interval);        }        catch(Exception ex){}              }                        //while(!killThread)     serviceRepaints();     img = null;     System.gc();     PaoPao.shiftCanvas(PaoPao.GAMEWORLD_ID,6);     */  } //run  void drawFrame(Graphics g) {    g.setColor(46, 49, 146);    g.fillRect(2, 2, paintw - 4, painth - 4);    g.setColor(128, 128, 128);    g.drawLine(2, 2, 2, painth - 2);    g.drawLine(2, 4, paintw - 2, 4);    g.drawLine(2 + paintw - 7, 2, 2 + paintw - 7, painth - 2);    g.drawLine(2, 4 + painth - 6, paintw - 2, 4 + painth - 6);    g.setColor(184, 184, 184);    g.drawLine(3, 2, 3, painth - 2);    g.drawLine(2, 3, paintw - 2, 3);    g.drawLine(3 + paintw - 7, 2, 3 + paintw - 7, painth - 2);    g.drawLine(2, 3 + painth - 6, paintw - 2, 3 + painth - 6);    g.setColor(248, 248, 248);    g.drawLine(4, 2, 4, painth - 2);    g.drawLine(2, 2, paintw - 2, 2);    g.drawLine(4 + paintw - 7, 2, 4 + paintw - 7, painth - 2);    g.drawLine(2, 2 + painth - 6, paintw - 2, 2 + painth - 6);    //g.drawImage(img[1],3,3,g.HCENTER|g.VCENTER );    // g.drawImage(img[1],3,painth-3,g.HCENTER|g.VCENTER );    // g.drawImage(img[1],paintw-3,3,g.HCENTER|g.VCENTER );    //g.drawImage(img[1],paintw-3,painth-3,g.HCENTER|g.VCENTER );  }  public static void drawHelpString(Graphics g, String str, int x, int y) {    System.gc();    StringBuffer output = new StringBuffer(30);    int j = 0;    for (int i = 0; i < str.length(); i++) {      if (str.charAt(i) != '&') {        output.append(str.charAt(i));      }      else {        if (y + 12 * j > g.getClipY() - 20 &&            y + 12 * j < g.getClipY() + g.getClipHeight())          g.drawString(output.toString(), x, y + 12 * j, g.TOP | g.LEFT);        j++;        output.delete(0, 29);      }    }  }}

⌨️ 快捷键说明

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