代码格式

master
kn5886348135 3 years ago
parent a7dd8af564
commit 11457b64b8

@ -4,8 +4,8 @@ import java.awt.Graphics;
import java.awt.Color;
public class Bullet {
public static final int SPEED = 10;
private static final int WIDTH = 5, HEIGHT = 5;
private static final int SPEED = 1;
private static final int WIDTH = 30, HEIGHT = 30;
private int x, y;
private Dir dir;
@ -18,7 +18,7 @@ public class Bullet {
public void paint(Graphics g) {
Color c = g.getColor();
g.setColor(Color.RED);
g.fillOval(x, y, 50, 50);
g.fillOval(x, y, WIDTH, HEIGHT);
g.setColor(c);
move();
}

@ -1,7 +1,7 @@
package com.example.tankbattle;
import java.awt.*;
import java.awt.Graphics;
import java.awt.Color;
public class Tank {
private int x,y;
@ -39,10 +39,6 @@ public class Tank {
move();
}
public void fire(){
tf.bullets.add(new Bullet(this.x, this.y, this.dir));
}
private void move() {
if (!moving) {
return;
@ -64,4 +60,8 @@ public class Tank {
break;
}
}
public void fire(){
tf.bullets.add(new Bullet(this.x, this.y, this.dir));
}
}

@ -10,16 +10,13 @@ import java.util.List;
public class TankFrame extends Frame {
private static final int SPEED = 10;
Tank myTank = new Tank(200, 200, Dir.DOWN, this);
Bullet bullet = new Bullet(300, 300, Dir.DOWN);
private static final int GAME_WIDTH = 800,GAME_HEIGHT=600;
List<Bullet> bullets = new ArrayList<>();
Bullet bullet = new Bullet(300, 300, Dir.DOWN);
public TankFrame() throws HeadlessException {
setSize(GAME_WIDTH, GAME_HEIGHT);
setResizable(false);
@ -28,7 +25,7 @@ public class TankFrame extends Frame {
addKeyListener(new MyKeyListener());
addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
@ -54,7 +51,7 @@ public class TankFrame extends Frame {
myTank.paint(g);
bullet.paint(g);
for (Bullet bullet1 : bullets) {
bullet.paint(g);
bullet1.paint(g);
}
}

Loading…
Cancel
Save