?? about.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 + -