Add files via upload

This commit is contained in:
HueyM 2020-12-17 08:58:19 +08:00 committed by GitHub
parent 3cee2087ca
commit 981d5d3de4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
93 changed files with 1572 additions and 0 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,39 @@
一、项目名称《天天酷跑》RunDay
二、功能介绍:
闯关类游戏,玩家登录后,选择进入游戏,通过键盘控制玩家的上下左右移动,来躲避
障碍物和吃金币,玩家躲避的障碍物越多跑酷距离越远,玩家吃的金币越多,得分越高。
三、功能模块:
1、登录界面
用户名(输入框,明文) 密码(输入框,密文) 登录、取消按钮
2、菜单选择界面
开始游戏按钮(图片按钮) 帮助按钮 退出按钮
3、缓冲加载界面
自动加载进度条,加载完毕之后,跳转到下一界面
4、游戏主界面
移动的背景图片、动态的玩家、五种障碍物持续出现、玩家和障碍物的碰撞、
暂停、继续功能、玩家的移动功能
5、结束界面
获取玩家的得分、跑酷距离。继续游戏、返回主菜单的功能。
--------------------------------------------------------------
四、开发者Huey
五、版本号1.0
六、开发时间2020.11.16
开发模式MVC模式
MModel数据层存储的是实体类。
V:View显示层存储的是关于界面的类。
Controller控制层存储的是相关的逻辑层代码。
企业级项目命名规范:
cn.sqc.runday.view

BIN
RunDay/image/1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
RunDay/image/101.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

BIN
RunDay/image/11.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

BIN
RunDay/image/11.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

BIN
RunDay/image/112.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

BIN
RunDay/image/113.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

BIN
RunDay/image/114.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
RunDay/image/115.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

BIN
RunDay/image/117.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

BIN
RunDay/image/12.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

BIN
RunDay/image/13.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

BIN
RunDay/image/14.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

BIN
RunDay/image/2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

BIN
RunDay/image/21.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

BIN
RunDay/image/22.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

BIN
RunDay/image/23.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

BIN
RunDay/image/24.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

BIN
RunDay/image/25.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

BIN
RunDay/image/26.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

BIN
RunDay/image/3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
RunDay/image/4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

BIN
RunDay/image/5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
RunDay/image/6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
RunDay/image/7.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
RunDay/image/8.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
RunDay/image/9.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
RunDay/image/a12.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

BIN
RunDay/image/a2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

BIN
RunDay/image/a4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
RunDay/image/a9.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

BIN
RunDay/image/b1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

BIN
RunDay/image/b11.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
RunDay/image/b2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

BIN
RunDay/image/bzbg.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 207 KiB

BIN
RunDay/image/cc.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 187 KiB

BIN
RunDay/image/chou.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 351 KiB

BIN
RunDay/image/d1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
RunDay/image/d2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
RunDay/image/d3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
RunDay/image/d4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
RunDay/image/d5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
RunDay/image/d6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
RunDay/image/daodan.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
RunDay/image/end_1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

BIN
RunDay/image/endbg.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 361 KiB

BIN
RunDay/image/gbg.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

BIN
RunDay/image/h3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

BIN
RunDay/image/hbg.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

BIN
RunDay/image/hh1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

BIN
RunDay/image/hh2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

BIN
RunDay/image/hh3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

BIN
RunDay/image/hh4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

BIN
RunDay/image/hh5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

BIN
RunDay/image/hh6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

BIN
RunDay/image/hhh.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

BIN
RunDay/image/login.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

BIN
RunDay/image/m1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 117 KiB

BIN
RunDay/image/main.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 788 KiB

BIN
RunDay/image/mian_1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

BIN
RunDay/image/mm1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 KiB

BIN
RunDay/image/pp.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

View File

