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

📄 gamemenu.java

📁 j2me,连连看
💻 JAVA
字号:
package com.ismyway.n840_kyodai;

import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;

/**
 * <p>Title: S60_Kyodai</p>
 * <p>Description: for S60 platform</p>
 * <p>Copyright: Copyright (c) 2005</p>
 * <p>Company: www.ismyway.com</p>
 * @author ZhangJian
 * @version 1.0
 */

public class GameMenu
    extends GameCanvas {
  private String[] menu = {
      "开始游戏", "高手排行", "音效设定", "游戏模式", "游戏说明", "退出游戏"};
  private String[] music = {
      "Beach", "BlueIce", "Sashay", "Electriceel",
      "Nightclub", "Solar", "DanceNow", "静音", "随机"};
  private String[] level = {
      "轻松惬意", "快乐挑战"};

  Font f = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN,
                        Font.SIZE_MEDIUM);
  int selectIndex = 0;
  Kyodai kyodai;

  public GameMenu(Kyodai kyodai) {
    super(false);
    System.gc();
    //System.out.println(Runtime.getRuntime().totalMemory());
    this.kyodai = kyodai;
    //image = kyodai.icons[23];
  }

  public void paint(Graphics g) {
    //g.drawImage(image, 0, 0, Graphics.LEFT | Graphics.TOP);
    g.setColor(0);
    g.fillRect(0, 0, CV.srcWidth, CV.srcHeight);
    int height = 84;
    for (int i = 0; i < menu.length; i++) {
      String str = menu[i];
      int strLen = f.stringWidth(str);
      g.setFont(f);
      if (i == selectIndex) {
        drawText(g, str, 96, height + 5, 0xffffff, 0);
      }
      else {
        drawText(g, str, 96, height + 5, 0xff6600, 0);
      }
      g.drawString(str, 96, height + 5, Graphics.LEFT | Graphics.TOP);
      height += 18;
    }

    if (selectIndex == 2) { //显示音效的设定
      if (!Kyodai.supportMMAPI) { //不支持MMAPI就总使用静音
        kyodai.musicMode = 7;
      }
      drawText(g, "当前选择", 10, 108, 0xffffff, 0);
      drawText(g, music[Kyodai.musicMode], 10, 128, 0xffffff, 0);
    }

    if (selectIndex == 3) { //显示游戏模式的设定
      drawText(g, "当前选择", 10, 108, 0xffffff, 0);
      drawText(g, level[Kyodai.gameMode], 10, 128, 0xffffff, 0);
    }

  }

  public void keyPressed(int keyCode) {
    switch (keyCode) {
      case CV.KEY_UP: //上
        moveSelect( -1);
        repaint();
        break;
      case CV.KEY_DOWN: //下
        moveSelect(1);
        repaint();
        break;
      case CV.KEY_LEFT: //左
        musicSelect( -1);
        repaint();
        break;
      case CV.KEY_RIGHT: //右
        musicSelect(1);
        repaint();
        break;
      case CV.KEY_SELECT:
      case CV.KEY_NUM5:
        makeSelect();
        break;
    }
  }

  private void moveSelect(int step) {
    if (step > 0) {
      selectIndex++;
      if (selectIndex == menu.length) {
        selectIndex = 0;
      }
    }
    else {
      selectIndex--;
      if (selectIndex == -1) {
        selectIndex = menu.length - 1;
      }
    }
  }

  private void musicSelect(int step) {
    if (selectIndex == 2) { //当前停留在音效选择上
      Kyodai.musicMode += step;
      Kyodai.musicMode = (Kyodai.musicMode + music.length) % music.length;
      return;
    }
    if (selectIndex == 3) { //当前停留在游戏模式选择上
      Kyodai.gameMode++;
      Kyodai.gameMode &= 1;
      return;
    }

  }

  private void makeSelect() {
    switch (selectIndex) {
      case 0: //开始游戏
        KyodaiUI kui = new KyodaiUI(kyodai);
        Display.getDisplay(kyodai).setCurrent(kui);
        kui.start();
        break;
      case 1: //Top10
        Display.getDisplay(kyodai).setCurrent(new Top10(kyodai, this));
        break;
      case 2: //音效
        break;
      case 3:
        break;
      case 4: //说明
        Display.getDisplay(kyodai).setCurrent(new About(kyodai, this));
        break;
      case 5: //退出
        kyodai.exit();
    }
  }

  /**
   * 绘制带有边框的文字
   * @param g
   * @param text
   * @param x
   * @param y
   * @param fg
   * @param bg
   */
  private void drawText(Graphics g, String text, int x, int y, int fg, int bg) {
    g.setColor(bg);
    g.drawString(text, x + 1, y, Graphics.LEFT | Graphics.TOP);
    g.drawString(text, x, y - 1, Graphics.LEFT | Graphics.TOP);
    g.drawString(text, x, y + 1, Graphics.LEFT | Graphics.TOP);
    g.drawString(text, x - 1, y, Graphics.LEFT | Graphics.TOP);
    g.setColor(fg);
    g.drawString(text, x, y, Graphics.LEFT | Graphics.TOP);
  }
}

⌨️ 快捷键说明

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