|
|
|
@ -5,6 +5,8 @@ import java.awt.event.KeyAdapter;
|
|
|
|
|
import java.awt.event.KeyEvent;
|
|
|
|
|
import java.awt.event.WindowAdapter;
|
|
|
|
|
import java.awt.event.WindowEvent;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -16,7 +18,8 @@ import java.util.Objects;
|
|
|
|
|
public class TankFrame extends Frame {
|
|
|
|
|
|
|
|
|
|
Tank tank = new Tank(200, 200, DirEnum.RIGHT, this);
|
|
|
|
|
Bullet bullet = new Bullet(200, 200, DirEnum.DOWN);
|
|
|
|
|
// Bullet bullet = new Bullet(200, 200, DirEnum.DOWN);
|
|
|
|
|
List<Bullet> bullets = new ArrayList<>();
|
|
|
|
|
public static final int GAME_WIDTH = 800;
|
|
|
|
|
public static final int GAME_HEIGHT = 600;
|
|
|
|
|
|
|
|
|
@ -42,8 +45,14 @@ public class TankFrame extends Frame {
|
|
|
|
|
@Override
|
|
|
|
|
public void paint(Graphics g) {
|
|
|
|
|
// super.paint(g);
|
|
|
|
|
Color color = g.getColor();
|
|
|
|
|
g.setColor(Color.BLACK);
|
|
|
|
|
g.drawString("子弹的数量:" + bullets.size(), 10, 60);
|
|
|
|
|
g.setColor(color);
|
|
|
|
|
tank.paint(g);
|
|
|
|
|
bullet.paint(g);
|
|
|
|
|
for (int i=0; i<bullets.size(); i++) {
|
|
|
|
|
bullets.get(i).paint(g);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//双缓冲,解决闪烁现象
|
|
|
|
|