Java游戏开发之坦克大战代码(五)

2014-11-24 08:49:44 来源: 作者: 浏览: 1
for(int i = 0 ; i < ets.size(); i ++){
EnemyTask et = ets.get(i);
TanksX[i] = et.getX();
TanksY[i] = et.getY();
ETdirects [i] = et.direct;

for(int j = 1 ; j < et.ss.size(); j++){
shot s = et.ss.get(j);
ShotsX[j] = s.x;
ShotsY[j] = s.y;
}
}
for(int i = 0 ; i < hero.ss.size(); i++ ){
shot s = hero.ss.get(i);
HeroShotsX[i] = s.x ;
HeroShotsY[i] = s.y;

}

BufferedWriter bw = null;
BufferedWriter bw1 = null ;
try {


bw = new BufferedWriter(new FileWriter("d:\\aa\\TanksX.txt"));
for(int i = 0 ; i < enSize ; i ++){
bw.write(TanksX[i] + "\r\n");
bw.write(TanksY[i] + "\r\n");
}
bw1 = new BufferedWriter(new FileWriter("d:\\aa\\KeepRecoding.txt"));
bw1.write((20 - getEnNum()) + "\r\n" );

} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
try {
bw1.close();
bw.close();

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}
private static int enNum = 5;
public static int getEnNum() {
return enNum;
}
public static void setEnNum(int enNum) {
Recoder.enNum = enNum;
}
public static int getMyLife() {
return myLife;
}
public static void setMyLife(int myLife) {
Recoder.myLife = myLife;
}
private static int myLife = 3;
private static BufferedReader br = null;

public static void getRecording(){
try {
br = new BufferedReader(new FileReader("d:\\aa\\KeepRecoding.txt"));
String n ;

while((n = br.readLine()) != null ){
String a = n;
enNum = 20 - Integer.parseInt(n);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
try {
br.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}


}
private static BufferedWriter bw = null;
public static void KeepRecording (){
try {
bw = new BufferedWriter(new FileWriter("d:\\aa\\KeepRecoding.txt"));
bw.write((20 - getEnNum()) + "\r\n" );
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
bw.close();//先开后关
//new FileWriter("d:\\aa\\KeepRecoding.txt").close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}
}


public class Tank {
int x = 0 ;
int y = 0;
int direct = 0; //方向
int type = 0 ;//类型
int speed = 30;//速度
int color;
boolean isLive;
public int getColor() {
return color;
}
public void setColor(int color) {
this.color = color;
}
public int getS() {
return speed;
}
public void setS(int speed) {
this.speed = speed;
}
public Tank(int x , int y , int direct
, int type, int speed, boolean isLive){
this.x = x;
this.y = y;
this.direct = direct;
this.type= type;
this.speed = speed;
this.isLive = isLive;
}
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 getD() {
return direct;
}
public void setD(int direct) {
this.direct = direct;
}
public int getT() {
return type;
}
public void setT(int type) {
this.type = type;
}

}
class EnemyTask extends Tank implements Runnable{
Vector ss = new Vector();
Vector ets = new Vector();
boolean isdirects = true;
public EnemyTask(int x, int y, int direct
, int type, int speed ,boolean isLive) {
super(x, y, direct, type, speed, isLive);
// TODO Auto-generated constructor stub
}
public boolean isTouchOhterTank (){
boolean b = false;
switch (this.direct) {
case 0://此坦克向上
for(int i = 0; i < ets.size(); i++){
EnemyTask et = ets.get(i);
if(et != this){
if(et.direc

-->

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: