diff --git a/docs/坦克大战笔记.docx b/docs/坦克大战笔记.docx index a5a7408..666b8f0 100644 Binary files a/docs/坦克大战笔记.docx and b/docs/坦克大战笔记.docx differ diff --git a/src/com/demo/tank/coruse2/Bullet.java b/src/com/demo/tank/coruse2/Bullet.java index b5581d2..d43266e 100644 --- a/src/com/demo/tank/coruse2/Bullet.java +++ b/src/com/demo/tank/coruse2/Bullet.java @@ -17,7 +17,7 @@ public class Bullet { public void paint(Graphics g){ Color color = g.getColor(); - g.setColor(Color.BLACK); + g.setColor(Color.RED); g.fillOval(x, y, WIDTH, HEIGHT); g.setColor(color); move(); diff --git a/src/com/demo/tank/coruse2/Tank.java b/src/com/demo/tank/coruse2/Tank.java index 7f6ee56..5615af9 100644 --- a/src/com/demo/tank/coruse2/Tank.java +++ b/src/com/demo/tank/coruse2/Tank.java @@ -6,12 +6,14 @@ public class Tank { private Direction dir; private static final int SPEED = 10; private boolean moving; + private TankFrame tankFrame; - public Tank(int x, int y, Direction dir) { + public Tank(int x, int y, Direction dir, TankFrame tankFrame) { this.x = x; this.y = y; this.dir = dir; + this.tankFrame = tankFrame; } public void paint(Graphics g) { @@ -70,4 +72,9 @@ public class Tank { public void setMoving(boolean moving) { this.moving = moving; } + + public void fire() { + Bullet bullet = new Bullet(x+15, y, this.dir); + tankFrame.bullet = bullet; + } } diff --git a/src/com/demo/tank/coruse2/TankFrame.java b/src/com/demo/tank/coruse2/TankFrame.java index 5220bc8..be41f05 100644 --- a/src/com/demo/tank/coruse2/TankFrame.java +++ b/src/com/demo/tank/coruse2/TankFrame.java @@ -11,7 +11,7 @@ public class TankFrame extends Frame { private static final int GAME_HEIGHT = 600; Image image = null; - Tank tank = new Tank(500, 500, Direction.UP); + Tank tank = new Tank(500, 500, Direction.UP, this); Bullet bullet = new Bullet(520, 440, Direction.UP); public TankFrame(){ @@ -35,7 +35,7 @@ public class TankFrame extends Frame { } Graphics imgGraphic = image.getGraphics(); Color color = g.getColor(); - imgGraphic.setColor(Color.WHITE); + imgGraphic.setColor(Color.BLACK); imgGraphic.fillRect(0,0, GAME_WIDTH, GAME_HEIGHT); imgGraphic.setColor(color); paint(imgGraphic); @@ -90,6 +90,9 @@ public class TankFrame extends Frame { case KeyEvent.VK_S: bD = false; break; + case KeyEvent.VK_SPACE: + tank.fire(); + break; default: break; }