Java坦克大战游戏设计 下载本文

内容发布更新时间 : 2024/5/4 13:05:49星期一 下面是文章的全部内容请认真阅读。

Java大作业报告(截止5月20日)

import java.util.Random; import java.util.Vector;

public class EnemyTank extends Tank implements Runnable{

//定义一个类集框架,存放敌人的子弹 Vector ss = new Vector();

public EnemyTank(int x, int y) { super(x, y); }

@Override

public void run() {

// TODO Auto-generated method stub while(true){ try {

Thread.sleep(50); } catch (Exception e) { // TODO: handle exception }

Java大作业报告(截止5月20日)

switch (this.direct){ case 0:

for(int i = 0 ;i <30;i++){ if(y>0) y= y-speed; try {

Thread.sleep(50); } catch (Exception e) { // TODO: handle exception } } break; case 1:

for(int i = 0 ;i <30;i++){ if(x<370) x= x+speed; try {

Thread.sleep(50); } catch (Exception e) { // TODO: handle exception

Java大作业报告(截止5月20日)

} } break; case 2:

for(int i = 0 ;i <30;i++){ if(y<270) y= y+speed; try {

Thread.sleep(50); } catch (Exception e) { // TODO: handle exception } } break; case 3:

for(int i = 0 ;i <30;i++){ if(x>0) x= x-speed; try {

Thread.sleep(50); } catch (Exception e) { // TODO: handle exception

Java大作业报告(截止5月20日)

} } break; }

//随机产生方向

Random random = new Random(); this.direct = random.nextInt(4); //判断是否死亡

if(this.isLive == false){ break; } } } }

********************************************** public class Shot implements Runnable{ //子弹坐标 int x; int y; //子弹发射方向

Java大作业报告(截止5月20日)

int direct; //子弹的速度 int speed = 6; //子弹是否生存

boolean isLive = true;

public Shot(int x,int y,int direct){ this.x=x; this.y=y;

this.direct = direct; }

@Override

public void run() {

// TODO Auto-generated method stub while(true){

//线程休眠50毫秒,每隔50毫秒子弹坐标修改一次 try {

Thread.sleep(50); } catch (Exception e) { // TODO: handle exception }

switch(direct){ case 0 ://向上飞