資源簡介
我用Java寫的小蜜蜂游戲,圖形界面,解壓后在myEclipse里直接import運行即可。

代碼片段和文件信息
package?Game;
import?java.applet.AudioClip;
import?java.awt.*;
import?java.awt.event.ActionEvent;
import?java.awt.event.ActionListener;
import?java.awt.event.KeyAdapter;
import?java.awt.event.KeyEvent;
import?java.awt.event.WindowAdapter;
import?java.awt.event.WindowEvent;
import?javax.swing.ImageIcon;
import?javax.swing.Japplet;
import?javax.swing.JLabel;
class?Cannonball{
static?int??y=560score=0;
int?temp?=?240;
ClassLoader?classLoader?=?this.getClass().getClassLoader();
public?void?paint(Graphics?gint?x2){
int?t?=?0;
if(y==560){
temp?=?x2;
}
g.setColor(Color.red);
g.fillOval(temp+20?y10?10);
if(y<560)
y--;
g.setColor(Color.LIGHT_GRAY);
g.fillOval(temp+20?y+10?10?10);
if(((temp+20)%40==0?&&?y==70?&&?TestHoney.a[0][(temp+20)/40-1]==1)||((temp+20)%40==0?&&?y==110&&?TestHoney.a[1][(temp+20)/40-1]==1)||((temp+20)%40==0?&&?y==150&&?TestHoney.a[2][(temp+20)/40-1]==1)){
AudioClip?au?=?Japplet.newAudioClip(classLoader.getResource(“112.wav“));?
au.play();?
g.setColor(Color.LIGHT_GRAY);
g.fillRect(temp+20?y?20?30);
if(y==70){
t=0;
}else?if(y==110){
t=1;
}else?if(y==150){
t=2;
}
TestHoney.a[t][(temp+20)/40-1]=0;
score+=100;
y=560;
}
if(y==0){
y=560;
}
}
}
public?class?TestHoney?extends?frame{
static?int?x1=200;
static?int?[]?[]a={{11111111111}
{11111111111}
{11111111111}};
ClassLoader?classLoader?=?this.getClass().getClassLoader();
public?TestHoney(){
AudioClip?au?=?Japplet.newAudioClip(classLoader.getResource(“start.wav“));?
au.play();
addWindowListener(new?WindowAdapter(){
public?void?windowClosing(WindowEvent?e){
dispose();
System.exit(0);
}
});
addKeyListener(new?KeyAdapter()?{
public?void?keyPressed(KeyEvent?e)?{
int?keycode?=?e.getKeyCode();
if?(keycode?==?KeyEvent.VK_LEFT)?{
x1?=?x1?-?10;
}?else?if?(keycode?==?KeyEvent.VK_RIGHT)?{
x1?=?x1?+?10;
}
else?if?(keycode?==?KeyEvent.VK_SPACE){
if(Cannonball.y==560){
AudioClip?au?=?Japplet.newAudioClip(classLoader.getResource(“BONG.wav“));?
au.play();
Cannonball.y=559;
}else
{}
}
repaint();
}
});
}
public?void?paint(Graphics?g){
int?num;
g.setColor(Color.BLUE);
g.drawString(“分數:“+Cannonball.score?20?50);
g.fillOval(x1?560?50?30);
g.setColor(Color.BLACK);
num=0;
for(int?i=0;i<11;i++){
if(a[0][i]==1)
g.fillOval(num=num+40?70?10?10);
else
num?=?num+40;
}num=0;
for(int?i=0;i<11;i++){
if(a[1][i]==1)
g.fillOval(num=num+40?110?10?10);
else
num?=?num+40;
}num=0;
for(int?i=0;i<11;i++){
if(a[2][i]==1)
g.fillOval(num=num+40?150?10?10);
else
num?=?num+40;
}
}
public?static?void?main(String?[]?args){
TestHoney?th?=?new?TestHoney();
th.setBackground(Color.LIGHT_GRAY);
th.set
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????301??2012-09-15?22:20??Honey\.classpath
?????文件????????381??2012-09-15?22:20??Honey\.project
?????文件????????598??2012-09-15?22:20??Honey\.settings\org.eclipse.jdt.core.prefs
?????文件??????58717??2012-09-16?11:34??Honey\backround.png
?????文件?????184364??2012-09-15?22:10??Honey\bin\112.wav
?????文件??????46054??2012-09-15?21:53??Honey\bin\BONG.wav
?????文件???????1781??2012-09-16?13:55??Honey\bin\Game\Cannonball.class
?????文件????????671??2012-09-16?13:55??Honey\bin\Game\TestHoney$1.class
?????文件???????1220??2012-09-16?13:55??Honey\bin\Game\TestHoney$2.class
?????文件???????3054??2012-09-16?13:55??Honey\bin\Game\TestHoney.class
?????文件?????764972??2012-09-16?13:30??Honey\bin\start.wav
?????文件?????184364??2012-09-15?22:10??Honey\src\112.wav
?????文件??????46054??2012-09-15?21:53??Honey\src\BONG.wav
?????文件???????3330??2012-09-16?13:55??Honey\src\Game\TestHoney.java
?????文件?????764972??2012-09-16?13:30??Honey\src\start.wav
?????目錄??????????0??2012-09-15?22:23??Honey\bin\Game
?????目錄??????????0??2012-09-15?22:23??Honey\src\Game
?????目錄??????????0??2012-09-15?22:23??Honey\.settings
?????目錄??????????0??2012-09-16?13:56??Honey\bin
?????目錄??????????0??2012-09-16?13:56??Honey\src
?????目錄??????????0??2012-09-16?13:56??Honey
-----------?---------??----------?-----??----
??????????????2060833????????????????????21
- 上一篇:基于javaweb進銷存管理系統
- 下一篇:拼多多、京東sdk.jar
評論
共有 條評論