坦克java代码 java tank程序代码( 四 )


/*
* 指明子弹-爆炸-坦克的数量
* 以及坦克的生命值
*/
g.drawString("missiles count:" + missiles.size(), 10, 50);
g.drawString("explodes count:" + explodes.size(), 10, 70);
g.drawString("tankscount:" + tanks.size(), 10, 90);
g.drawString("tankslife:" + myTank.getLife(), 10, 110);
if(tanks.size() = 0) {
【坦克java代码 java tank程序代码】for(int i=0; iInteger.parseInt(PropertyMgr.getProperty("reProduceTankCount")); i++) {
tanks.add(new Tank(50 + 40*(i+1), 50, false, Direction.D, this));
}
}
for(int i=0; imissiles.size(); i++) {
Missile m = missiles.get(i);
m.hitTanks(tanks);
m.hitTank(myTank);
m.hitWall(w1);
m.hitWall(w2);
m.draw(g);
//if(!m.isLive()) missiles.remove(m);
//else m.draw(g);
}
for(int i=0; iexplodes.size(); i++) {
Explode e = explodes.get(i);
e.draw(g);
}
for(int i=0; itanks.size(); i++) {
Tank t = tanks.get(i);
t.collidesWithWall(w1);
t.collidesWithWall(w2);
t.collidesWithTanks(tanks);
t.draw(g);
}
myTank.draw(g);
myTank.eat(b);
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.BLACK);
gOffScreen.fillRect(0, 0, GAME_WIDTH, GAME_HEIGHT);
gOffScreen.setColor(c);
paint(gOffScreen);
g.drawImage(offScreenImage, 0, 0, null);
}
/**
* 本方法显示坦克主窗口
*
*/
public void lauchFrame() {
int initTankCount = Integer.parseInt(PropertyMgr.getProperty("initTankCount"));
for(int i=0; iinitTankCount; i++) {
tanks.add(new Tank(50 + 40*(i+1), 50, false, Direction.D, this));
}
//this.setLocation(400, 300);
this.setSize(GAME_WIDTH, GAME_HEIGHT);
this.setTitle("TankWar");
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
this.setResizable(false);
this.setBackground(Color.GREEN);
this.addKeyListener(new KeyMonitor());
setVisible(true);
new Thread(new PaintThread()).start();
}
public static void main(String[] args) {
TankClient tc = new TankClient();
tc.lauchFrame();
}
private class PaintThread implements Runnable {
public void run() {
while(true) {
repaint();
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
private class KeyMonitor extends KeyAdapter {
public void keyReleased(KeyEvent e) {
myTank.keyReleased(e);
}
public void keyPressed(KeyEvent e) {
myTank.keyPressed(e);
}
}
}
java坦克大战源代码 怎么导入坦克大战源代码应该是个完整的项目吧 。
对于完整的带项目配置文件的java源码 , 按步骤操作即可:
File- Import-General
选择Existing Projects into Workspace,选择要导入的文件 , 点击“finish",OK 。
坦克java代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java tank程序代码、坦克java代码的信息别忘了在本站进行查找喔 。

推荐阅读