資源簡介
金子,銀子,炸彈下落,利用錢袋進行接寶,錢袋可以移動實現接寶游戲設計。

代碼片段和文件信息
package?zhidao;
import?java.awt.Color;
import?java.awt.Font;
import?java.awt.Graphics;
import?java.awt.Graphics2D;
import?java.awt.Image;
import?java.awt.RenderingHints;
import?java.awt.event.KeyAdapter;
import?java.awt.event.KeyEvent;
import?java.io.BufferedReader;
import?java.io.BufferedWriter;
import?java.io.File;
import?java.io.FileReader;
import?java.io.FileWriter;
import?java.io.IOException;
import?java.io.PrintWriter;
import?java.util.ArrayList;
import?java.util.Arrays;
import?java.util.linkedList;
import?java.util.List;
import?java.util.Random;
import?java.util.Vector;
import?javax.swing.ImageIcon;
import?javax.swing.Jframe;
public?class?YuanbaoGame?extends?Jframe?implements?Runnable?{
private?Image?iBuffer;?//?雙緩沖,防止游戲閃爍
private?Graphics?gBuffer;?//?雙緩沖,防止游戲閃爍
private?long?gameSpeed?=?10;//?游戲速度
private?long?nextFloatSpeed?=?800;?//?每個多長時間出現一個
/**
?*?
?*/
private?long?timer?=?0;?//?計時器
private?Color?panelColor?=?Color.white;
private?int?gameScore?=?0;
private?int?flapperPosX?=?125;
private?boolean?gamePause?=?true;
private?boolean?gameOver?=?false;
private?boolean?gameHistoryScores?=?false;
List?floatItems?=?new?linkedList();
List?scores?=?new?ArrayList();
//?Vector?floatItems?=?new?Vector();
public?YuanbaoGame()?{
try?{
BufferedReader?br?=?new?BufferedReader(new?FileReader(new?File(YuanbaoGame.class.getResource(“historyscore“).toURI())));
StringBuffer?scoreBuff?=?new?StringBuffer(““);
String?tmp?=?null;
while((tmp?=?br.readLine())?!=?null){
scoreBuff.append(tmp);
}
if(scoreBuff.length()?>?0){
String[]?scoreArr?=?scoreBuff.toString().split(““);
for?(String?s?:?scoreArr)?{
try?{
scores.add(Integer.parseInt(s));
}?catch?(NumberFormatException?e)?{
System.err.println(“[“+s+“]不是有效分數!“);
}
}
}
}?catch?(Exception?e)?{
e.printStackTrace();
}
}
public?void?run()?{
while?(true)?{
try?{
Thread.sleep(gameSpeed);
if(gamePause){
drawGamePause();
continue;
}
if(gameOver?&&?!gamePause){
gamePause?=?true;
drawGameOver();
continue;
}
timer?+=?gameSpeed;
}?catch?(InterruptedException?e)?{
e.printStackTrace();
}
synchronized?(floatItems)?{
if?(floatItems.size()?>?0)?{
FloatItem?item?=?null;
for?(int?i?=?0;?i? item?=?floatItems.get(i);
item.setPosY(item.getPosY()?+?item.getSpeed());
//?檢測碰撞
if?(item.getPosY()?>?530?-?FloatItem.IMAGE_WIDTH)?{
if?(item.getPosX()?>?flapperPosX?-?FloatItem.IMAGE_WIDTH?&&?item.getPosX()? if?(item.getScore()?>?0)?{
gameScore?+=?item.getScore();
floatItems.remove(i);
}?else?{
gameOver?=?true;
}
}
}
//?物品掉落到底部,刪除該物品
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-03-03?10:56??知道\
?????文件?????????299??2014-09-11?12:36??知道\.classpath
?????文件?????????382??2014-09-11?12:36??知道\.project
?????目錄???????????0??2017-03-03?10:56??知道\.settings\
?????文件?????????598??2014-09-11?12:36??知道\.settings\org.eclipse.jdt.core.prefs
?????目錄???????????0??2017-03-03?10:56??知道\bin\
?????目錄???????????0??2017-03-03?10:56??知道\bin\zhidao\
?????文件???????22270??2014-09-21?22:06??知道\bin\zhidao\boom.png
?????文件????????2277??2014-10-04?18:32??知道\bin\zhidao\FloatItem.class
?????文件???????21287??2014-09-21?22:06??知道\bin\zhidao\gold.png
?????文件?????????210??2014-10-04?18:42??知道\bin\zhidao\historyscore
?????文件???????21214??2014-09-21?22:06??知道\bin\zhidao\silver.png
?????文件????????1263??2014-10-04?18:32??知道\bin\zhidao\YuanbaoGame$1.class
?????文件????????9277??2014-10-04?18:32??知道\bin\zhidao\YuanbaoGame.class
?????文件???????22270??2014-09-10?15:18??知道\boom.png
?????文件???????21287??2014-09-10?15:35??知道\gold.png
?????文件???????21214??2014-09-10?15:35??知道\silver.png
?????目錄???????????0??2017-03-03?10:56??知道\src\
?????目錄???????????0??2017-03-03?10:56??知道\src\zhidao\
?????文件???????22270??2014-09-21?22:06??知道\src\zhidao\boom.png
?????文件???????21287??2014-09-21?22:06??知道\src\zhidao\gold.png
?????文件???????????0??2014-09-21?22:06??知道\src\zhidao\historyscore
?????文件???????21214??2014-09-21?22:06??知道\src\zhidao\silver.png
?????文件????????9908??2014-10-04?18:32??知道\src\zhidao\YuanbaoGame.java
- 上一篇:駕校管理系統課程設計JAVA
- 下一篇:JAVA圖書管理系統源代碼
評論
共有 條評論