default:
break;
}
return b ;
}
@Override
public void run() {
int a = (int) (Math.random() * 10 + 2);//连动步数
int times = 0;
while(true){
try {
Thread.sleep(300);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//if(x > 0 && x < 400 - 30 & y > 0 && y < 300 - 30){
//if(!this.isTouchOhterTank()){
switch(this.direct){
case 0:
//System.out.println(isTouchOhterTank());
for(int i = 0 ;i < a ; i++){
if(y - this.speed > 0 && !this.isTouchOhterTank()){
y -= this.speed;
}
try {
Thread.sleep(50);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
break;
case 1:
for(int i = 0 ;i < a ; i++){
if(y + speed < 300 - 30 && !this.isTouchOhterTank()){
y += this.speed;
}
try {
Thread.sleep(50);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
break;
case 2:
for(int i = 0 ;i < a ; i++){
if(x - speed > 0 && !this.isTouchOhterTank()){
x -= this.speed;
}
try {
Thread.sleep(50);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
break;
case 3:
for(int i = 0 ;i < a ; i++){
if(x + speed < 400 - 30 && !this.isTouchOhterTank()){
x += this.speed;
}
try {
Thread.sleep(50);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
break;
}
//}
times ++;
if(times % 2 == 0){
if(isLive){
if(ss.size() < 3){
shot s = null;
switch (direct) {
case 0://向上
s = new shot(x + 10 , y ,0);
ss.add(s);
break;
case 1://向下
s = new shot(x + 10 , y + 30 , 1);
ss.add(s);
break;
case 2://向左
s = new shot(x , y + 10 , 2);
ss.add(s);
break;
case 3://右
s = new shot(x + 30 , y + 10 , 3);
ss.add(s);
break;
default:
break;
}
Thread t = new Thread(s);
t.start();
}
}
}
//}
// //随机改变方向
// public void changeDirect(){
//
// }
if(isdirects){
this.direct = (int) (Math.random() * 4);
}
if(this.isLive == false){
break;
}
if(ss.size() < 3){
}
}
}
public void setEts(Vector<EnemyTask> ets) {
this.ets = ets;
}
Java游戏开发之坦克大战代码(6)
内容版权声明:除非注明,否则皆为本站原创文章。
转载注明出处:http://www.heiqu.com/34fa2e4cb3df2ac646cd1064dd4540ad.html