前言:
本篇文章篇幅较长,请根据自己的需求在目录上跳转对应内容哦!源码及实验报告的获取在文章的后面哦!本人代码水平不佳,希望本文章和项目能带给大家帮助!
目录
前言:
一.成果预览:
二.前期准备:
(1)编译器的下载安装
(2)easyX库的下载
三:功能实现
1.test.cpp
2.game.h
3.game.cpp
(1)全局变量
(2)账户界面
(3)注册
(4)登录
(5)图片加载
(6)图形界面按钮设计
(7)游戏菜单
(8)游戏规则
(9)游戏难度菜单
(10)初级难度
(11)中级难度
(12)困难难度
(13)扫雷面板初始化
(14)扫雷面板打印
(15)设置地雷
(16)地雷个数
(17)加密扫雷面板
(18)解密并打印扫雷面板
(19)排除地雷以及重新或退出游戏
(20)判定选中格是否为雷区
(21)胜利界面
(22)失败界面
(23)排行榜写入
(24)排行榜读取
(25)结束游戏
四.下载源码后如何个性化配置及启动运行项目
1.个性化配置
2.启动运行项目
五.源码及实验报告获取
1.实验报告获取
编辑 2.源码获取
一.成果预览:
下面放一些扫雷游戏的最终成果图片:
二.前期准备:
(1)编译器的下载安装
首先请各位最好统一编程工具,我是使用VS2022来完成这一个扫雷游戏的制作的,所以接下来的教学都是以VS2022进行的!如果你使用Dec、小熊猫或者其他编译器 ,可能会有不方便的地方。但是如果你不想换编译器那么也不强求,自己用的习惯就好!
下面是VS编译器的下载安装使用教学:https://www.bilibili.com/video/BV11R4y1s7jz/?spm_id_from=333.337.search-card.all.click
大家可以先去下载安装VS2022编译器
(2)easyX库的下载
本次扫雷游戏是图形界面版的,我们如果想要完成图形界面版的扫雷,那么必须下载easyX库。下载地址如下,请先自行下载!
https://easyx.cn/
下载完成后记得安装到VS2022编译器上
注意在VS内创建的项目必须是.cpp后缀的项目,否则easyX无法正常使用!!!
三:功能实现
这一部分就主要教学扫雷游戏的做法!
代码分为三个模块,分别为test.cpp,game.cpp,test.cpp
这三个模块分别有什么作用呢:
test.cpp: 这部分为代码的主程序,程序从这里开始执行
game.h:这部分为代码函数的声明,在代码中我们用到的函数都需要在这里声明
game.cpp:这部分为代码函数的具体实现内容,在代码中我们的函数操作在这里执行
这三个部分构成了一个完整的扫雷项目,这样做的好处就是能够更有逻辑性的管理我们的项目和代码!
下面我将各部分的代码展示给各位:
1.test.cpp
#define _CRT_SECURE_NO_WARNINGS 1
# include "game.h"
int main()
{mciSendString("open ./卡农.mp3", NULL, 0, NULL); mciSendString("play ./卡农.mp3 repeat", NULL, 0, NULL);srand((unsigned int)time(NULL));user();mciSendString("stop ./卡农.mp3", NULL, 0, NULL);return 0;
}
2.game.h
#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <Windows.h>
#include <string.h>
#include <graphics.h>
#include <conio.h>
#include <Ctype.h>
#include <mmsystem.h>//包含多媒体接口
#pragma comment(lib,"winmm.lib")//处理接口
#define SIZE 35//登录注册页面
void user();//登录
void login();//注册
void enroll();//游戏菜单函数声明
void meau();//游戏规则函数声明
void rule();//游戏难度函数声明
void difficult_meau();//游戏主程序函数声明
void game_easy();
void game_middle();
void game_terrible();//初始化
void Intboard(int arr[32][24],int x, int y);//打印面板
void Printboard(int arr[32][24],IMAGE img[12],int x, int y);//设置地雷
void Setboom(int arr[32][24], int arr1[32][24],int x, int y, int boom_num);//寻找地雷
int Findboom(int arr[32][24],int x,int y);//图形界面按钮文字打印设计
void button(int x, int y, int w, int h, TCHAR* text);//加载图片
void img_load(IMAGE img[15]);//地雷数量
void boom_arround(int arr[32][24],int x,int y);//加密
void password(int arr[32][24], int x, int y);//判定
int judgeboom(int arr[32][24], int i, int j);//直接退出
void ending();//解密打印
void word(int arr[32][24], int arr1[32][24],int x,int y);//胜利判定
void judge_boom_win(int count,int arr[32][24],IMAGE img[12], int x, int y);//失败判定
void judge_boom_def(int count, int arr[32][24], IMAGE img[12], int x, int y);//排行榜写入
void write_rank(int x,int y);//排行榜读取
void read_rank();
3.game.cpp
(1)全局变量
#define _CRT_SECURE_NO_WARNINGS 1
#include "game.h"//全局变量
FILE* fd;
FILE* fp;
FILE* fq;
FILE* fr;
char name_login[20] = { 0 };struct rank
{char name[30];int time;
};struct user
{char name[30];char password[30];
};
struct user read;
struct user write;
clock_t Start_time;
clock_t End_time;
int time_rank;
char str[100];
(2)账户界面
//账户界面
void user()
{IMAGE image1;initgraph(2560, 1440);setorigin(0, 0);loadimage(&image1, "./boom_picture/background.jpg", 1706, 950);putimage(0, 0, &image1);TCHAR s[50] = "1.登录";TCHAR s1[50] = "2.注册";TCHAR s2[50] = "3.退出游戏";button(1100, 300, 170, 50, s);button(1100, 400, 170, 50, s1);button(1100, 500, 170, 50, s2);ExMessage msg;while (1){if ((peekmessage(&msg, EM_MOUSE))){switch (msg.message){case WM_LBUTTONDOWN:if (msg.x >= 1100 && msg.x <= 1100 + 170 && msg.y >= 300 && msg.y <= 300 + 50){login();break;}if (msg.x >= 1100 && msg.x <= 1100 + 170 && msg.y >= 400 && msg.y <= 400 + 50){enroll();break;}if (msg.x >= 1100 && msg.x <= 1100 + 170 && msg.y >= 500 && msg.y <= 500 + 50){ending();break;}}}}
}
(3)注册
void enroll()
{int number = 0;closegraph();fd = fopen("user.txt", "r+");fseek(fd, 0, SEEK_END);InputBox(write.name, 50, "请输入账号", "注册",0,0);InputBox(write.password, 50, "请输入密码", "注册",0,0);number = fwrite(write.name, sizeof(write.name), 1, fd); if (number == 0){MessageBox(0, "账户用户名注册失败,请重试", "Caption", MB_OK);}number = fwrite(write.password, sizeof(write.password), 1, fd); if (number == 0){MessageBox(0, "账户密码注册失败,请重试", "Caption", MB_OK);}fclose(fd);user();
}
(4)登录
//登录
void login()
{closegraph();int number = 0;char password[20] = {0};InputBox(name_login, 50, "请输入用户名", "登录",0,0);InputBox(password, 50, "请输入密码", "登录",0,0);fd = fopen("user.txt", "a+");fseek(fd, 0, SEEK_SET);while (1){number = fread(read.name, sizeof(read.name), 1, fd);if (number == 0){MessageBox(0, "用户名或密码错误,请重试", "error", MB_OK);user();break;}number = fread(read.password, sizeof(read.password), 1, fd);if (number == 0){MessageBox(0, "用户名或密码错误,请重试", "error", MB_OK);user();break;}if (strcmp(name_login, read.name) == 0 && strcmp(password, read.password) == 0){MessageBox(0, "登录成功", "Welcome", MB_OK);fclose(fd);meau();break;}}fclose(fd);
}
(5)图片加载
void img_load(IMAGE img[15])
{loadimage(&img[0], "./boom_picture/0.jpg", 35, 35);loadimage(&img[1], "./boom_picture/1.jpg", 35, 35);loadimage(&img[2], "./boom_picture/2.jpg", 35, 35);loadimage(&img[3], "./boom_picture/3.jpg", 35, 35);loadimage(&img[4], "./boom_picture/4.jpg", 35, 35);loadimage(&img[5], "./boom_picture/5.jpg", 35, 35);loadimage(&img[6], "./boom_picture/6.jpg", 35, 35);loadimage(&img[7], "./boom_picture/7.jpg", 35, 35);loadimage(&img[8], "./boom_picture/8.jpg", 35, 35);loadimage(&img[9], "./boom_picture/9.jpg", 35, 35);loadimage(&img[10], "./boom_picture/10.jpg", 35, 35);loadimage(&img[11], "./boom_picture/flag.jpg", 35, 35);loadimage(&img[12], "./boom_picture/black.jpg", 140, 35);
}
(6)图形界面按钮设计
//图形界面按钮文字打印设计
void button(int x, int y, int w, int h, TCHAR* text)
{setbkmode(TRANSPARENT);setfillcolor(GREEN);fillroundrect(x, y, x + w, y + h, 10, 10);settextstyle(30, 0, "黑体");int tx = x + (w - textwidth(text)) / 2;int ty = y + (h - textheight(text)) / 2;outtextxy(tx, ty, text);
}
(7)游戏菜单
//游戏菜单
void meau()
{closegraph();IMAGE image1;initgraph(2560, 1440);setorigin(0, 0);loadimage(&image1, "./boom_picture/background.jpg",1706,950);putimage(0, 0, &image1);TCHAR s[50] = "1.开始游戏";TCHAR s1[50] = "2.游戏规则";TCHAR s2[50] = "3.退出游戏";TCHAR s3[50] = "4.排行榜";button(1100, 300, 170, 50, s);button(1100, 400, 170, 50, s1);button(1100, 500, 170, 50, s2);button(1100, 600, 170, 50, s3);ExMessage msg;while (1){if (peekmessage(&msg, EM_MOUSE)){switch (msg.message){case WM_LBUTTONDOWN:if (msg.x >= 1100 && msg.x <= 1100 + 170 && msg.y >= 300 && msg.y <= 300 + 50){difficult_meau();meau();break;}if (msg.x >= 1100 && msg.x <= 1100 + 170 && msg.y >= 400 && msg.y <= 400 + 50){rule();meau();break;}if (msg.x >= 1100 && msg.x <= 1100 + 170 && msg.y >= 600 && msg.y <= 600 + 50){read_rank();break;}if (msg.x >= 1100 && msg.x <= 1100 + 170 && msg.y >= 500 && msg.y <= 500 + 50){ending();}}}}
}
(8)游戏规则
//游戏规则
void rule()
{int number = 0;IMAGE image1;initgraph(1706, 1280);setorigin(0, 0);loadimage(&image1, "./boom_picture/background.jpg", 1706, 950);putimage(0, 0, &image1);TCHAR s[80] = "随便点开一个方格根据展开方格的数字去";TCHAR s1[80] = "推断其相邻九宫格内未展开方格下面是否是地雷";TCHAR s2[100] = "最终任务就是点开所有没有地雷的方格,以找出所有的地雷。";TCHAR s3[80] = "注意:如果不小心点到雷,那么游戏结束!";TCHAR s4[50] = "返回";button(1100, 300, 170, 50, s);button(1100, 400, 170, 50, s1);button(1100, 500, 170, 50, s2);button(1100, 600, 170, 50, s3);button(1100, 700, 170, 50, s4);ExMessage msg;while (1){if (peekmessage(&msg, EM_MOUSE)){switch (msg.message){case WM_LBUTTONDOWN:if (msg.x >= 1100 && msg.x <= 1100 + 170 && msg.y >= 700 && msg.y <= 700 + 50){number = 1;closegraph();break;}}if (number == 1){break;}}}
}
(9)游戏难度菜单
//游戏难度菜单
void difficult_meau()
{int number = 0;IMAGE image1;initgraph(1706, 1280);setorigin(0, 0);loadimage(&image1, "./boom_picture/background.jpg", 1706, 950);putimage(0, 0, &image1);TCHAR s[50] = "1.初级";TCHAR s1[50] = "2.中级";TCHAR s2[50] = "3.高级";TCHAR s3[50] = "4.返回";button(1100, 300, 170, 50, s);button(1100, 400, 170, 50, s1);button(1100, 500, 170, 50, s2);button(1100, 600, 170, 50, s3);ExMessage msg;while (1){if ((peekmessage(&msg, EM_MOUSE))){switch (msg.message){case WM_LBUTTONDOWN:if (msg.x >= 1100 && msg.x <= 1100 + 170 && msg.y >= 300 && msg.y <= 300 + 50){number = 1;game_easy();break;}if (msg.x >= 1100 && msg.x <= 1100 + 170 && msg.y >= 400 && msg.y <= 400 + 50){number = 1;game_middle();break;}if (msg.x >= 1100 && msg.x <= 1100 + 170 && msg.y >= 500 && msg.y <= 500 + 50){number = 1;game_terrible();break;}if (msg.x >= 1100 && msg.x <= 1100 + 170 && msg.y >= 600 && msg.y <= 600 + 50){number = 1;closegraph();meau();break;}}if (number == 1){break;}}}
}
(10)初级难度
void game_easy()
{int tran = 1;int arr[11][24];IMAGE img[15];img_load(img);int x = 11;int y = 11;IMAGE image1;initgraph((x-1) * SIZE, (y+5) * SIZE);TCHAR s1[50] = "重新开始";TCHAR s2[50] = "返回";TCHAR s3[50] = "用时:";button(35, 400, 115, 50, s1);button(190, 400, 115, 50, s2);button(65, 500, 110, 50, s3);int boom_num = 10;int arr1[11][24];int count = (x - 1) * (y - 1) - boom_num;Intboard(arr1, x, y);Setboom(arr1,arr, x, y, boom_num);Start_time = clock();while (1){End_time = clock();time_rank = (int)((End_time - Start_time) / CLOCKS_PER_SEC);settextstyle(30, 0, "宋体");setcolor(WHITE);sprintf_s(str, " %d s", time_rank);outtextxy(185, 510, str);//Sleep(1);int change = 0;Printboard(arr1, img, x, y);change = Findboom(arr1,x, y);if (change == 6){count--;tran--;}judge_boom_win(count, arr, img, x, y);if (change == 12){if (tran == 1){Intboard(arr1, x, y);Setboom(arr1,arr, x, y, boom_num);}else{judge_boom_def(count, arr, img, x, y);}}}
}
(11)中级难度
//中级难度
void game_middle()
{int tran = 1;int arr[32][24];IMAGE img[15];img_load(img);int x = 18;int y = 18;IMAGE image1;initgraph((x-1) * SIZE, (y+3) * SIZE);TCHAR s1[50] = "重新开始";TCHAR s2[50] = "返回";TCHAR s3[50] = "用时:";button(35, 630, 115, 50, s1);button(190, 630, 115, 50, s2);button(355, 630, 90, 50, s3);int boom_num = 40;int arr1[18][24];int count = (x - 1) * (y - 1) - boom_num;Intboard(arr1, x, y);Setboom(arr1,arr,x, y, boom_num);Start_time = clock();while (1){End_time = clock();time_rank = (int)((End_time - Start_time) / CLOCKS_PER_SEC);settextstyle(30, 0, "宋体");setcolor(WHITE);sprintf_s(str, " %d s", time_rank);outtextxy(455, 640, str);//Sleep(1);int change = 0;Printboard(arr1, img, x, y);change = Findboom(arr1, x, y);if (change == 6){count--;tran--;}judge_boom_win(count, arr, img, x, y);if (change == 12){if (tran == 1){Intboard(arr1, x, y);Setboom(arr1,arr, x, y, boom_num);}else{judge_boom_def(count, arr, img, x, y);}}}
}
(12)困难难度
//困难难度
void game_terrible()
{int tran = 1;int arr[32][24];IMAGE img[15];img_load(img);int x = 24;int y = 24;IMAGE image1;initgraph((x+5) * SIZE, (y-1) * SIZE);TCHAR s1[50] = "重新开始";TCHAR s2[50] = "返回";TCHAR s3[50] = "用时:";button(840, 35, 115, 50, s1);button(840, 125, 115, 50, s2);button(840, 215, 90, 50, s3);int boom_num = 70;int arr1[24][24];int count = (x - 1) * (y - 1) - boom_num;Intboard(arr1, x, y);Setboom(arr1, arr,x, y, boom_num);Start_time = clock();while (1){End_time = clock();time_rank = (int)((End_time - Start_time) / CLOCKS_PER_SEC);settextstyle(30, 0, "宋体");setcolor(WHITE);sprintf_s(str, " %d s", time_rank);outtextxy(840, 310, str);// Sleep(1);int change = 0;Printboard(arr1, img, x, y);change = Findboom(arr1,x, y);if (change == 6){count--;tran--;}judge_boom_win(count, arr, img, x, y);if (change == 12){//如果第一次踩到雷,那么直接重开一局if (tran == 1){Intboard(arr1, x, y);Setboom(arr1,arr,x, y, boom_num);}//反之如果不是在第一次踩到雷,那么游戏结束else{judge_boom_def(count, arr, img, x, y);}}}
}
(13)扫雷面板初始化
//初始化
void Intboard(int arr[32][24],int x, int y)
{int i = 0;int j = 0;for (i = 0; i < x; i++){for (j = 0; j < y; j++){arr[i][j] = 0;}}
}
(14)扫雷面板打印
//打印扫雷面板
void Printboard(int arr[32][24],IMAGE img[12],int x, int y)
{int i = 0;int j = 0;for (i = 0; i < x; i++){for (j = 0; j < y; j++){if (arr[i][j] == -1){putimage((i - 1) * SIZE, (j - 1) * SIZE, &img[9]);}else if (arr[i][j] >= 0 && arr[i][j] <= 8){putimage((i - 1) * SIZE, (j - 1) * SIZE, &img[arr[i][j]]);}else if (arr[i][j] >= 19 && arr[i][j] <= 28){putimage((i - 1) * SIZE, (j - 1) * SIZE, &img[10]);}else if (arr[i][j] > 30){putimage((i - 1) * SIZE, (j - 1) * SIZE, &img[11]);}}}if (x == 11 && y == 11){putimage(185, 510, &img[12]);}if (x == 18 && y == 18){putimage(455, 640, &img[12]);}if (x == 24 && y == 24){putimage(840, 310, &img[12]);}
}
(15)设置地雷
//设置地雷
void Setboom(int arr[32][24],int arr1[32][24],int x, int y, int boom_num)
{while (boom_num){int i = (rand() % (x - 2)) + 1;int j = (rand() % (y - 2)) + 1;if (arr[i][j] == 0){arr[i][j] = -1;boom_arround(arr, i, j);boom_num--;}}word(arr1, arr, x, y);password(arr, x, y);
}
(16)地雷个数
//地雷个数
void boom_arround(int arr[32][24], int x, int y)
{int i = 0;int j = 0;for (i = x - 1; i <= x + 1; i++){for (j = y - 1; j <= y + 1; j++){if (i != x || j != y){arr[i][j] = arr[i][j] + 1;}}}
}
(17)加密扫雷面板
//加密
void password(int arr[32][24], int x, int y)
{int i = 0;int j = 0;for (i = 0; i < x; i++){for (j = 0; j < y; j++){arr[i][j] = arr[i][j] + 20;}}
}
(18)解密并打印扫雷面板
//解密打印
void word(int arr[32][24], int arr1[32][24], int x, int y)
{int i = 0;int j = 0;for (i = 0; i < x; i++){for (j = 0; j < y; j++){arr[i][j] = arr1[i][j];}}
}
(19)排除地雷以及重新或退出游戏
//排除地雷以及重新游戏退出游戏
int Findboom(int arr[32][24],int x,int y)
{int change = 0;if (MouseHit()){MOUSEMSG msg = GetMouseMsg();int i = (msg.x) / SIZE + 1;int j = (msg.y) / SIZE + 1;int m = arr[i][j];switch (msg.uMsg){case WM_LBUTTONDOWN:if (x == 11 && y == 11){if (msg.x >= 35 && msg.x <= 35 + 115 && msg.y >= 400 && msg.y <= 400 + 50){difficult_meau();break;}if (msg.x >= 190 && msg.x <= 190 + 115 && msg.y >= 400 && msg.y <= 400 + 50){meau();}}if (x == 18 && y == 18){if (msg.x >= 35 && msg.x <= 35 + 115 && msg.y >= 630 && msg.y <= 630 + 50){difficult_meau();break;}if (msg.x >= 190 && msg.x <= 190 + 115 && msg.y >= 630 && msg.y <= 630 + 50){meau();}}if (x == 24 && y == 24){if (msg.x >= 840 && msg.x <= 840 + 115 && msg.y >= 35 && msg.y <= 35 + 50){difficult_meau();break;}if (msg.x >= 840 && msg.x <= 840 + 115 && msg.y >= 125 && msg.y <= 125 + 50){meau();}}if (m >= 19 && m <= 48){arr[i][j] = arr[i][j] - 20;change = 1;}break;case WM_RBUTTONDOWN:if (m >= 19 && m <= 28){arr[i][j] = arr[i][j] + 20;change = 1;}break;}if (change == 1){change = judgeboom(arr,i, j);return change;}}}
(20)判定选中格是否为雷区
//判定
int judgeboom(int arr[32][24],int i,int j)
{if (arr[i][j] >= 0 && arr[i][j] <= 9){return 6;}if (arr[i][j] == -1){return 12;}
}
(21)胜利界面
//胜利界面
void judge_boom_win(int count,int arr[32][24],IMAGE img[12],int x,int y)
{if (count == 0){closegraph();IMAGE imge;initgraph(x * SIZE, y * SIZE);Printboard(arr, img, x, y);initgraph(1706, 1280);setorigin(0, 0);IMAGE image1;loadimage(&image1, "./boom_picture/background.jpg", 1706, 950);putimage(0, 0, &image1);TCHAR s[80] = "游戏胜利!";TCHAR s1[50] = "再来一局";TCHAR s2[50] = "返回";TCHAR s3[50] = "用时:";TCHAR s4[30] = "排行榜";TCHAR s5[30];button(1100, 300, 170, 50, s);button(1100, 400, 170, 50, s1);button(1100, 500, 170, 50, s2);button(1100, 600, 170, 50, s3);button(1100, 700, 170, 50, s4);sprintf_s(s5, " %d s", time_rank);button(1300, 600, 170, 50, s5);write_rank(x,y);ExMessage msg;while (1){if (peekmessage(&msg, EM_MOUSE)){switch (msg.message){case WM_LBUTTONDOWN:if (msg.x >= 1100 && msg.x <= 1100 + 170 && msg.y >= 400 && msg.y <= 400 + 50){difficult_meau();break;}if (msg.x >= 1100 && msg.x <= 1100 + 170 && msg.y >= 500 && msg.y <= 500 + 50){meau();break;}if (msg.x >= 1100 && msg.x <= 1100 + 170 && msg.y >= 600 && msg.y <= 600 + 50){closegraph();Printboard(arr,img,x,y);break;}if (msg.x >= 1100 && msg.x <= 1100 + 170 && msg.y >= 700 && msg.y <= 700 + 50){read_rank();break;}}}}}
}
(22)失败界面
//失败界面
void judge_boom_def(int count, int arr[32][24], IMAGE img[12], int x, int y)
{int number = 0;initgraph(1706, 1280);setorigin(0, 0);IMAGE image1;loadimage(&image1, "./boom_picture/background.jpg", 1706, 950);putimage(0, 0, &image1);IMAGE image2;Printboard(arr, img, x, y);TCHAR s[80] = "你碰到了雷,游戏失败!";TCHAR s1[50] = "再来一局";TCHAR s2[50] = "返回";TCHAR s3[30] = "排行榜";button(1100, 300, 170, 50, s);button(1100, 400, 170, 50, s1);button(1100, 500, 170, 50, s2);button(1100, 600, 170, 50, s3);ExMessage msg;while (1){if (peekmessage(&msg, EM_MOUSE)){switch (msg.message){case WM_LBUTTONDOWN:if (msg.x >= 1100 && msg.x <= 1100 + 170 && msg.y >= 400 && msg.y <= 400 + 50){difficult_meau();break;}if (msg.x >= 1100 && msg.x <= 1100 + 170 && msg.y >= 500 && msg.y <= 500 + 50){meau();break;}if (msg.x >= 1100 && msg.x <= 1100 + 170 && msg.y >= 600 && msg.y <= 600 + 50){read_rank();break;}}}}
}
(23)排行榜写入
//排行榜写入
void write_rank(int x,int y)
{struct rank tmp;char ch[10] = "---------";if (x == 11 && y == 11){fp = fopen("rank.txt", "r+");fscanf(fp, "%s %d", &tmp.name, &tmp.time);if (time_rank < tmp.time){rewind(fp);fprintf(fp, "%s %d %s", name_login, time_rank, ch);}fclose(fp);}if (x == 18 && y == 18){fq = fopen("rank_middle.txt", "r+");fscanf(fq, "%s %d", &tmp.name, &tmp.time);if (time_rank < tmp.time){rewind(fq);fprintf(fq, "%s %d %s", name_login, time_rank, ch);}fclose(fq);}if (x == 24 && y == 24){fr = fopen("rank_terrible.txt", "r+");fscanf(fr, "%s %d", &tmp.name, &tmp.time);if (time_rank < tmp.time){rewind(fr);fprintf(fr, "%s %d %s", name_login, time_rank, ch);}fclose(fr);}
}
(24)排行榜读取
//排行榜读取
void read_rank()
{closegraph();IMAGE image1;initgraph(2560, 1440);setorigin(0, 0);loadimage(&image1, "./boom_picture/background.jpg", 1706, 950);putimage(0, 0, &image1);TCHAR s[30] = "游戏排行榜";TCHAR s1[30] = "初级TOP1:";TCHAR s2[30] = "中级TOP1:";TCHAR s3[30] = "高级TOP1:";TCHAR s4[30] = "用户名";TCHAR s5[30] = "用时";TCHAR s6[30];TCHAR s7[30];TCHAR s8[30];TCHAR s9[30];TCHAR s10[30];TCHAR s11[30];TCHAR s12[30] = "返回";button(1100, 50, 150, 50, s);button(600, 250, 150, 50, s1);button(600, 450, 150, 50, s2);button(600, 650, 150, 50, s3);button(850, 150, 150, 50, s4);button(1350, 150, 150, 50, s5);button(1100, 750, 150, 50, s12);struct rank tmp[4];fp = fopen("rank.txt", "r");fscanf(fp, "%s %d", &tmp[0].name, &tmp[0].time);fq = fopen("rank_middle.txt", "r");fscanf(fq, "%s %d", &tmp[1].name, &tmp[1].time);fr = fopen("rank_terrible.txt", "r");fscanf(fr, "%s %d", &tmp[2].name, &tmp[2].time);strcpy(s6, tmp[0].name);strcpy(s8, tmp[1].name);strcpy(s10, tmp[2].name);sprintf_s(s7, " %d s", tmp[0].time);sprintf_s(s9, " %d s", tmp[1].time);sprintf_s(s11, " %d s", tmp[2].time);button(850, 250, 150, 50, s6);button(1350, 250, 150, 50, s7);button(850, 450, 150, 50, s8);button(1350, 450, 150, 50, s9);button(850, 650, 150, 50, s10);button(1350, 650, 150, 50, s11);ExMessage msg;while (1){if (peekmessage(&msg, EM_MOUSE)){switch (msg.message){case WM_LBUTTONDOWN:if (msg.x >= 1100 && msg.x <= 1100 + 150 && msg.y >= 750 && msg.y <= 750 + 50){meau();break;}}}}fclose(fp);fclose(fq);fclose(fr);
}
(25)结束游戏
//直接结束
void ending(){closegraph();exit(5181);}
四.下载源码后如何个性化配置及启动运行项目
1.个性化配置
我们首先进入源码文件的这个目录下,大家可以看见项目所用的一些图片
大家如果想更换这些图片,就将新的图片放入该文件夹中,随后改成原文件的对应名字即可!!
如果想更换背景音乐,那么进入这个目录下
随后在test.cpp中,更改自己新加入音乐的名字或地址即可
2.启动运行项目
首先下载并打开VS
选择打开本地文件夹,随后选中源码文件中的game_mine.sln即可打开
随后点击调试,在点击开始执行即可运行程序
五.源码及实验报告获取
1.实验报告获取
本实验报告为该项目配套文档,内容包括设计目的、设计内容与要求、设计思路、实验过程、结论与改进五大部分内容!!!本实验报告共计8700余字,共23页文档内容。实验报告的内容图文并茂,内含大量思维导图及流程图,并且已排版到位!在实验报告中,项目的各个模块都有详细说明和介绍,是作者下足心血和功夫编写的配套实验报告!!!下面是配套实验报告的部分内容截图,想获取完整的实验报告文档原件,请加wx:zck2020090062获取!!!
2.源码获取
话不多说,直接给大家分享出来源码,希望对大家有所帮助!需要实验报告的请加wx:zck2020090062获取!!!上面有配套实验报告的介绍和部分内容截图,需要的小伙伴记得加wx获取哦!!!
通过网盘分享的文件:game_mine
链接: https://pan.baidu.com/s/1wnEvZ1Cy8eHPBtvqjxR6oQ?pwd=qing 提取码: qing