資源簡介
飛機大戰 首先對這個游戲分析,在屏幕上的物體都是飛行物,我們可以把建一個類,讓其他飛行物繼承這個類.游戲中應有英雄機(也就是自己控制的飛機)、敵人。而敵人應該分為打死給分的飛機(就是普通飛機),另一種就是打死有獎勵的敵人。他們都應該是飛行物的子類,我們也可以為普通飛機和給獎勵的敵人設一個接口讓他們去實現接口,這樣有利于以后的擴展,我在這里給的簡化版的飛機大戰,主要是為了讓大家了解面向對象。
代碼片段和文件信息
package?cn.tedu.shoot;
import?java.util.Random;
/**?小敵機:?是飛行物,也是敵人?*/
public?class?Airplane?extends?Flyingobject?implements?Enemy?{
private?int?speed?=?3;?//移動速度
/**?構造方法?*/
public?Airplane(){
image?=?ShootGame.airplane;?//圖片
width?=?image.getWidth();???//寬
height?=?image.getHeight();?//高
Random?rand?=?new?Random();?//隨機數對象
x?=?rand.nextInt(ShootGame.WIDTH-this.width);?//x:0到(窗口寬-敵機寬)之間的隨機數
y?=?-this.height;?//y:負的敵機的高
}
/**?重寫getScore()得分?*/
public?int?getScore(){
return?5;?//打掉一個敵機得5分
}
/**?重寫step()走一步?*/
public?void?step(){
y+=speed;?//y+(向下)
}
/**?重寫outOfBounds()檢查越界?*/
public?boolean?outOfBounds(){
return?this.y>=ShootGame.HEIGHT;?//敵機的y>=窗口的高,即為越界了
}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????301??2019-11-25?09:40??Shoot\.classpath
?????文件????????381??2019-11-25?09:40??Shoot\.project
?????文件?????????57??2019-11-25?09:42??Shoot\.settings\org.eclipse.core.resources.prefs
?????文件????????598??2019-11-25?09:40??Shoot\.settings\org.eclipse.jdt.core.prefs
?????文件???????1049??2019-11-28?09:01??Shoot\bin\cn\tedu\shoot\Airplane.class
?????文件???????3575??2019-11-25?09:42??Shoot\bin\cn\tedu\shoot\airplane.png
?????文件????????357??2019-11-28?09:01??Shoot\bin\cn\tedu\shoot\Aoo.class
?????文件????????212??2019-11-28?09:01??Shoot\bin\cn\tedu\shoot\Award.class
?????文件??????26709??2019-11-25?09:42??Shoot\bin\cn\tedu\shoot\background.png
?????文件???????1186??2019-11-28?09:01??Shoot\bin\cn\tedu\shoot\Bee.class
?????文件???????6405??2019-11-25?09:42??Shoot\bin\cn\tedu\shoot\bee.png
?????文件????????268??2019-11-28?09:01??Shoot\bin\cn\tedu\shoot\Boo.class
?????文件????????856??2019-11-28?09:01??Shoot\bin\cn\tedu\shoot\Bullet.class
?????文件????????408??2019-11-25?09:42??Shoot\bin\cn\tedu\shoot\bullet.png
?????文件????????130??2019-11-28?09:01??Shoot\bin\cn\tedu\shoot\Enemy.class
?????文件????????882??2019-11-28?09:01??Shoot\bin\cn\tedu\shoot\Flyingob
?????文件??????20220??2019-11-25?09:42??Shoot\bin\cn\tedu\shoot\gameover.png
?????文件???????2302??2019-11-28?09:01??Shoot\bin\cn\tedu\shoot\Hero.class
?????文件??????12280??2019-11-25?09:42??Shoot\bin\cn\tedu\shoot\hero0.png
?????文件??????16243??2019-11-25?09:42??Shoot\bin\cn\tedu\shoot\hero1.png
?????文件??????14902??2019-11-25?09:42??Shoot\bin\cn\tedu\shoot\pause.png
?????文件???????1811??2019-11-28?09:01??Shoot\bin\cn\tedu\shoot\ShootGame$1.class
?????文件????????925??2019-11-28?09:01??Shoot\bin\cn\tedu\shoot\ShootGame$2.class
?????文件???????8482??2019-11-28?09:01??Shoot\bin\cn\tedu\shoot\ShootGame.class
?????文件??????43132??2019-11-25?09:42??Shoot\bin\cn\tedu\shoot\start.png
?????文件????????448??2019-11-28?09:01??Shoot\bin\cn\tedu\shoot\Test.class
?????文件????????896??2019-11-25?09:43??Shoot\src\cn\tedu\shoot\Airplane.java
?????文件???????3575??2019-11-25?09:42??Shoot\src\cn\tedu\shoot\airplane.png
?????文件????????204??2019-11-25?09:43??Shoot\src\cn\tedu\shoot\Award.java
?????文件??????26709??2019-11-25?09:42??Shoot\src\cn\tedu\shoot\background.png
............此處省略27個文件信息
評論
共有 條評論