JUI打字游戏
效果展示
游戏页面
暂停图
游戏结束页面
素材
链接: 单词素材
提取码: 95a8
链接:图片素材
提取码: 7s1u
代码实现
子弹类:
package www.git;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
/*
*@author Liu
*@Description 创建子弹类
*@data 2021/12/8
*/
public class Bullet {
private int x;
private int y;
private int speed;
public static BufferedImage image;
static {
try {
image = ImageIO.read(Bullet.class.getResourceAsStream("1bullet.png"));
} catch (IOException e) {
e.printStackTrace();
}
}
public void step() {
this.y -= this.speed;
}
public Bullet(int x) {
this.x = x;
this.y = Typer.HEIGHT;
this.speed = 12;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public int getSpeed() {
return speed;
}
public void setSpeed(int speed) {
this.speed = speed;
}
public BufferedImage getImage() {
return image;
}
public void setImage(BufferedImage image) {
this.image = image;
}
}
单词课程类
```java
package www.git;
import java.io.*;
import java.util.LinkedList;
import java.util.List;
/*
*@author Liu
*@Description
*@data 2021/12/7
*/
public class Course {
private String name;//第一行的内容
private String content;//第二行的内容
private List<Word> list;
private int index;
public Course(File file, int index) throws IOException {
if (!file.exists()) {
System.out.println("文件不存在!");
return;
}
InputStreamReader isr = new InputStreamReader(new FileInputStream(file));
BufferedReader br = new BufferedReader(isr);
this.name=br.readLine().trim();
this.content=br.readLine().trim();
this.list=new LinkedList<>();
String line=null;
while ((line=br.readLine()) != null) {
line=line.trim();
if (line.length()!=0) {
String[] s = line.trim().split("\\s+");
Word word = new Word(s[1], s[0]);
this.list.add(word);
}
}
this.index=index;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public List<Word> getList() {
return list;
}
public void setList(List<Word> list) {
this.list = list