@ -0,0 +1,364 @@
package cn.sqc.runday.controller;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
import cn.sqc.runday.model.Barrs_1;
import cn.sqc.runday.model.Barrs_2;
import cn.sqc.runday.model.Barrs_3;
import cn.sqc.runday.model.Barrs_4;
import cn.sqc.runday.model.Barrs_5;
import cn.sqc.runday.model.Person;
import cn.sqc.runday.view.EndFrame;
import cn.sqc.runday.view.GameFrame;
/**
* @author Huey
*2020-11-27 下午12:28:44
* 游戏主面板类核心逻辑类
* 1背景图片滚动效果
* 2玩家动态效果
* 3五种障碍物的出现
* 4玩家和障碍物的碰撞逻辑
* 5暂停继续逻辑
* 6结束逻辑
*/
public class GamePanel extends JPanel implements KeyListener{
/**2、生成动态的背景图片***/
//2.1声明背景图片对象
Image background;
Image score;
Image pause;//暂停
Image proceed;//继续.
/***3.实现玩家的动态效果和移动功能***/
//3.1创建玩家对象类的实例化
Person person;
Barrs_2 barrs_2;//宠物
Barrs_4 barrs_4;//鱼钩等障碍物
Barrs_5 barrs_5;//金币
/**4.实现螃蟹障碍物*/
//4.1
Barrs_1[]barrs1 = {};//存储螃蟹数组没有元素可以扩容
Barrs_3[]barrs3 ={};//导弹
Barrs_4[]barrs4={};//鱼钩
Barrs_5[]barrs5 = {};//金币
public GamePanel() {
//3.2
person = new Person();//调用Person类的构造方法创建对象并赋值
barrs_2 = new Barrs_2();
//2.2读取图片文件
try{
background =ImageIO.read(new File("Image/cc.png"));//跑酷背景
score =ImageIO.read(new File("Image/a12.png"));//得分背景
pause = ImageIO.read(new File("Image/b2.png"));
proceed = ImageIO.read(new File("Image/b1.png"));
}catch(IOException e){
e.printStackTrace();
}
}
//2.5
int x=0;//背景图片初始位置
@Override
public void paint(Graphics g) {
super.paint(g);
//2.7
if(flag){
x-=20;//图片滚动的速度
}
//2.3绘制背景图片(动态切换很流畅)
g.drawImage(background, x, 0, GameFrame.WIDTH, GameFrame.HEIGHT, null);
g.drawImage(background, x+GameFrame.WIDTH, 0, GameFrame.WIDTH, GameFrame.HEIGHT,null);
if(x<=-GameFrame.WIDTH){//实现两张图片之间的切换
x = 0;
}
//3.3绘制 玩家
person.paintPerson(g);
//绘制螃蟹
for(int i =0;i<barrs1.length;i++){
barrs1[i].paintBarrs(g);
}
//绘制宠物
barrs_2.paintBarrs(g);
//绘制导弹
for(int i =0;i<barrs3.length;i++){
barrs3[i].paintBarrs(g);
}
//随机绘制鱼钩障碍物
for(int i =0;i<barrs4.length;i++){
barrs4[i].paintBarrs(g);
}
//随机绘制金币
for(int i = 0;i<barrs5.length;i++){
barrs5[i].paintBarrs(g);
}
//位置越往下图层越往上
//绘制玩家分数
g.drawImage(score, 120, 50,null);
g.setColor(Color.ORANGE);
g.setFont(new Font("宋体",Font.BOLD,30 ));
g.drawString("玩家得分:"+person.getScore()+"", 133, 95);
//绘制暂停继续标识图片
if(flag){
g.drawImage(proceed, 200, 800, 90,90,null);
}else{
g.drawImage(pause, 200, 800, 90, 90, null);
}
}
//
int index =0;
public void enteredAction(){//实现源源 生成障碍物的效果
index++;
//生成螃蟹障碍物
if(index%100==0){
//生成一个螃蟹
Barrs_1 b1 = new Barrs_1();
Barrs_3 b3 = new Barrs_3();
Barrs_4 b4 = new Barrs_4();
barrs1 =Arrays.copyOf(barrs1,barrs1.length+1);//数组扩容
barrs1[barrs1.length-1]= b1;//放到数组最后一个元素的位置
//System.out.println("测试"+barrs1.length);
barrs3 =Arrays.copyOf(barrs3,barrs3.length+1);
barrs3[barrs3.length-1]= b3;
barrs4 =Arrays.copyOf(barrs4,barrs4.length+1);
barrs4[barrs4.length-1]= b4;
}
if(index%15==0){
Barrs_5 b5 = new Barrs_5();
barrs5 = Arrays.copyOf(barrs5, barrs5.length +1);
barrs5[barrs5.length-1] = b5;
}
}
//
public void stepAction(){
//3..4
person.step();//切换玩家的图片>动起来
person.drop();//不断下坠
barrs_2.drop();
//螃蟹障碍物移动
for(int i =0;i<barrs1.length;i++){
barrs1[i].step();
//判断当前障碍物是否 越界并做越界处理
if(barrs1[i].outofBounds()){
//删除越界的螃蟹障碍物
barrs1[i] = barrs1[barrs1.length - 1];//将螃蟹数组最后一个元素赋给越界的螃蟹覆盖了相当于间接删除了
barrs1= Arrays.copyOf(barrs1, barrs1.length - 1);//数组缩容
}
}
barrs_2.step();
for(int i =0;i<barrs3.length;i++){
barrs3[i].step();
//删除越界的导弹障碍物
if(barrs3[i].outofBounds()){
barrs3[i] = barrs3[barrs3.length - 1];
barrs3 = Arrays.copyOf(barrs3, barrs3.length - 1);
}
}
for(int i =0;i<barrs4.length;i++){
barrs4[i].step();
//删除越界的鱼叉障碍物
if(barrs4[i].outofBounds()){
barrs4[i] = barrs4[barrs4.length - 1 ];
barrs4 = Arrays.copyOf(barrs4, barrs4.length - 1);
}
}
for(int i = 0;i<barrs5.length;i++){
barrs5[i].step();
if(barrs5[i].outofBounds()){
//删除越界的金币
barrs5[i] = barrs5[barrs5.length - 1];
barrs5 = Arrays.copyOf(barrs5, barrs5.length - 1);
}
}
}
//玩家和障碍物碰撞的处理方法
public void pengAction(){
//判断玩家是否和螃蟹障碍物进行碰撞
for(int i = 0;i<barrs1.length;i++){//上下左右都写了下是用不到的
if(person.getX() + Person.WIDTH >= barrs1[i].getX() &&
person.getX() <= barrs1[i].getX() + Barrs_1.WIDTH &&
person .getY() +Person.getHeight() >= barrs1[i].getY() &&
person.getY() <= barrs1[i].getY () + Barrs_1.HEIGHT){
//碰撞后的处理遮挡类障碍物
if(person.getX() + Person.WIDTH <= barrs1[i].getX() + Barrs_1.WIDTH){//防止人在右边碰撞后可以穿过障碍物
//左碰撞
person.setX(barrs1[i].getX() - Barrs_1.WIDTH);
}else{
//右碰撞
person.setX(barrs1[i].getX()+ Barrs_1.WIDTH );
}
}
}
//判断玩家是否和导弹障碍物进行碰撞
for(int i = 0;i<barrs3.length;i++){
if(person.getX() + Person.WIDTH >= barrs3[i].getX() &&
person.getX() <= barrs3[i].getX() + Barrs_3.WIDTH &&
person .getY() +Person.getHeight() >= barrs3[i].getY() &&
person.getY() <= barrs3[i].getY () + Barrs_3.HEIGHT){
if(person.getX() + Person.WIDTH <= barrs3[i].getX() + Barrs_3.WIDTH){//玩家的宽度120px是比障碍物小的
//左碰撞
person.setX(barrs3[i].getX() - Barrs_3.WIDTH);
}else{
//右碰撞
person.setX(barrs3[i].getX()+ Barrs_3.WIDTH );
}
}
}
//判断玩家是否和鱼叉障碍物进行碰撞
for(int i = 0;i<=barrs4.length -1;i++){//小心数组越界
if(person.getX() + Person.WIDTH >= barrs4[i].getX() &&
person.getX() <= barrs4[i].getX() + Barrs_4.WIDTH &&
person.getY() + Person.HEIGHT >= barrs4[i].getY() &&
person.getY() <= barrs4[i].getY() + Barrs_4.HEIGHT ){
if(person.getX() + Person.WIDTH <= barrs4[i].getX() + Barrs_4.WIDTH ){
//左碰撞
person.setX(barrs4[i].getX() - Barrs_4.WIDTH);
}else{
//右碰撞
person.setX(barrs4[i].getX()+ Barrs_4.WIDTH );
}
}
}
//玩家和金币的碰撞
for(int i = 0;i<barrs5.length;i++){
if(person.getX() + Person.WIDTH >= barrs5[i].getX() &&
person.getX() <= barrs5[i].getX() + Barrs_5.WIDTH &&
person .getY() +Person.getHeight() >= barrs5[i].getY() &&
person.getY() <= barrs5[i].getY () + Barrs_5.HEIGHT){//判断玩家与金币的碰撞
if(person.getX() + Person.WIDTH <= barrs5[i].getX() + Barrs_5.WIDTH){
//删除当前金币
barrs5[i] = barrs5[barrs5.length - 1];
barrs5 = Arrays.copyOf(barrs5, barrs5.length - 1);
//玩家加分
int score = person.getScore();
person.setScore(score + 10);
}
}
}
}
//结束逻辑
public void gameOverAction(){
if(person.outOfBounds()){
//程序结束
isGameOver = true;
//传递数据创建结束界面
new EndFrame(person);//面向对象思想
//数据清空
person = new Person();
barrs1 = new Barrs_1[]{};
barrs3 = new Barrs_3[]{};
}
}
public boolean isGameOver = false;
boolean flag = true;
//2.8
public void action(){
new Thread(){//匿名内部类
//重写run方法
public void run() {
while(!isGameOver){
//3.4
if(flag){
enteredAction();//细节只有先生成了障碍物后下面才能调用移动障碍物的方法
stepAction();
pengAction();//玩家和障碍物碰撞
gameOverAction();
}
//重绘方法
repaint();
//线程休眠
try {
Thread.sleep(60);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
};
}.start();//创建一个线程并启动
}
@Override
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
}
@Override
public void keyPressed(KeyEvent e) {
//获取玩家当前位置坐标
int x = person.getX();
int y = person.getY();
int x1 = barrs_2.getX();
int y1 = barrs_2.getY();
//
if(e.getKeyCode() == KeyEvent.VK_UP && y > 10 && y1 > 10){
person.setY(y-25);
barrs_2.setY(y-25);
}
//
if(e.getKeyCode()== KeyEvent.VK_DOWN && y<=560 && y1<560){
person.setY(y+30);
barrs_2.setY(y-30);
}
//
if(e.getKeyCode()==KeyEvent.VK_LEFT && x>=0 ){
person.setX(x-30);
barrs_2.setX(x1-30);
}
//
if(e.getKeyCode()==KeyEvent.VK_RIGHT){
person.setX(x+22);
barrs_2.setX(x1+22);
if(x>=GameFrame.WIDTH-Person.WIDTH){//如果人物到了右边界
person.setX(GameFrame.WIDTH-Person.WIDTH);
}
if(x1>=GameFrame.WIDTH-barrs_2.WIDTH){//如果宠物到了右边界
barrs_2.setX(GameFrame.WIDTH - barrs_2.WIDTH);
}
}
//暂停 继续功能
if(e.getKeyCode() == KeyEvent.VK_SPACE){
flag = !flag;
}
}
@Override
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
}
}

