java坦克大战_用java编写坦克大战的问题

我现在进入写打出第一发子弹的阶段了但是很纠结啊···我的子弹始终在枪口,你动,后台输出子弹的坐标也已经在移动了但是就是不动、我的代码如下,球牛人指点啊啊啊啊啊啊//子弹类cl...

我现在进入写打出第一发子弹的阶段了 但是很纠结啊···我的子弹始终在枪口,你动,后台输出子弹的坐标也已经在移动了 但是就是不动、我的代码如下,球牛人指点啊啊啊啊啊啊//子弹类

class Shot implements Runnable{

int x;

public int getX() {

return x;

}

public void setX(int x) {

this.x = x;

}

public int getY() {

return y;

}

public void setY(int y) {

this.y = y;

}

public int getDirect() {

return direct;

}

public void setDirect(int direct) {

this.direct = direct;

}

public int getSpeed() {

return speed;

}

public void setSpeed(int speed) {

this.speed = speed;

}

int y;

int direct;

int speed=1;

//是否还活着

boolean isLive=true;

public Shot(int x,int y,int direct)

{

this.x=x;

this.y=y;

this.direct=direct;

}

@Override

public void run() {

while(true)

{

try{

Thread.sleep(50);

}catch(Exception e){

// TODO Auto-generated method stub

}

while(true)

{

switch(direct)

{

case 0:

//子弹向上

y-=speed;

break;

case 1:

x+=speed;

break;

case 2:

y+=speed;

break;

case 3:

x-=speed;

break;

}

System.out.println("子弹坐标x"+x+"y="+y);

//子弹何时死亡?

//判断该子弹是否碰到边缘

if(x<0||x>400||y<0||y>300)

{

this.isLive=false;

break;

}

}

}

}

}

//我的坦克

class Hero extends Tank

{

//子弹

Shot s=null;

public Hero(int x,int y)

{

super(x,y);

}

//开火

public void shotEnemy()

{

switch(this.direct)

{

case 0:

s=new Shot(x+10,y,0);

break;

case 1:

s=new Shot(x+30,y+10,1);

break;

case 2:

s=new Shot(x+10,y+30,2);

break;

case 3:

s=new Shot(x,y+30,3);

break;

}

//启动子弹

Thread t=new Thread(s);

t.start();

}

展开

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值