?? kyodaiui.java
字號:
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 + -