代码格式

master
kn5886348135 3 years ago
parent 4dbbef3ac4
commit 64198d3eeb

@ -1,12 +1,11 @@
package com.example.tankbattle; package com.example.tankbattle;
import java.awt.Color;
import java.awt.Graphics; import java.awt.Graphics;
public class Bullet { public class Bullet {
private static final int SPEED = 1; private static final int SPEED = 10;
public static final int WIDTH = ResourceMgr.bulletD.getWidth(); public static int WIDTH = ResourceMgr.bulletD.getWidth();
public static final int HEIGHT = ResourceMgr.bulletD.getHeight(); public static int HEIGHT = ResourceMgr.bulletD.getHeight();
private int x, y; private int x, y;
private Dir dir; private Dir dir;

@ -1,7 +0,0 @@
package com.example.tankbattle;
public class Image {
public void test() {
}
}

@ -1,8 +1,8 @@
package com.example.tankbattle; package com.example.tankbattle;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.IOException; import java.io.IOException;
import javax.imageio.ImageIO;
public class ResourceMgr { public class ResourceMgr {
public static BufferedImage tankL, tankU, tankR, tankD; public static BufferedImage tankL, tankU, tankR, tankD;
@ -19,8 +19,8 @@ public class ResourceMgr {
bulletU = ImageIO.read(ResourceMgr.class.getClassLoader().getResourceAsStream("images/bulletU.gif")); bulletU = ImageIO.read(ResourceMgr.class.getClassLoader().getResourceAsStream("images/bulletU.gif"));
bulletR = ImageIO.read(ResourceMgr.class.getClassLoader().getResourceAsStream("images/bulletR.gif")); bulletR = ImageIO.read(ResourceMgr.class.getClassLoader().getResourceAsStream("images/bulletR.gif"));
bulletD = ImageIO.read(ResourceMgr.class.getClassLoader().getResourceAsStream("images/bulletD.gif")); bulletD = ImageIO.read(ResourceMgr.class.getClassLoader().getResourceAsStream("images/bulletD.gif"));
} catch (IOException exception) { } catch (IOException e) {
exception.printStackTrace(); e.printStackTrace();
} }
} }
} }

@ -1,6 +1,5 @@
package com.example.tankbattle; package com.example.tankbattle;
import java.awt.Color;
import java.awt.Graphics; import java.awt.Graphics;
public class Tank { public class Tank {
@ -8,8 +7,8 @@ public class Tank {
private Dir dir = Dir.DOWN; private Dir dir = Dir.DOWN;
private static final int SPEED = 5; private static final int SPEED = 5;
private static final int WIDTH = ResourceMgr.tankD.getWidth(); private static int WIDTH = ResourceMgr.tankD.getWidth();
private static final int HEIGHT = ResourceMgr.tankD.getHeight(); private static int HEIGHT = ResourceMgr.tankD.getHeight();
private boolean moving = false; private boolean moving = false;

@ -15,11 +15,11 @@ import java.util.List;
public class TankFrame extends Frame { public class TankFrame extends Frame {
Tank myTank = new Tank(200, 200, Dir.DOWN, this); Tank myTank = new Tank(200, 200, Dir.DOWN, this);
public static final int GAME_WIDTH = 800,GAME_HEIGHT=600;
List<Bullet> bullets = new ArrayList<>(); List<Bullet> bullets = new ArrayList<>();
public static final int GAME_WIDTH = 800,GAME_HEIGHT=600;
public TankFrame() { public TankFrame() {
setSize(GAME_WIDTH, GAME_HEIGHT); setSize(GAME_WIDTH, GAME_HEIGHT);
setResizable(false); setResizable(false);
setTitle("tank battle"); setTitle("tank battle");
@ -52,7 +52,7 @@ public class TankFrame extends Frame {
public void paint(Graphics g) { public void paint(Graphics g) {
Color c = g.getColor(); Color c = g.getColor();
g.setColor(Color.WHITE); g.setColor(Color.WHITE);
g.drawString("子弹的数量" + bullets.size(), 10, 60); g.drawString("子弹的数量:" + bullets.size(), 10, 60);
g.setColor(c); g.setColor(c);
myTank.paint(g); myTank.paint(g);

Loading…
Cancel
Save