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

📄 kyodaiui.java

📁 j2me,连连看
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
  private void updateInfo() {
    long time = System.currentTimeMillis() - startTime;
    g.setColor(0xffffff);
    g.fillRect(0, 233, CV.srcWidth, 20);
    g.setFont(f);
    g.setColor(0);
    time = time == 0 ? 1 : time;
    long fps = frames * 1000 / time;
    String info = "";
    if (Kyodai.gameMode == 1) {
      info = "Time: " + formatTime(limitTime - time);
      info += ", Step: " + (limitStep - gameSteps);
    }
    else {
      info = "Time: " + formatTime(time);
    }
    if (SeriesHints > 0) {
      info += ", Combo: " + SeriesHints + "[" + CV.SeriesScorce[SeriesHints] +
          "]";
    }
    info += ", fps = " + fps;
    g.drawString(info, 5, 250, Graphics.LEFT | Graphics.BOTTOM);

    flushGraphics();
  }

  /**
   * 供游戏开始的时候,找到第一个停留点
   */
  private void getStartPoint() {
    if (gameEnd) {
      return;
    }

    for (int row = 0; row < CV.ROW; row++) {
      for (int col = 0; col < CV.COLUMN; col++) {
        if (gm.getMap()[row][col] > 0) {
          currentPoint.x = row;
          currentPoint.y = col;
          return;
        }
      }
    }
  }

  /**
   * 绘制选中图片的边框
   * @param p 坐标
   * @param color 颜色
   */
  /*private void drawBorder(Point p, int color) {
    if (p.x < 0 || p.y < 0) {
      return;
    }
    int x = p.y * (CV.SPACING + CV.ICON_WIDTH);
    int y = p.x * (CV.SPACING + CV.ICON_HEIGHT);
    g.setColor(color);
    g.drawRect(x, y, CV.ICON_WIDTH + CV.SPACING,
               CV.ICON_HEIGHT + CV.SPACING);
     }*/

  private void newStep() {
    gameSteps++;
  }

  private void drawGameMap() {
    g.setColor(CV.GAMEBGCOLOR);
    g.fillRect(0, 0, CV.srcWidth, CV.srcHeight);

    //绘制地图
    for (int row = 0; row < CV.ROW; row++) {
      for (int col = 0; col < CV.COLUMN; col++) {
        if (gm.getMap()[row][col] != 0) {
          int index = gm.getMap()[row][col] - 1;
          int x = CV.SPACING +
              col * (CV.SPACING + CV.ICON_WIDTH);
          int y = CV.SPACING +
              row * (CV.SPACING + CV.ICON_HEIGHT);
          Kyodai.sprites[index].setPosition(x, y);
          Kyodai.sprites[index].paint(g);
          //Kyodai.translucenceSprite[index].setPosition(x, y);
          //Kyodai.translucenceSprite[index].paint(g);
        }
      }
    }

    //重新停留点的选择框
    drawBorder(currentPoint, CV.HOVERCOLOR);

    flushGraphics();
  }

  private void movePoint(int direct) {
    if (gameEnd) { //如果游戏已结束,返回
      return;
    }

    newStep(); //记录下用户移动了一步

    Point p = gm.getSmartPoint(currentPoint, direct);

    //清除上一次的背景
    drawBorder(currentPoint, CV.GAMEBGCOLOR);
    drawBorder(lastSelected, CV.SELECTEDCOLOR);
    drawBorder(p, CV.HOVERCOLOR);

    flushGraphics();

    //重新设置当前的停留点
    currentPoint.x = p.x;
    currentPoint.y = p.y;
    System.gc();
  }

  private void fillBorder(Point p, int color) {
    if (p.x < 0 || p.y < 0) {
      return;
    }

    int x = p.y * (CV.SPACING + CV.ICON_WIDTH);
    int y = p.x * (CV.SPACING + CV.ICON_HEIGHT);
    g.setColor(color);
    g.fillRect(x, y, CV.ICON_WIDTH + CV.SPACING * 2,
               CV.ICON_HEIGHT + CV.SPACING * 2);
  }

  private void addScore(String name, int score) {
    Record[] record = new Record[10];
    //保存原来的游戏记录
    for (int i = 1; i < kyodai.record.length; i++) {
      record[i - 1] = new Record();
      record[i - 1].setName(kyodai.record[i].getName());
      record[i - 1].setScore("" + kyodai.record[i].getScore());
    }
    int offset = 0;
    for (; offset < record.length; offset++) {
      if (score > record[offset].getScore()) {
        kyodai.record[offset + 1].setName(name);
        kyodai.record[offset + 1].setScore("" + score);
        break;
      }
      kyodai.record[offset + 1].setName(record[offset].getName());
      kyodai.record[offset + 1].setScore("" + record[offset].getScore());
    }
    for (; offset < record.length - 1; offset++) {
      kyodai.record[offset + 2].setName(record[offset].getName());
      kyodai.record[offset + 2].setScore("" + record[offset].getScore());
    }
    record = null;
    System.gc();
    /*for (int i = 1; i < kyodai.record.length; i++) {
      System.out.println(kyodai.record[i].getScore());
         }*/
  }

  /**
   * 用户完成游戏
   */
  private void makeWinImage() {
    gameEnd = true;
    long usedTime = System.currentTimeMillis() - startTime;

    g.setColor(CV.GAMEBGCOLOR);
    g.fillRect(0, 0, CV.srcWidth, CV.srcHeight);

    g.setColor(0xff0000);

    int x = 0;
    int y = 10;

    y += 10;
    int blocks = gm.getBlocks();

    int timeScore = (gameSteps << 3) - (int) usedTime; //gameSteps * 8 - usedTime
    timeScore = timeScore > 0 ? timeScore : 0;

    g.drawString("时间得分: " + timeScore + "(" + usedTime + "s)", 40, y,
                 Graphics.LEFT | Graphics.TOP);

    y += 25;
    int stepScore = (blocks << 3) + (blocks << 2) - gameSteps; //blocks * 12 - gameSteps
    stepScore = stepScore > 0 ? stepScore : 0;
    g.drawString("\u8ddd\u79bb\u5f97\u5206: " + stepScore + "(" + gameSteps +
                 ")", 40, y,
                 Graphics.LEFT | Graphics.TOP);

    y += 25;

    int levelScore = 0;
    if (kyodai.gameMode == 1) {
      levelScore = 1500;
      g.drawString("挑战模式: 1500(额外奖励)", 40, y,
                   Graphics.LEFT | Graphics.TOP);
    }
    y += 25;

    int freshScore = 0;
    freshScore = - ( (refreshTimes << 5) + (refreshTimes << 3)); //refreshTimes * 40
    g.drawString("重列得分: " + freshScore + "(" + refreshTimes + ")", 40, y,
                 Graphics.LEFT | Graphics.TOP);
    y += 25;
    g.drawString("消除方块: " + blocks, 40, y,
                 Graphics.LEFT | Graphics.TOP);

    y += 25;
    g.drawString("方块得分: " + earseScore, 40, y,
                 Graphics.LEFT | Graphics.TOP);

    y += 25;
    g.drawString(" 总  计 : " +
                 (timeScore + stepScore + freshScore + earseScore + levelScore),
                 40, y,
                 Graphics.LEFT | Graphics.TOP);
    flushGraphics();
    System.gc();
    if (kyodai.gameMode == 1) { //高难度
      addScore("快乐挑战",
               timeScore + stepScore + freshScore + earseScore + levelScore);
    }
    else {
      addScore("轻松惬意", timeScore + stepScore + freshScore + earseScore);
    }
  }

  /**
   * 游戏结束画面
   */
  private void makeEndImage() { //总之死得很惨:)
    gameEnd = true;
    g.setColor(0xff0000);
    g.fillRect(0, 0, CV.srcWidth, CV.srcHeight);
    g.setColor(0xffffff);
    String str = "胜败乃兵家常事,";
    int x = (CV.srcWidth - f.stringWidth(str)) >> 1;
    g.drawString(str, x, 50, Graphics.LEFT | Graphics.TOP);
    str = "请大侠重新来过!";
    x = (CV.srcWidth - f.stringWidth(str)) >> 1;
    g.drawString(str, x, 80, Graphics.LEFT | Graphics.TOP);
    flushGraphics();
  }

  /**
   * 将时间格式化输出
   * @param time
   * @return
   */
  private String formatTime(long time) {
    int msb = (int) time / 1000;
    int lsb = (int) (time - msb * 1000) / 100;
    StringBuffer sb = new StringBuffer("");
    sb.append(msb);
    sb.append(".");
    sb.append(lsb);
    return sb.toString();
  }

  /**
   * 绘制边框
   * @param p
   * @param color
   */
  private void drawBorder(Point p, int color) {
    if (p.x < 0 || p.y < 0) {
      return;
    }

    int x = p.y * (Settings.SPACING + Settings.ICON_WIDTH);
    int y = p.x * (Settings.SPACING + Settings.ICON_HEIGHT);
    g.setColor(color);
    g.drawRect(x, y, Settings.ICON_WIDTH + Settings.SPACING,
               Settings.ICON_HEIGHT + Settings.SPACING);
  }
}

⌨️ 快捷键说明

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