java编程 坦克大战 为什么敌人的坦克死了以后不自动添加新的坦克

publicclassTankClientextendsFrame{publicstaticfinalintGAME_WIDTH=800;publicstaticfina... public class TankClient extends Frame{
public static final int GAME_WIDTH = 800;
public static final int GAME_HEIGHT = 600;
Image offScreenImage = null;
Tank myTank = new Tank(50,50,true,Tank.Direction.STOP,this);
Wall w1 = new Wall(300,200,20,150,this), w2 = new Wall(500,100,150,20,this);
List<Explode> explodes = new ArrayList<Explode>();
List<Missile> missile = new ArrayList<Missile>();
List<Tank> tanks = new ArrayList<Tank>();
Blood b = new Blood();
public void paint(Graphics g) {
g.drawString("多少发炮弹" + missile.size(), 10, 50);
g.drawString("爆炸了多少次" + explodes.size(), 10, 70);
g.drawString("tanks...life:"+ myTank.getLife(), 10, 90);
if(tanks.size() <= 0){//敌人坦克都死了 ,为什么这句话不执行
for(int i = 0; i < 5; i++){
tanks.add(new Tank(50 + 40*(i + 1),50,false,Tank.Direction.D, this)); } }
//if(m != null) m.draw(g);
for(int i=0; i<missile.size(); i++){
Missile m = missile.get(i);
m.hitTanks(tanks);
m.hitTank(myTank);
m.hitWall(w1);
m.hitWall(w2);
//m.hitTank(badTank);
//if(!m.isLive()) missile.remove(m);
m.draw(g); }
for(int i =0; i < explodes.size(); i++){
Explode e = explodes.get(i);
e.draw(g);
}
for(int i = 0; i < tanks.size(); i++){
Tank t = tanks.get(i);
t.hitWall(w1);
t.hitWall(w2);
t.collidesWithTanks(tanks);
t.draw(g); }
myTank.draw(g);
myTank.eat(b);
//badTank.draw(g);
w1.draw(g);
w2.draw(g);
b.draw(g); }
public void update(Graphics g) {
if(offScreenImage == null){
offScreenImage = this.createImage(GAME_WIDTH, GAME_HEIGHT); }
Graphics goffScreen = offScreenImage.getGraphics();
Color c = goffScreen.getColor();
goffScreen.setColor(Color.GREEN);
goffScreen.fillRect(0, 0, GAME_WIDTH, GAME_HEIGHT);
goffScreen.setColor(c);
paint(goffScreen);
g.drawImage(offScreenImage, 0, 0, null); }
public void lauchFrame(){
for(int i = 0; i < 10; i++){
tanks.add(new Tank(50 + 40*(i + 1),50,false,Tank.Direction.D, this)); }
this.setLocation(300, 200);
this.setSize(GAME_WIDTH, GAME_HEIGHT);
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e) {
System.exit(0); } });
this.setTitle("Tank War");
this.setResizable(false);
this.setBackground(Color.green);
this.addKeyListener(new KeyMoniter());
setVisible(true);
new Thread(new PaintThread()).start(); }
public static void main(String[] args) {
TankClient tc = new TankClient();
tc.lauchFrame(); }
public class PaintThread implements Runnable{
public void run() {
while(true){
repaint();
try {
Thread.sleep(20);
} catch (InterruptedException e) {
e.printStackTrace(); } } } }
public class KeyMoniter extends KeyAdapter{
public void keyReleased(KeyEvent e) {
myTank.keyReleased(e); }
public void keyPressed(KeyEvent e) {
myTank.keyPressed(e); } }}
展开
 我来答
粑粑爱你丶亲
2015-02-05
知道答主
回答量:5
采纳率:0%
帮助的人:5746
展开全部
需要每次坦克死亡之后再新NEW一个坦克对象出来,放入生产坦克的数组或者集合里边
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式