View File

@ -0,0 +1,89 @@
package cn.sqc.runday.model;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Paint;
import java.io.File;
import javax.imageio.ImageIO;
import cn.sqc.runday.view.GameFrame;
public class Barrs_1 {
private Image image;
private Image [] images;
public static final int WIDTH=100;
public static final int HEIGHT=110;
private int x,y;
int index;
private int speed;
public Barrs_1() {// 螃蟹
images = new Image[2];
try {
images[0]=ImageIO.read(new File("image/a2.png"));
images[1]=ImageIO.read(new File("image/a4.png"));
} catch (Exception e) {
// TODO: handle exception
}
image = images[0];
x=GameFrame.WIDTH+100;
y=580;
speed =30;
index = 0;
}
public void step() {//切换图片
image =images[index++/5%images.length];
x-=speed;//切换图片实现螃蟹爪子张合的动态效果的同时使其向左移动
}
public void paintBarrs(Graphics g) {
g.drawImage(image, x,y,WIDTH,HEIGHT, null);
}
public boolean outofBounds(){
return this.x <=-WIDTH;
}
public Image getImage() {
return image;
}
public void setImage(Image image) {
this.image = image;
}
public Image[] getImages() {
return images;
}
public void setImages(Image[] images) {
this.images = images;
}
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 getIndex() {
return index;
}
public void setIndex(int index) {
this.index = index;
}
public int getSpeed() {
return speed;
}
public void setSpeed(int speed) {
this.speed = speed;
}
public static int getWidth() {
return WIDTH;
}
public static int getHeight() {
return HEIGHT;
}
}

