@ -1,61 +1,63 @@
|
|||||||
import java.awt.*;
|
package com.mashibing.tank;
|
||||||
|
|
||||||
/**
|
import java.awt.*;
|
||||||
* @Description: 子弹
|
|
||||||
* @Author: zhanxinlin
|
/**
|
||||||
* @Date: 2022-09-27 23:10
|
* @Description: 子弹
|
||||||
*/
|
* @Author: zhanxinlin
|
||||||
public class Bullet {
|
* @Date: 2022-09-27 23:10
|
||||||
private static final int SPEED = 10;
|
*/
|
||||||
private static final int WIDTH = 20;
|
public class Bullet {
|
||||||
private static final int HEIGHT = 20;
|
private static final int SPEED = 10;
|
||||||
|
private static final int WIDTH = 20;
|
||||||
private int x;
|
private static final int HEIGHT = 20;
|
||||||
private int y;
|
|
||||||
private FrameTank frameTank;
|
private int x;
|
||||||
private Direction direction;
|
private int y;
|
||||||
private boolean live = true;
|
private FrameTank frameTank;
|
||||||
|
private Direction direction;
|
||||||
public Bullet(int x, int y, Direction direction, FrameTank frameTank) {
|
private boolean live = true;
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
public Bullet(int x, int y, Direction direction, FrameTank frameTank) {
|
||||||
this.direction = direction;
|
this.x = x;
|
||||||
this.frameTank = frameTank;
|
this.y = y;
|
||||||
}
|
this.direction = direction;
|
||||||
|
this.frameTank = frameTank;
|
||||||
public void paint(Graphics g) {
|
}
|
||||||
// 子弹超出界限,从子弹集合中移除
|
|
||||||
if (!live) {
|
public void paint(Graphics g) {
|
||||||
frameTank.bulletList.remove(this);
|
// 子弹超出界限,从子弹集合中移除
|
||||||
}
|
if (!live) {
|
||||||
|
frameTank.bulletList.remove(this);
|
||||||
Color color = g.getColor();
|
}
|
||||||
g.setColor(Color.RED);
|
|
||||||
g.fillOval(x, y, WIDTH, HEIGHT);
|
Color color = g.getColor();
|
||||||
g.setColor(color);
|
g.setColor(Color.RED);
|
||||||
move();
|
g.fillOval(x, y, WIDTH, HEIGHT);
|
||||||
}
|
g.setColor(color);
|
||||||
|
move();
|
||||||
private void move() {
|
}
|
||||||
// 定义坦克的移动特征
|
|
||||||
switch (direction) {
|
private void move() {
|
||||||
case LEFT:
|
// 定义坦克的移动特征
|
||||||
x -= SPEED;
|
switch (direction) {
|
||||||
break;
|
case LEFT:
|
||||||
case UP:
|
x -= SPEED;
|
||||||
y -= SPEED;
|
break;
|
||||||
break;
|
case UP:
|
||||||
case RIGHT:
|
y -= SPEED;
|
||||||
x += SPEED;
|
break;
|
||||||
break;
|
case RIGHT:
|
||||||
case DOWN:
|
x += SPEED;
|
||||||
y += SPEED;
|
break;
|
||||||
break;
|
case DOWN:
|
||||||
}
|
y += SPEED;
|
||||||
|
break;
|
||||||
// 子弹超出临界范围
|
}
|
||||||
if (x < 0 || y < 0 || y > FrameTank.GAME_HEIGHT || x > FrameTank.GAME_WIDTH) {
|
|
||||||
live = false;
|
// 子弹超出临界范围
|
||||||
}
|
if (x < 0 || y < 0 || y > FrameTank.GAME_HEIGHT || x > FrameTank.GAME_WIDTH) {
|
||||||
}
|
live = false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +1,10 @@
|
|||||||
/**
|
package com.mashibing.tank;
|
||||||
* @Description: 方向枚举
|
|
||||||
* @Author: zhanxinlin
|
/**
|
||||||
* @Date: 2022-09-27 22:21
|
* @Description: 方向枚举
|
||||||
*/
|
* @Author: zhanxinlin
|
||||||
public enum Direction {
|
* @Date: 2022-09-27 22:21
|
||||||
LEFT, UP, RIGHT, DOWN
|
*/
|
||||||
}
|
public enum Direction {
|
||||||
|
LEFT, UP, RIGHT, DOWN
|
||||||
|
}
|
After Width: | Height: | Size: 824 B |
After Width: | Height: | Size: 868 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 936 B |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 8.0 KiB |
After Width: | Height: | Size: 8.0 KiB |
After Width: | Height: | Size: 8.2 KiB |
After Width: | Height: | Size: 8.2 KiB |
After Width: | Height: | Size: 855 B |
After Width: | Height: | Size: 839 B |
After Width: | Height: | Size: 839 B |
After Width: | Height: | Size: 852 B |
After Width: | Height: | Size: 847 B |
After Width: | Height: | Size: 312 B |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1022 B |
After Width: | Height: | Size: 814 B |
After Width: | Height: | Size: 460 B |
After Width: | Height: | Size: 280 B |
After Width: | Height: | Size: 565 B |
After Width: | Height: | Size: 846 B |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 864 B |
After Width: | Height: | Size: 863 B |
After Width: | Height: | Size: 861 B |
After Width: | Height: | Size: 863 B |
After Width: | Height: | Size: 673 B |
After Width: | Height: | Size: 670 B |
After Width: | Height: | Size: 680 B |
After Width: | Height: | Size: 677 B |
After Width: | Height: | Size: 660 B |
After Width: | Height: | Size: 691 B |
After Width: | Height: | Size: 674 B |
After Width: | Height: | Size: 271 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 1.3 KiB |
@ -0,0 +1,33 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 读取图片测试类
|
||||||
|
*/
|
||||||
|
class ImageTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 读取图片路径写死,不推荐
|
||||||
|
// BufferedImage image = ImageIO.read(new File("C:/work/javaprojects/Tank_60/src/images/bulletD.gif"));
|
||||||
|
// assertNotNull(image);
|
||||||
|
|
||||||
|
BufferedImage image2 = ImageIO.read(ImageTest.class.getClassLoader().getResourceAsStream("images/bulletD.gif"));
|
||||||
|
assertNotNull(image2);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|