资源简介
基于java的坦克大战游戏,该程序可完美运行。
代码片段和文件信息
package com.Game;
import java.util.Random;
import java.util.Vector;
//坦克类
class Tank{
int x;
int y;
int direct;
int speed=8;
boolean isLive=true;
public Tank(int xint y){
this.x=x;
this.y=y;
}
public void moveUp(){
y-=speed;
if(y<0){
y=0;
}
}
public void moveDown(){
y+=speed;
if(y>570){
y=570;
}
}
public void moveLeft(){
x-=speed;
if(x<0){
x=0;
}
}
public void moveRight(){
x+=speed;
if(x>690){
x=690;
}
}
public int getX(){
return x;
}
public int getY(){
return y;
}
public void setDirect(int direct){
this.direct=direct;
}
public int getDirect(){
return direct;
}
public boolean isAcross(){
return false;
}
}
//玩家坦克类
class Hero extends Tank{
//定义子弹集合
Vector ss=new Vector();
Shot s=null;
//定义导弹集合
Vector mis=new Vector();
Missile missile=null;
int misSize=5;
//定义大炸弹数量
int c4=1;
int life=3;
public Hero(int xint y){
super(xy);
}
public void lifeDown(){
if(life>0){
life--;
}else{
this.isLive=false;
}
}
public void shotEnemy(){
s=new Shot(xydirect);
ss.add(s);
Thread t=new Thread(s);
t.start();
}
public void missileEnemy(){
if(this.misSize>0){
missile=new Missile(xydirect);
mis.add(missile);
Thread t=new Thread(missile);
t.start();
misSize--;
}
}
}
//敌人坦克类
class Enemy extends Tank implements Runnable{ //敌人坦克
int type;
int direct=1;
int life=1;
boolean begin=false;
Vector es=new Vector();
Shot enemyShot=null;//敌人子弹
Random r=new Random();
public Enemy(int xint yint type){
super(xy);
this.type=type;
if(type==0){
life=1;
}
else if(type==1){
life=2;
}
}
public void lifeDown(){
if(life>0){
life--;
}
else{
isLive=false;
}
}
public int getType(){
return type;
}
public void run() {
while(isLive){
try{
Thread.sleep(200);
}catch (InterruptedException e){
e.printStackTrace();
}
if(this.begin){
if(r.nextInt(4)==1)
{
direct=r.nextInt(4);
}
switch(direct){
case 0:this.moveUp();break;
case 1:this.moveDown();break;
case 2:this.moveLeft();break;
case 3:this.moveRight();break;
}
if(r.nextInt(4)==1&&es.size()<2){
enemyShot=new Shot(xydirect);
es.add(enemyShot);
Thread t=new Thread(enemyShot);
t.start();
}
}
}
}
}
//子弹类
class Shot implements Runnable{
int x;//子弹初始坐标
int y;
int direct;//子弹发射方向
int speed=8;//子弹速度
boolean isLive=true;
public Shot(int xint yint direct){
switch(direct){
case 0:
this.x=x+15;
this.y=y-4;
break;
case 1:
this.x=x+15;
this.y=y+34;
break;
case 2:
this.x=x-4;
this.y=y+15;
break;
case 3:
this.x=x+34;
this.y=y+15;
break;
}
this.direct=direct;
}
public int getX(){
return x
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2015-07-04 14:12 TankWar5.0\
文件 301 2015-06-29 09:50 TankWar5.0\.classpath
文件 386 2015-06-29 09:49 TankWar5.0\.project
目录 0 2015-07-04 14:12 TankWar5.0\.settings\
文件 598 2015-06-29 09:49 TankWar5.0\.settings\org.eclipse.jdt.core.prefs
目录 0 2015-07-04 14:12 TankWar5.0\bin\
文件 732956 2015-06-28 10:40 TankWar5.0\bin\background.png
文件 723137 2015-06-28 10:37 TankWar5.0\bin\background2.png
文件 205366 2015-06-28 11:41 TankWar5.0\bin\begin.png
文件 4878 2015-07-01 21:20 TankWar5.0\bin\bomb.png
文件 6019 2015-06-27 15:59 TankWar5.0\bin\boss.png
文件 296 2012-11-21 14:44 TankWar5.0\bin\bullet.png
目录 0 2015-07-04 14:12 TankWar5.0\bin\com\
目录 0 2015-07-04 14:12 TankWar5.0\bin\com\Game\
文件 565 2015-07-03 17:25 TankWar5.0\bin\com\Game\Bomb.class
文件 706 2015-07-03 17:25 TankWar5.0\bin\com\Game\Boss.class
文件 1906 2015-07-03 17:25 TankWar5.0\bin\com\Game\Enemy.class
文件 1481 2015-07-03 17:25 TankWar5.0\bin\com\Game\Hero.class
文件 705 2015-07-03 17:25 TankWar5.0\bin\com\Game\Lawn.class
文件 1332 2015-07-03 17:25 TankWar5.0\bin\com\Game\Missile.class
文件 1437 2015-07-04 12:39 TankWar5.0\bin\com\Game\MyGamePanel.class
文件 27967 2015-07-04 12:39 TankWar5.0\bin\com\Game\MyPanel.class
文件 565 2015-07-03 17:25 TankWar5.0\bin\com\Game\Nbomb.class
文件 447 2015-07-03 17:25 TankWar5.0\bin\com\Game\prop.class
文件 258 2015-07-03 17:25 TankWar5.0\bin\com\Game\Scene.class
文件 1328 2015-07-03 17:25 TankWar5.0\bin\com\Game\Shot.class
文件 498 2015-07-03 17:25 TankWar5.0\bin\com\Game\Stone.class
文件 1324 2015-07-03 17:25 TankWar5.0\bin\com\Game\Tank.class
文件 705 2015-07-03 17:25 TankWar5.0\bin\com\Game\Wall.class
文件 6088 2015-06-28 13:21 TankWar5.0\bin\enemy_1_0.png
文件 6368 2015-06-28 13:21 TankWar5.0\bin\enemy_1_1.png
............此处省略57个文件信息
评论
共有 条评论