Compare commits

...

3 Commits

Before

Width:  |  Height:  |  Size: 824 B

After

Width:  |  Height:  |  Size: 824 B

Before

Width:  |  Height:  |  Size: 868 B

After

Width:  |  Height:  |  Size: 868 B

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Before

Width:  |  Height:  |  Size: 936 B

After

Width:  |  Height:  |  Size: 936 B

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Before

Width:  |  Height:  |  Size: 8.0 KiB

After

Width:  |  Height:  |  Size: 8.0 KiB

Before

Width:  |  Height:  |  Size: 8.0 KiB

After

Width:  |  Height:  |  Size: 8.0 KiB

Before

Width:  |  Height:  |  Size: 8.2 KiB

After

Width:  |  Height:  |  Size: 8.2 KiB

Before

Width:  |  Height:  |  Size: 8.2 KiB

After

Width:  |  Height:  |  Size: 8.2 KiB

Before

Width:  |  Height:  |  Size: 855 B

After

Width:  |  Height:  |  Size: 855 B

Before

Width:  |  Height:  |  Size: 839 B

After

Width:  |  Height:  |  Size: 839 B

Before

Width:  |  Height:  |  Size: 839 B

After

Width:  |  Height:  |  Size: 839 B

Before

Width:  |  Height:  |  Size: 852 B

After

Width:  |  Height:  |  Size: 852 B

Before

Width:  |  Height:  |  Size: 847 B

After

Width:  |  Height:  |  Size: 847 B

Before

Width:  |  Height:  |  Size: 312 B

After

Width:  |  Height:  |  Size: 312 B

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Before

Width:  |  Height:  |  Size: 1022 B

After

Width:  |  Height:  |  Size: 1022 B

Before

Width:  |  Height:  |  Size: 814 B

After

Width:  |  Height:  |  Size: 814 B

Before

Width:  |  Height:  |  Size: 460 B

After

Width:  |  Height:  |  Size: 460 B

Before

Width:  |  Height:  |  Size: 280 B

After

Width:  |  Height:  |  Size: 280 B

Before

Width:  |  Height:  |  Size: 565 B

After

Width:  |  Height:  |  Size: 565 B

Before

Width:  |  Height:  |  Size: 846 B

After

Width:  |  Height:  |  Size: 846 B

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Before

Width:  |  Height:  |  Size: 864 B

After

Width:  |  Height:  |  Size: 864 B

Before

Width:  |  Height:  |  Size: 863 B

After

Width:  |  Height:  |  Size: 863 B

Before

Width:  |  Height:  |  Size: 861 B

After

Width:  |  Height:  |  Size: 861 B

Before

Width:  |  Height:  |  Size: 863 B

After

Width:  |  Height:  |  Size: 863 B

Before

Width:  |  Height:  |  Size: 673 B

After

Width:  |  Height:  |  Size: 673 B

Before

Width:  |  Height:  |  Size: 670 B

After

Width:  |  Height:  |  Size: 670 B

Before

Width:  |  Height:  |  Size: 680 B

After

Width:  |  Height:  |  Size: 680 B

Before

Width:  |  Height:  |  Size: 677 B

After

Width:  |  Height:  |  Size: 677 B

Before

Width:  |  Height:  |  Size: 660 B

After

Width:  |  Height:  |  Size: 660 B

Before

Width:  |  Height:  |  Size: 691 B

After

Width:  |  Height:  |  Size: 691 B

Before

Width:  |  Height:  |  Size: 674 B

After

Width:  |  Height:  |  Size: 674 B

Before

Width:  |  Height:  |  Size: 271 KiB

After

Width:  |  Height:  |  Size: 271 KiB

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

@ -9,8 +9,8 @@ import java.awt.*;
*/
public class Bullet {
private static final int SPEED = 10;
private static final int WIDTH = 20;
private static final int HEIGHT = 20;
public static int WIDTH = ResourceImageRead.BULLET_DOWN.getWidth();
public static int HEIGHT = ResourceImageRead.BULLET_DOWN.getHeight();
private int x;
private int y;
@ -31,15 +31,28 @@ public class Bullet {
frameTank.bulletList.remove(this);
}
Color color = g.getColor();
g.setColor(Color.RED);
g.fillOval(x, y, WIDTH, HEIGHT);
g.setColor(color);
// 画出坦克前后左右移动的图片
switch (direction) {
case LEFT:
g.drawImage(ResourceImageRead.BULLET_LEFT, x, y, null);
break;
case UP:
g.drawImage(ResourceImageRead.BULLET_UP, x, y, null);
break;
case RIGHT:
g.drawImage(ResourceImageRead.BULLET_RIGHT, x, y, null);
break;
case DOWN:
g.drawImage(ResourceImageRead.BULLET_DOWN, x, y, null);
break;
}
// 子弹移动
move();
}
private void move() {
// 定义坦克的移动特征
// 定义子弹的移动特征
switch (direction) {
case LEFT:
x -= SPEED;

@ -14,14 +14,25 @@ public class ResourceImageRead {
public static BufferedImage TANK_UP;
public static BufferedImage TANK_RIGHT;
public static BufferedImage TANK_DOWN;
public static BufferedImage BULLET_LEFT;
public static BufferedImage BULLET_UP;
public static BufferedImage BULLET_RIGHT;
public static BufferedImage BULLET_DOWN;
// 当ResourceImageRead类加载时静态代码块执行直接初始化
static {
try {
// 赋值坦克图片
TANK_LEFT = ImageIO.read(ResourceImageRead.class.getClassLoader().getResourceAsStream("images/tankL.gif"));
TANK_UP = ImageIO.read(ResourceImageRead.class.getClassLoader().getResourceAsStream("images/tankU.gif"));
TANK_RIGHT = ImageIO.read(ResourceImageRead.class.getClassLoader().getResourceAsStream("images/tankR.gif"));
TANK_DOWN = ImageIO.read(ResourceImageRead.class.getClassLoader().getResourceAsStream("images/tankD.gif"));
// 赋值子弹图片
BULLET_LEFT = ImageIO.read(ResourceImageRead.class.getClassLoader().getResourceAsStream("images/bulletL.gif"));
BULLET_UP = ImageIO.read(ResourceImageRead.class.getClassLoader().getResourceAsStream("images/bulletU.gif"));
BULLET_RIGHT = ImageIO.read(ResourceImageRead.class.getClassLoader().getResourceAsStream("images/bulletR.gif"));
BULLET_DOWN = ImageIO.read(ResourceImageRead.class.getClassLoader().getResourceAsStream("images/bulletD.gif"));
} catch (IOException e) {
e.printStackTrace();
}

@ -9,6 +9,9 @@ import java.awt.*;
*/
public class Tank {
private static final int SPEED = 5;
public static int WIDTH = ResourceImageRead.TANK_DOWN.getWidth();
public static int HEIGHT = ResourceImageRead.TANK_DOWN.getHeight();
private int x;
private int y;
private Direction direction;
@ -79,8 +82,11 @@ public class Tank {
* FrameTank
*/
public void fire() {
int bulletX = this.x + Tank.WIDTH / 2 - Bullet.WIDTH / 2;
int bulletY = this.y + Tank.HEIGHT / 2 - Bullet.HEIGHT / 2;
// 将子弹加入子弹集合
frameTank.bulletList.add(new Bullet(this.x, this.y, this.direction, this.frameTank));
frameTank.bulletList.add(new Bullet(bulletX, bulletY, this.direction, this.frameTank));
}
public Direction getDirection() {

@ -3,7 +3,6 @@ package test;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

Loading…
Cancel
Save