View File

@ -0,0 +1,91 @@
package cn.sqc.runday.model;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.KeyListener;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import cn.sqc.runday.view.GameFrame;
public class Barrs_2{ // ³èÎ
private Image image;
private Image images [] ;
public static final int WIDTH= 70;
public static final int HEIGHT = 60;
private int x,y;
int index;
public Barrs_2() {
init();
image = images[0];
x=300;
y=460;
}
public void drop() {
y ++;
if(y>=460){
y = 460;
}
}
public void step(){
image = images[index++/2%images.length];
}
public void paintBarrs(Graphics g) {
g.drawImage(image, x,y,WIDTH,HEIGHT, null);
}
public boolean outofBounds() {
return this.x<=-WIDTH;
}
public void init(){
images = new Image[6];
for( int i=0;i<6;i++){
try {
images[i]=ImageIO.read(new File ("Image/"+"d"+(i+1)+".png"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public Image getImage() {
return image;
}
public void setImage(Image image) {
this.image = image;
}
public Image[] getImages() {
return images;
}
public void setImages(Image[] images) {
this.images = images;
}
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 getIndex() {
return index;
}
public void setIndex(int index) {
this.index = index;
}
public static int getWidht() {
return WIDTH;
}
public static int getHeight() {
return HEIGHT;
}
}

View File

@ -0,0 +1,69 @@
package cn.sqc.runday.model;
import java.awt.Graphics;
import java.awt.Image;
import java.io.File;
import javax.imageio.ImageIO;
import cn.sqc.runday.view.GameFrame;
public class Barrs_3 {// µ¼µ¯£¡
private Image image;
private int x,y;
public static final int WIDTH = 150;
public static final int HEIGHT=70;
private int speed;
public Barrs_3() {
try {
image = ImageIO.read(new File("image/daodan.png"));
} catch (Exception e) {
// TODO: handle exception
}
x=GameFrame.WIDTH+1000;
y=450;
speed = 25 ;
}
public void step(){
x-=speed;
}
public void paintBarrs(Graphics g) {
g.drawImage(image, x, y, WIDTH, HEIGHT, null);
}
public boolean outofBounds(){
return this.x<=-WIDTH;
}
public Image getImage() {
return image;
}
public void setImage(Image image) {
this.image = image;
}
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 static int getWidth() {
return WIDTH;
}
public static int getHeight() {
return HEIGHT;
}
}

View File

@ -0,0 +1,75 @@
package cn.sqc.runday.model;
import java.awt.Graphics;
import java.awt.Image;
import java.io.File;
import java.util.Random;
import javax.imageio.ImageIO;
import cn.sqc.runday.view.GameFrame;
public class Barrs_4 {// Óã²æÕϰ­Î
private Image image;
private Image images[];
public static final int WIDTH =150;
public static final int HEIGHT =350;
private int x,y;
public Barrs_4() {//¹¹Ôì·½·¨
Random random = new Random();
images = new Image[4] ;
try {
images[0] = ImageIO.read(new File("image/11.png"));
images[1]= ImageIO.read(new File("image/12.png"));
images[2]= ImageIO.read(new File("image/13.png"));
images[3]= ImageIO.read(new File("image/14.png"));
} catch (Exception e) {
// TODO: handle exception
}
image= images[random.nextInt(4)];
x=GameFrame.WIDTH+1500;
y=0;
}
public void step(){
x-=20;
}
public void paintBarrs(Graphics g){
g.drawImage(image, x, y, WIDTH, HEIGHT, null);
}
public boolean outofBounds(){
return this.x<=-WIDTH;
}
public Image getImage() {
return image;
}
public void setImage(Image image) {
this.image = image;
}
public Image[] getImages() {
return images;
}
public void setImages(Image[] images) {
this.images = images;
}
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 static int getWidth() {
return WIDTH;
}
public static int getHeight() {
return HEIGHT;
}
}

View File

@ -0,0 +1,97 @@
package cn.sqc.runday.model;
import java.awt.Graphics;
import java.awt.Image;
import java.io.File;
import java.io.IOException;
import java.util.Random;
import javax.imageio.ImageIO;
import cn.sqc.runday.view.GameFrame;
/**
* @author Huey
*2020-11-30 下午03:44:51
*金币障碍物类
*
*/
public class Barrs_5 {
private Image image;//当前显示图片
public static final int WIDTH = 30;
public static final int HEIGHT = 30;
private int x,y;
private int speed;
Random random = new Random();
public Barrs_5() {
try {
image = ImageIO.read(new File("Image/"+(random.nextInt(6) + 21) + ".png"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
x = GameFrame.WIDTH + 10;
y = random.nextInt(600);
speed = 20;
}
public void step(){
x -= speed;
}
public void paintBarrs(Graphics g){
g.drawImage(image, x, y, WIDTH, HEIGHT, null);
}
public boolean outofBounds() {
return this.x<=-WIDTH;
}
public Image getImage() {
return image;
}
public void setImage(Image image) {
this.image = image;
}
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 Random getRandom() {
return random;
}
public void setRandom(Random random) {
this.random = random;
}
public static int getWidth() {
return WIDTH;
}
public static int getHeight() {
return HEIGHT;
}
}

View File

@ -0,0 +1,148 @@
package cn.sqc.runday.model;
import java.awt.Graphics;
import java.awt.Image;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import cn.sqc.runday.controller.GamePanel;
import cn.sqc.runday.view.GameFrame;
/**
* @author Huey
* @date 2020-11-23
* 玩家的实体类
*/
public class Person {//1.声明属性
private Image image;//1.1 玩家当前显示图片
private Image[] images;//1.2 玩家所有图片
public static final int WIDTH = 120;//1.3玩家宽高
public static final int HEIGHT = 120;
//1.4玩家初始位置坐标
private int x,y;
int index;//下面用作切换图片
//玩家得分
private int score;
//玩家跑酷距离
private int distance;
//玩家总分
private int totalScore;
public Person() {//2.赋值
//给图片数组images赋值
init();//2.1 先写会提示要不要实现自动生成方法
//默认当前显示图片位第一张图片 2.6
image = images[0];
x = 90;//2.7
y = 580;//脚踩地板
index = 0;
score = 0;
distance = 0;
}
//玩家自由下落方法5.1
public void drop() {
y += 5;
if(y>=580){// 下落归下落也得温柔点不能让小人儿踩破了地板
y = 580;
}
}
//玩家移动的方法
public void step(){
//玩家图片的切换
image = images[index ++ /3%images.length];
//玩家坐标改变玩家坐标通过键盘控制此次不做处理
//玩家跑酷距离计算
distance += 2;
}
//绘制玩家的方法
public void paintPerson(Graphics g){
g.drawImage(image, x, y, WIDTH, HEIGHT, null);
}
//判断玩家是否越界的方法
public boolean outOfBounds(){
return this.x >= GameFrame.WIDTH || this.x <= -WIDTH;
}
private void init() {//2.2
images = new Image[9];
for(int i = 0; i<images.length; i++){//2.3
try {//2.5
images[i] = ImageIO.read(new File("Image/"+(i+1) + ".png"));//2.4
} catch (IOException e) {//2.5
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
//2.8 右键SourceGGAS
public Image getImage() {
return image;
}
public void setImage(Image image) {
this.image = image;
}
public Image[] getImages() {
return images;
}
public void setImages(Image[] images) {
this.images = images;
}
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 static int getWidth() {
return WIDTH;
}
public static int getHeight() {
return HEIGHT;
}
public int getIndex() {
return index;
}
public void setIndex(int index) {
this.index = index;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
public int getDistance() {
return distance;
}
public void setDistance(int distance) {
this.distance = distance;
}
public int getTotalScore() {
return (int) (score * 10 + distance * 0.6);
}
public void setTotalScore(int totalScore) {
this.totalScore = totalScore;
}
}

View File

@ -0,0 +1,120 @@
package cn.sqc.runday.view;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import cn.sqc.runday.controller.GamePanel;
import cn.sqc.runday.model.Person;
public class EndFrame extends JFrame implements MouseListener {
//创建继续游戏按钮返回主菜单按钮退出按钮 组件
JLabel again,back,exit;
public EndFrame(Person person) {
again = new JLabel(new ImageIcon("Image/hh5.png"));
again.setBounds(520, 622, 60, 25);
again.addMouseListener(this);
this.add(again);
back = new JLabel(new ImageIcon("Image/hh6.png"));
back.setBounds(520, 722, 60, 25);
back.addMouseListener(this);
this.add(back);
exit = new JLabel(new ImageIcon("Image/hh3.png"));
exit.setBounds(520, 822, 60, 25);
exit.addMouseListener(this);
this.add(exit);
EndPanel end = new EndPanel(person);
this.add(end);//将结束面板组件添加到结束窗口上
this.setSize(1500, 900);
this.setLocationRelativeTo(null);
this.setUndecorated(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setIconImage(new ImageIcon("Image/115.png").getImage());
this.setVisible(true);
}
public static void main(String[] args) {
//new EndFrame();
}
class EndPanel extends JPanel{
Image background;
Person p;
public EndPanel(Person person) {//类比int a
this.p = person;//创建对象传值
try {
background = ImageIO.read(new File("Image/chou.png"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void paint(Graphics g) {
// TODO Auto-generated method stub
super.paint(g);
g.drawImage(background, 0, 0,1500,900 ,null);
g.setColor(Color.CYAN);
g.setFont(new Font("宋体",Font.BOLD,30));
g.drawString(p.getScore()+"",1110,705);// + 属实妙
g.drawString(p.getDistance() + " ", 1110, 622);
g.setFont(new Font("宋体",Font.BOLD,50));
g.setColor(Color.ORANGE);
g.drawString(p.getTotalScore() + "", 1075, 500);
}
}
@Override
public void mouseClicked(MouseEvent e) {
if(e.getSource().equals(again)){
//跳转到下一界面
new WindowFrame().Start();
//关闭当前界面
dispose();
} else if(e.getSource().equals(back)){
new MainFrame();
dispose();
}else if(e.getSource().equals(exit)){
System.exit(0);
}
}
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
}

View File

@ -0,0 +1,48 @@
package cn.sqc.runday.view;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import cn.sqc.runday.controller.GamePanel;
/**
* @author Huey
*2020-11-27 下午12:40:22
* 游戏主界面显示窗体承载游戏的主面板类
*/
public class GameFrame extends JFrame {
//设置窗体宽高属性
public static final int WIDTH=1500;
public static final int HEIGHT=900;
public GameFrame() {
//2.4创建游戏面板对象并添加到窗体上去
GamePanel panel = new GamePanel();
panel.action();//程序启动的方法
this.addKeyListener(panel);//谁实现就监听谁
this.add(panel);
/**1.设置窗体基本属性*/
this.setSize(WIDTH,HEIGHT);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setIconImage(new ImageIcon("Image/115.png").getImage());
this.setUndecorated(true);
this.setVisible(true);
while(true){
if(panel.isGameOver){//因为isGameOver之前用static修饰,所以报错
dispose();//关闭窗口
}
try {
Thread.sleep(2);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public static void main(String[] args) {
new GameFrame();
}
}

View File

@ -0,0 +1,161 @@
package cn.sqc.runday.view;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
/**
*
* @author Huey
* @date 2020-11-16
* 登录界面用户名输入框 密码输入框 登录取消按钮 功能
*
*/
public class LoginFrame extends JFrame{
//用户名变量文本
JLabel userLabel;
//用户名输入框文本输入框
JTextField userField;
//密码变量文本
JLabel userLabel2;
//密码输入框文本输入框
JPasswordField userField2;
//登录按钮取消按钮按钮
JButton Login,Cancel;
public LoginFrame() {//直接 alt / 无参构造
userLabel = new JLabel("用户名");
//设置字体
userLabel.setFont(new Font("微软雅黑",Font.BOLD,18));
userLabel2 = new JLabel("密 码");
userLabel2.setFont(new Font("微软雅黑",Font.BOLD,18));
//布局方式绝对布局
userLabel.setBounds(20, 220, 100, 30);//x位置y位置所占显示空间的大小
this.add(userLabel);//将用户名这三个字添加到登录界面上以下同理
userLabel2.setBounds(20, 280, 100, 30);
this.add(userLabel2);
//用户名输入框
userField = new JTextField();
userField.setBounds(80, 220, 100, 30);
//设置输入框凹陷效果
userField.setBorder(BorderFactory.createLoweredBevelBorder());
//设置输入框背景透明
userField.setOpaque(false);
this.add(userField);
userField2 = new JPasswordField();
userField2.setBounds(80, 280, 100, 30);
userField2.setBorder(BorderFactory.createLoweredBevelBorder());
userField2.setOpaque(false);
this.add(userField2);
//登录按钮
Login = new JButton("登录");
Login.setBounds(45,350,60,36);
//Login.setBackground(new Color(44,22,44));//背景色
//Login.setForeground(Color.BLUE);//前景色
//绑定登录按钮的事件监听
Login.addActionListener(new ActionListener() {//ActionListener alt /
@Override
public void actionPerformed(ActionEvent e) {
//System.out.println("点击登录按钮");
//获取用户名输入框的内容
String userName = userField.getText();
String passWord = userField2.getText();//横杠原因方法太老了不推荐用
if("Huey".equals(userName) && "123".equals(passWord)){
//登录成功
JOptionPane.showMessageDialog(null, "欢迎"+userName+"来到天天酷跑游戏");
//跳转到下一界面
new MainFrame();
//关闭当前界面
dispose();
}else if("".equals(userName) || "".equals(passWord)){
//不能为空
JOptionPane.showMessageDialog(null, "用户名 / 密码不能为空,请重新输入!");
}else{
JOptionPane.showMessageDialog(null, "用户名 / 密码输入错误,请重新输入!");
}
}
});
this.add(Login);
//取消按钮
Cancel = new JButton("取消");
Cancel.setBounds(135,350,60,36);
this.add(Cancel);
Cancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
dispose();
}
});
//创建背景面板并添加到窗体上去
LoginPanel panel = new LoginPanel();
this.add(panel);
//设置登录界面的基本属性
this.setSize(900,530);
this.setLocationRelativeTo(null);//位置居中
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setUndecorated(true);
//设置窗体的Logo图标
this.setIconImage(new ImageIcon("Image/115.png").getImage());//存储图片
this.setVisible(true);
}
//测试用的main方法 main + Alt /
public static void main(String[] args) {
new LoginFrame();
}
class LoginPanel extends JPanel{//画板
//背景图片变量
Image background;//------ctr shift + o 导包
public LoginPanel() {//-----alt / 回车 构造方法 {后双击,显示作用域
//读取图片文件赋值给background变量
try {//-----虽然不大可能但也做好吃饭噎死的准备
background = ImageIO.read(new File("Image/login.jpg"));//----read参数为File类型
} catch (IOException e) {//-------捕获异常信息
// 打印异常日志信息
e.printStackTrace();
}
}
//绘制方法
@Override
public void paint(Graphics g) {
super.paint(g);
//绘制背景图片
g.drawImage(background, 0, 0,900,530, null);//900,530为宽高
}
}
}
//throws ......抛异常将下面的异常向上抛,交给上级不建议

View File

@ -0,0 +1,155 @@
package cn.sqc.runday.view;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class MainFrame extends JFrame implements MouseListener {
//设置窗体的基本属性 大小
/**
* 1.1设置窗体基本属性大小 居中 边框隐藏 默认关闭按钮 logo图标
1.2创建背景面板MainPanel实现背景图片功能
2.图片按钮功能
*/
//2.1创建开始按钮 帮助按钮 离开按钮 组件
JLabel start,help,exit;
JPanel MainPanel;
public MainFrame() {//无参构造创建对象并在main函数中调用
//2.2
start = new JLabel(new ImageIcon("Image/hh1.png"));//ImageIcon:图标
start.setBounds(350,320,150,40);
start.setEnabled(false);//false按钮为灰色
start.addMouseListener(this);
this.add(start);
help = new JLabel(new ImageIcon("Image/hh2.png"));
help.setBounds(350,420,150,40);
help.setEnabled(false);
help.addMouseListener(this);
this.add(help);
exit = new JLabel(new ImageIcon("Image/hh3.png"));
exit.setBounds(350, 520, 150, 40);
exit.setEnabled(false);
exit.addMouseListener(this);
this.add(exit);
/**1.实现背景图片及窗体属性*/
MainPanel panel = new MainPanel();
this.add(panel);
//设置窗体基本属性大小 居中 边框隐藏 默认关闭按钮 logo图标
this.setSize(1200,730);//大小
this.setLocationRelativeTo(null);//居中
this.setUndecorated(true);//边框隐藏
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//默认关闭
this.setIconImage(new ImageIcon("Image/115.png").getImage());//logo
this.setVisible(true);
}
public static void main(String[] args) {
new MainFrame();
}
//2创建背景面板MainPanel实现背景图片功能
class MainPanel extends JPanel{//创建的MainPanel类在MainFrame中调用
Image background;
public MainPanel() {
try {
background = ImageIO.read(new File("Image/main.png"));
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void paint(Graphics g) {
super.paint(g);
g.drawImage(background, 0, 0,1200,730, null);
}
}
//以下五个方法均为添加 implements MouseListener 快捷出来的
@Override
public void mouseClicked(MouseEvent e) {
//鼠标点击
if(e.getSource().equals(start)){
//跳转到下一界面
new WindowFrame().Start();
//关闭当前界面
//dispose();
}else if(e.getSource().equals(exit)){
dispose();
}else if(e.getSource().equals(help)){
JOptionPane.showMessageDialog(null, "有疑问请联系开发者Huey");
}
}
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseEntered(MouseEvent e) {
// 鼠标移入
if(e.getSource().equals(start)){//e指一个事件e.getSource()获取事件
//如果鼠标移入到start组件图片按钮
start.setEnabled(true);
}else if(e.getSource().equals(help)){
help.setEnabled(true);
}else if(e.getSource().equals(exit)){
exit.setEnabled(true);
}
}
@Override
public void mouseExited(MouseEvent e) {
//鼠标移出
if(e.getSource().equals(start)){
start.setEnabled(false);
}else if(e.getSource().equals(help)){
help.setEnabled(false);
}else if(e.getSource().equals(exit)){
exit.setEnabled(false);
}
}
}

View File

@ -0,0 +1,77 @@
package cn.sqc.runday.view;
import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JProgressBar;
/**
*
* @author Huey
* @date 2020-11-18
* 缓存加载界面:背景图片进度条
* 动态加载过程线程
*
*/
public class WindowFrame extends JFrame implements Runnable{
JLabel background;
//进度条
JProgressBar jdt;
//创建一个线程并启动
public void Start(){
WindowFrame frame = new WindowFrame();
Thread t = new Thread(frame);//t代表线程
//启动线程
t.start();
dispose();
}
public WindowFrame() {
background = new JLabel(new ImageIcon("Image/hbg.jpg"));
this.add(BorderLayout.NORTH,background);//放在窗口上面
jdt = new JProgressBar();
jdt.setStringPainted(true);//加载以字符串形式呈现出来0%
jdt.setBackground(Color.ORANGE);
this.add(BorderLayout.SOUTH,jdt);
//大小 568 * 340
this.setSize(568,340);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(3);
this.setUndecorated(true);
this.setIconImage(new ImageIcon("Image/115.png").getImage());
this.setVisible(true);
}
public static void main(String[] args) {
//new WindowFrame().Start();
}
@Override
public void run() {
//启动线程后线程具体执行的内容
int [] values = {0,1,3,10,11,15,18,23,32,40,47,55,66,76,86,89,95,99,99,99,100};
for(int i=0; i<values.length; i++){//循环遍历赋值
jdt.setValue(values[i]);
//线程休眠
try {
Thread.sleep(200);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}//200毫秒
}
new GameFrame();
dispose();
}
}

View File

@ -0,0 +1,39 @@
一、项目名称《天天酷跑》RunDay
二、功能介绍:
闯关类游戏,玩家登录后,选择进入游戏,通过键盘控制玩家的上下左右移动,来躲避
障碍物和吃金币,玩家躲避的障碍物越多跑酷距离越远,玩家吃的金币越多,得分越高。
三、功能模块:
1、登录界面
用户名(输入框,明文) 密码(输入框,密文) 登录、取消按钮
2、菜单选择界面
开始游戏按钮(图片按钮) 帮助按钮 退出按钮
3、缓冲加载界面
自动加载进度条,加载完毕之后,跳转到下一界面
4、游戏主界面
移动的背景图片、动态的玩家、五种障碍物持续出现、玩家和障碍物的碰撞、
暂停、继续功能、玩家的移动功能
5、结束界面
获取玩家的得分、跑酷距离。继续游戏、返回主菜单的功能。
--------------------------------------------------------------
四、开发者Huey
五、版本号1.0
六、开发时间2020.11.16
开发模式MVC模式
MModel数据层存储的是实体类。
V:View显示层存储的是关于界面的类。
Controller控制层存储的是相关的逻辑层代码。
企业级项目命名规范:
cn.sqc.runday.view