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

📄 about.java

📁 java实现的简单连连看游戏
💻 JAVA
字号:
package com.ismyway.n840_kyodai;

import java.util.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
import java.io.*;

/**
 * <p>Title: N840 Kyodai</p>
 * <p>Description: N840上的连连看游�?</p>
 * <p>Copyright: Copyright (c) 2005</p>
 * <p>Company: http://www.ismyway.com</p>
 * @author 张剑
 * @version 1.0
 */
public class About
    extends GameCanvas {
  private String text = "注意:按#键可退出当前屏幕!\n\n"
      + "你快乐,所以我快乐:),欢迎使用“快乐连连看”\n\n"
      + "游戏规则\n"
      + "选择一对相同的图片,如果这一对图片之间可以使用不超过3条直线连接起来,可将消除此对图片,如果消完所有图片,游戏结束。\n\n"
      + "操作指南\n"
      + "方向键或2/4/6/8键进行移动,确认键/5键选择图片,0键刷新地图,游戏过程中,方向键可以穿越边界,并且可以随时按#键回到菜单。\n\n"
      + "游戏模式\n"
      + "本游戏提供两种模式供玩家选择,\"轻松惬意\"对游戏没有作任何限制,比较打发时间,\"快乐挑战\"属于高难度挑战级别,游戏开始会产生较多图片,并且限制了游戏时间和游戏步数(时间=图片*4s,步数=图片*6),如果用户没有在规定的时间和步数内完成游则游戏失败,如果玩家能够完成游戏,则奖1500分!\n\n"
      + "游戏排行\n"
      + "可记录用户进行游戏的最高10次的分数!获得高分的原则是在尽可能短的时间内完成游戏,并且使用尽可能少的步骤,同时,如果你的动作够快,可以获得连击分数奖励,连击最高可以达到9次,此时奖励的分数为(1+2+3+..+9)*10=450分。\n\n"
      + "关于游戏游戏中的图片、声音等资源基本上从网络中获得,如有不妥,请来信指出。要源程序请访问http://www.ismyway.com,源程序版权归属作者所有!  ";
  String[] lines;
  int lineIndex = 0;
  int maxLineIndex = 0;
  boolean showScrollBar = false;
  private Displayable dis;
  private Kyodai kyodai;

  private int scrollbar_height = 20;

  public About(Kyodai kyodai, Displayable dis) {
    super(false);
    this.kyodai = kyodai;
    this.dis = dis;

    Font font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN,
                             Font.SIZE_MEDIUM);
    lines = getSubsection(text, font, this.getWidth() - 20, "");
    maxLineIndex = lines.length - 13;
    if (maxLineIndex > 0) {
      showScrollBar = true;
    }
    else {
      showScrollBar = false;
    }
  }

  public void paint(Graphics g) {
    //清除背景
    g.setColor(0);
    g.fillRect(0, 0, CV.srcWidth, CV.srcHeight);
    //重画文字区域
    if (showScrollBar) {
      drawScrollBar(g);
    }
    //重绘文字
    g.setColor(0xffffff);
    int y = 10;
    for (int i = 0; i < 13; i++) {
      g.drawString(lines[i + lineIndex], 10, y, Graphics.LEFT | Graphics.TOP);
      y += 18;
    }
  }

  /**
   * 代码出处http://www.j2medev.com/Article_Show.asp?ArticleID=199
   * 但是此段代码在处理最后一行文本时会出现问�?
   * @param strSource
   * @param font
   * @param width
   * @param strSplit
   * @return
   */
  public String[] getSubsection(String strSource, Font font, int width,
                                String strSplit) {
    Vector vector = new Vector();
    String temp = strSource;
    int i, j;
    int LastLength = 1;
    int step = 0;
    try {
      while (!temp.equals("")) {
        i = temp.indexOf("\n");
        if (i > 0) {
          if (font.stringWidth(temp.substring(0, i - 1)) >= width) {
            i = -1;
          }
        }
        if (i == -1) {
          if (LastLength > temp.length()) {
            i = temp.length();
          }
          else {
            i = LastLength;
            step = font.stringWidth(temp.substring(0, i)) > width ? -1 : 1;
            if (i < temp.length()) {
              while (! (font.stringWidth(temp.substring(0, i)) <= width
                        && font.stringWidth(temp.substring(0, i + 1)) > width)) {
                i = i + step;
                if (i == temp.length()) {
                  break;
                }
              }
            }
          }
          if (!strSplit.equals("")) {
            j = i;
            if (i < temp.length()) {
              while (strSplit.indexOf(temp.substring(i - 1, i)) == -1) {
                i--;
                if (i == 0) {
                  i = j;
                  break;
                }
              }
            }
          }
        }
        LastLength = i;
        vector.addElement(temp.substring(0, i));
        if (i == temp.length()) {
          temp = "";
        }
        else {
          temp = temp.substring(i);
          if (temp.substring(0, 1).equals("\n")) {
            temp = temp.substring(1);
          }
        }
      }
    }
    catch (Exception e) {
      System.out.println("getSubsection:" + e);
    }
    String[] str = new String[vector.size()];
    for (int index = 0; index < vector.size(); index++) {
      str[index] = vector.elementAt(index).toString();
    }
    vector = null;
    System.gc();
    return str;
  }

  void moveSelect(int step) {
    if (step > 0) {
      if (lineIndex < maxLineIndex) {
        lineIndex++;
      }
    }
    else {
      if (lineIndex > 0) {
        lineIndex--;
      }
    }
  }

  public void keyPressed(int keyCode) {
    //System.out.println("keyCode = " + keyCode);
    switch (keyCode) {
      case CV.KEY_UP: //up
        if (showScrollBar) {
          moveSelect( -1);
          repaint();
        }
        break;
      case CV.KEY_DOWN: //down
        if (showScrollBar) {
          moveSelect(1);
          repaint();
        }
        break;
      case CV.KEY_POUND:
        Display.getDisplay(kyodai).setCurrent(dis);
        break;
    }

  }

  private void drawScrollBar(Graphics g) {
    g.setColor(0xffffff);
    //顶部的箭�?
    g.drawLine(CV.srcWidth - 5, 1, CV.srcWidth - 3, 1);
    g.drawLine(CV.srcWidth - 6, 2, CV.srcWidth - 2, 2);
    g.drawLine(CV.srcWidth - 6, 3, CV.srcWidth - 2, 3);
    //底部的箭�?
    g.drawLine(CV.srcWidth - 6, CV.srcHeight - 4,
               CV.srcWidth - 2, CV.srcHeight - 4);
    g.drawLine(CV.srcWidth - 6, CV.srcHeight - 3,
               CV.srcWidth - 2, CV.srcHeight - 3);
    g.drawLine(CV.srcWidth - 5, CV.srcHeight - 2,
               CV.srcWidth - 2, CV.srcHeight - 2);
    //直线
    g.drawLine(CV.srcWidth - 4, 0, CV.srcWidth - 4,
               CV.srcHeight - 1);
    //TickBar
    int y = 3 + lineIndex * 227 / maxLineIndex;
    g.fillRect(CV.srcWidth - 6, y, 5, 20);
  }

}

⌨️ 快捷键说明

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