赞
踩
小时候都玩过推箱子这个经典的小游戏,它伴随着我们的童年,带给我们了许多的乐趣。今天呢小编为大家分享一下使用C语言来完成推箱子游戏。以及如何将游戏与数据库连接和项目的打包发布。
下面是完成之后的效果展示:
①项目打包后我们会获得一个安装程序,点击安装程序就能将推箱子游戏安装在电脑上。这时候也可以将安装程序发给朋友安装试玩(因为时间原因没有做登录页面)
②游戏内效果,一共设计了四种地图,感兴趣的朋友可以继续在自己的数据库中添加地图。
下面我按照 推箱子游戏实现 → 数据库连接 → 程序打包 的路线分享本次项目
游戏图片下载(将图片与代码放在同一文件夹下)。图片下载https://download.csdn.net/download/qq_54169998/81551789这里为分享的源码是以文档做数据结构。下面我会介绍与MySQL相连
- #include<graphics.h>
- #include<iostream>
- #include<stdlib.h>
- #include<string>
- #include<conio.h>
- #include<fstream>
- #include<sstream>
- using namespace std;
-
- #define LINE 48
- #define COLUMN 48
-
- #define RATIO 40
- #define SCREEN_WIDTH 740
- #define SCREEN_HEIGHT 500
-
- #define START_X 50
- #define START_Y 75
-
- #define KEY_UP 'W'
- #define KEY_LEFT 'A'
- #define KEY_RIGHT 'D'
- #define KEY_DOWN 'S'
- #define KEY_OUT 'Q'
- #define GAME_AGAIN 'R'
-
- #define MAX_RETRY_TIMES 4
- #define BG_IMAGE -1
- #define isValid(next_pos) next_pos.x > 0 && next_pos.x < LINE && next_pos.y>0 && next_pos.y < COLUMN
-
- #define USERS "users.txt"
- #define LEVELS "levels.txt"
- #define ROUND 4
-
- typedef enum _PROPS {
- WALL, //墙
- FLOOR, //地板
- BOX_DES,//箱子目的地
- MAN, //小人
- BOX, //箱子
- HIT, //箱子命中目标
- MAN_DES, //人站在目标上
- VECTOR //通关图片
- }PROPS;
-
- typedef enum _DIRECTION {
- UP,
- DOWN,
- LEFT,
- RIGHT
- }DIRECTION;
-
- typedef struct _POS {
- int x; //小人所在二维数组的行数
- int y; //小人所在二维数组的列数
- }POS;
-
- typedef struct _userinfo {
- //这里将字符串初始为空
- _userinfo() :id(0), username(""), password(""), level_id(0) {};
- _userinfo(int _id, string _username, string _password, int _level_id) :id(_id), username(_username), password(_password), level_id(_level_id) {};
- int id; // 用户id
- string username;
- string password; // 密码
- int level_id;
- }userinfo;
-
- typedef struct _levelinfo {
- _levelinfo() :id(0), name(""), map_row(0), map_column(0), map_data(""), next_level(0) {};
- _levelinfo(int _id, string _name, int _map_row, int _map_column, string _map_data, int _next_level) :id(_id), name(_name), map_row(_map_row), map_column(_map_column), map_data(_map_data), next_level(_next_level) {};
- int id; // 关卡id
- string name; // 关卡名字
- int map_row; // 地图行数
- int map_column; //地图列数
- string map_data; // 二维地图数据
- int next_level; //下一关卡id
- }levelinfo;
-
- levelinfo game_data[4];
- struct _POS man;
- IMAGE images[9];
- int map[LINE][COLUMN] = { 0 };
-
- /******************************
- * 功能:数据重置,当数据文档错乱时可调用此函数一次将数据重装
- * 输入:
- * 无
- *
- * 返回值:
- * 无
- *****************************/
- void resetting_data() {
- levelinfo levels[ROUND] = { {1,"小试牛刀→第一关",8,10,"-1,0,0,0,0,0,0,0,-1,-1|-1,0,2,2,2,2,1,0,-1,-1|0,0,0,2,2,2,4,0,0,0|0,1,1,4,0,4,1,4,1,0|0,1,4,4,1,1,0,4,1,0|0,1,1,1,3,0,1,1,1,0|0,0,0,0,1,1,1,0,0,0,|-1,-1,-1,0,0,0,0,0,-1,-1",2},
- {2,"绝地强者→第二关",6,6,"0,0,0,0,0,0|0,2,2,1,1,0|0,4,4,1,3,0|0,2,1,4,0,0|0,1,1,1,0,-1|0,0,0,0,0,-1",3},
- {3,"天外强人→第三关",8,10,"-1,-1,0,0,0,0,0,0,-1,-1|0,0,0,1,1,1,0,0,0,0|0,1,1,1,4,1,4,1,1,0|0,1,4,1,1,1,4,1,3,0|0,0,0,4,4,0,0,0,0,0,|-1,-1,0,1,1,2,2,0,-1,-1|-1,-1,0,2,2,2,2,0,-1,-1|-1,-1,0,0,0,0,0,0,-1,-1",4},
- {4,"死而复生→BOSS关",8,8,"-1,0,0,0,0,0,0,-1|-1,0,2,1,2,2,0,-1|-1,0,2,1,4,2,0,-1|0,0,0,1,1,4,0,0|0,1,4,1,1,4,1,0|0,1,0,4,0,0,1,0|0,1,1,1,3,1,1,0|0,0,0,0,0,0,0,0",0}
- };
- ofstream ofs;
- ofs.open(LEVELS, ios::out);
- for (int i = 0; i < ROUND; ++i) {
- stringstream str_stream;
- str_stream << levels[i].id << " " << levels[i].name << " " << levels[i].map_row << " " << levels[i].map_column << " " << levels[i].map_data << " " << levels[i].next_level << endl;
- ofs << str_stream.str();
- }
- ofs.close();
- ofs.open(USERS, ios::out);
- userinfo user = { 1,"Jack","123456" ,1 };
- stringstream str;
- str << user.id << " " << user.username << " " << user.password << " " << user.level_id;
- ofs << str.str();
- ofs.close();
- }
-
- /******************************
- * 功能:地图数据加载
- * 输入:
- * 无
- *
- * 返回值:
- * 无
- *****************************/
- void load_data() {
- ifstream ifs;
- ifs.open(LEVELS);
- int index = 0;
- while (index < ROUND) {
- string line;
- getline(ifs, line);
- //cout << line << endl;
- int _id;
- char _name[64];
- int _map_row;
- int _map_column;
- char _map_data[2304];
- int _next_level_id;
- levelinfo info;
- sscanf_s(line.c_str(), "%d %s %d %d %s %d", &_id, _name, (unsigned int)sizeof(_name), &_map_row, &_map_column, _map_data, (unsigned int)sizeof(_map_data), &_next_level_id);
- game_data[index] = { _id,_name,_map_row,_map_column,_map_data,_next_level_id };
- index++;
- }
- }
-
-
- /******************************
- *功能:通过用户名和密码获取用户信息
- * 输入:
- * user - 用户信息结构体
- *
- * 返回值:
- * 获取成功返回true,失败false
- *****************************/
- bool fetch_user_info(userinfo& user) {
- ifstream ifs;
- ifs.open(USERS);
- if (!ifs) {
- return false;
- }
- string line;
- while (1) {
- getline(ifs, line);
- int _id;
- char _username[64];
- char _password[64];
- int _level_id;
- sscanf_s(line.c_str(), "%d%s%s%d", &_id, _username, (unsigned int)sizeof(_username), _password, (unsigned int)sizeof(_password), &_level_id);
- if (_username == user.username && _password == user.password) {
- user.id = _id;
- user.level_id = _level_id;
- return true;
- }
- if (ifs.eof()) {
- break;
- }
- }
- return false;
- }
-
- /*********************************
- *功能:根据关卡id获取完整的关卡信息(如:地图,下一关等)
- * 输入:
- * level - 保存关卡信息的结构体
- * level_id - 获取关卡id
- * 返回值:
- * 0 - 查找结果为空(用户已通关)
- * 1 - 查找成功
- *********************************/
- bool fetch_level_info(levelinfo& level, int level_id) {
- if (level_id == 0) {
- return false;
- }
- else {
- level = game_data[level_id - 1];
- return true;
- }
- }
-
- /******************************
- *功能:将获得的关卡数据转换到map地图数组中
- * 输入:
- * level - 关卡数据
- * map - 二维地图数组
- *
- * 返回值:
- * false - 转换失败
- * true - 转换成功
- *****************************/
- bool transform_map_db2array(levelinfo& level, int map[][COLUMN]) {
- if (level.map_row > LINE || level.map_column > COLUMN) {
- printf("地图过大,请重新设置\n");
- return false;
- }
- if (level.map_data.length() < 1) {
- printf("地图数据有误,请重新设置!\n");
- return false;
- }
- long long start = 0, end = 0;
- int row = 0, column = 0;
- do {
- /******************************
- *find返回size_t类型值,size_t在64位下是8字节长度,因此这里把start和end设置成long long类型(不设置会有“数据丢失”警告)。当然也可以简单粗暴的修改警告设置
- ******************************/
- end = level.map_data.find('|', start);
- if (end == -1) {
- end = level.map_data.length();
- }
- //合法性检查,结束时end=level.map_data.length,start=end+1
- if (start >= end)
- break;
- string line = level.map_data.substr(start, end - start);
- // 对行数据进行解析:0,1,0,1,1,1,1,1,1,1,0,0
- char* next_token = NULL;
- //line转为const char*(C语言中的字符串),strtok_s会修改line里的值,按照某个特定字符,所以需要将line.c_str()转为char *
- // strtok_s第一个参数是要劈开的字符串(要求是一个char *类型的);第二个参数是按某个字符劈开(会把“,”逗号变成‘\0’结束符,也就是说会修改原来字符串,所以要把原来的const char*转为char*);第三个参数是这个接口
- // 需要的,用来做定位功能,
- char* item = strtok_s((char*)line.c_str(), ",", &next_token);
- column = 0;
- //printf("%p", next_token);
- //::system("pause");
- //如果某行数据个数多余这个地图列数,控制只读取level.map_column-1个
- while (item && column < level.map_column) {
- map[row][column] = atoi(item);
- column++;
- //再使用strtok_s接口第一个参数可以写NULL,应该是next_token参数上一次做定位功能时已经记录了要劈开字符串给的某个位置
- item = strtok_s(NULL, ",", &next_token);
- }
- //合法性检查
- if (column < level.map_column) { // 某行的数据个数小于这个地图的列数
- printf("地图数据解析出错,终止!\n");
- return false;
- }
- row++;
-
- //列数多余的话直接舍弃
- if (row >= level.map_row) {
- break;
- }
- start = end + 1;
- } while (1 == 1);
- //列数多余则直接报错
- if (row < level.map_row) {
- printf("地图行数少于设定,终止!");
- return false;
- }
- return true;
- }
-
- /******************************
- *功能:更新用户游戏进度信息
- * 输入:
- * user - 用户信息
- * next_level_id - 游戏进度
- *
- * 返回值:
- * 获取成功返回true,失败false
- *****************************/
- bool update_user_level(userinfo& user, int next_level_id) {
- ifstream ifs;
- ifs.open(USERS);
- if (!ifs) {
- return false;
- }
- int user_index = 1;
- string strFileData = "";
- while (1) {
- if (user_index == user.id) {
- {string temp;
- getline(ifs, temp); }
- user_index++;
- continue;
- }
- if (ifs.eof()) {
- break;
- }
- string line;
- getline(ifs, line);
- strFileData += line;
- strFileData += '\n';
-
- }
- ifs.close();
- stringstream str_stream;
- str_stream << user.id << " " << user.username << " " << user.password << " " << next_level_id << endl;
- strFileData += str_stream.str();
- ofstream ofs;
- ofs.open(USERS);
- ofs.flush();
- ofs << strFileData;
- ofs.close();
- user.level_id = next_level_id;
- return true;
- }
-
- /*****************************
- * 功能:判断游戏是否结束
- * 输入:
- * 无
- * 输出:
- * true - 未结束
- * flase - 结束
- *****************************/
- bool isGameOver() {
- for (int i = 0; i < LINE; ++i) {
- for (int j = 0; j < COLUMN; ++j) {
- if (map[i][j] == BOX_DES)
- return false;
- }
- }
- return true;
- }
-
- /*****************************
- * 功能:加载游戏结束图片
- * 输入:
- * 无
- * 输出:
- * 无
- *****************************/
- void show_over() {
- cleardevice();
- IMAGE game_over;
- loadimage(&game_over, _T("gameover.png"), SCREEN_WIDTH, SCREEN_HEIGHT, true);
- putimage(0, 0, &game_over);
- }
-
- /*****************************
- * 功能:在指定位置更改地图信息 显示指定图片
- * 输入:
- * next_pos - 指定位置
- * prop - 指定图片
- * 输出:
- * 无
- *****************************/
- void changeMap(POS* next_pos, PROPS prop) {
- map[next_pos->x][next_pos->y] = prop;
- putimage(START_X + next_pos->y * RATIO, START_Y + next_pos->x * RATIO, &images[prop]);
- }
-
- /*****************************
- * 功能:在指定位置显示指定图片
- * 输入:
- * next_pos - 指定位置
- * prop - 指定图片
- * 输出:
- * 无
- *****************************/
- void changeMap2(POS* next_pos, PROPS prop) {
- putimage(START_X + next_pos->y * RATIO, START_Y + next_pos->x * RATIO, &images[prop]);
- }
-
- /*****************************
- * 功能:控制小人向指定方向移动
- * 输入:
- * direct - 指定方向
- * 输出:
- * 无
- *****************************/
- void gameControl(DIRECTION direct) {
- POS next_pos = man;
- POS next_next_pos = man;
- switch (direct) {
- case UP:
- next_pos.x--;
- next_next_pos.x -= 2;
- break;
- case DOWN:
- next_pos.x++;
- next_next_pos.x += 2;
- break;
- case LEFT:
- next_pos.y--;
- next_next_pos.y -= 2;
- break;
- case RIGHT:
- next_pos.y++;
- next_next_pos.y += 2;
- break;
- }
- //宏展开next_pos.x > 0 && next_pos.x < LINE && next_pos.y>0 && next_pos.y < COLUMN
- // 人的前方是地板
- if (isValid(next_pos) && map[next_pos.x][next_pos.y] == FLOOR) {
- //人的脚下是目的地
- if (map[man.x][man.y] == BOX_DES) {
- changeMap(&next_pos, MAN);
- changeMap2(&man, BOX_DES);
- }
- else {
- changeMap(&man, FLOOR);
- changeMap(&next_pos, MAN);
- }
- man = next_pos;
- }
- // 人的前方是箱子
- else if (isValid(next_next_pos) && map[next_pos.x][next_pos.y] == BOX) {
- if (map[next_next_pos.x][next_next_pos.y] == FLOOR) { // 箱子的前方是地板
- changeMap(&next_next_pos, BOX);
- changeMap(&next_pos, MAN);
- if (map[man.x][man.y] == BOX_DES) {
- changeMap(&man, BOX_DES);
- }
- else {
- changeMap(&man, FLOOR);
- }
- man = next_pos;
- }
- else if (map[next_next_pos.x][next_next_pos.y] == BOX_DES) { // 箱子前面是目的地
- changeMap(&next_next_pos, HIT);
- changeMap(&next_pos, MAN);
- if (map[man.x][man.y] == BOX_DES) {
- changeMap(&man, BOX_DES);
- }
- else {
- changeMap(&man, FLOOR);
- }
- man = next_pos;
- }
- }
- //前方是目的地
- else if (isValid(next_pos) && map[next_pos.x][next_pos.y] == BOX_DES) {
- //小人脚下也是目的地
- if (map[man.x][man.y] == BOX_DES) {
- changeMap2(&next_pos, MAN_DES);
- changeMap(&man, BOX_DES);
- }
- else {
- changeMap(&man, FLOOR);
- changeMap2(&next_pos, MAN_DES);
-
- }
- man = next_pos;
- }
- //前方是箱子命中点
- else if (isValid(next_pos) && map[next_pos.x][next_pos.y] == HIT) {
- if (map[next_next_pos.x][next_next_pos.y] == FLOOR) { // 箱子的前方是地板
- changeMap(&next_next_pos, BOX);
- changeMap(&next_pos, BOX_DES);
- changeMap2(&next_pos, MAN_DES);
- //人的脚下是目的地
- if (map[man.x][man.y] == BOX_DES) {
- changeMap(&man, BOX_DES);
- }
- else {
- changeMap(&man, FLOOR);
- }
- man = next_pos;
- }
- else if (map[next_next_pos.x][next_next_pos.y] == BOX_DES) { // 箱子前面是目的地
- changeMap(&next_next_pos, HIT);
- changeMap(&next_pos, BOX_DES);
- changeMap2(&next_pos, MAN_DES);
- //人的脚下是目的地
- if (map[man.x][man.y] == BOX_DES) {
- changeMap(&man, BOX_DES);
- }
- else {
- changeMap(&man, FLOOR);
- }
- man = next_pos;
- }
- }
- }
-
- /*****************************
- * 功能:用户登录
- * 输入:
- * user - 用户信息
- * 输出:
- * false - 登录失败
- * true - 登录成功
- *****************************/
- bool login(userinfo& user) {
- int times = 0;
- bool ret = false;
- do {
- cout << "请输入用户名:";
- cin >> user.username;
- cout << "请输入密码:";
- cin >> user.password;
- ret = fetch_user_info(user);
- times++;
- if (times >= MAX_RETRY_TIMES)
- break;
- if (ret == false) {
- cout << "登录失败,请重新输入!" << endl;
- }
- } while (!ret);
- return ret;
- }
-
- /*****************************
- * 功能:加载游戏素材
- * 输入:
- * 无
- * 输出:
- * 无
- *****************************/
- void init_graph() {
- initgraph(SCREEN_WIDTH, SCREEN_HEIGHT);
- loadimage(&images[WALL], _T("wall_right.bmp"), RATIO, RATIO, true);
- loadimage(&images[FLOOR], _T("floor.bmp"), RATIO, RATIO, true);
- loadimage(&images[BOX_DES], _T("des.bmp"), RATIO, RATIO, true);
- loadimage(&images[MAN], _T("man.bmp"), RATIO, RATIO, true);
- loadimage(&images[BOX], _T("box.jpg"), RATIO, RATIO, true);
- loadimage(&images[HIT], _T("box_des.jpg"), RATIO, RATIO, true);
- loadimage(&images[MAN_DES], _T("man_des.bmp"), RATIO, RATIO, true);
- loadimage(&images[VECTOR], _T("vector.png"), 6 * RATIO, 6 * RATIO, true);
- }
-
- /*****************************
- * 功能:显示指定地图
- * 输入:
- * level - 指定地图
- * 输出:
- * 无
- *****************************/
- void show_images(levelinfo& level) {
- cleardevice(); // 每次贴图清屏一下
- IMAGE bg_img;
- //图片的宽,高最后一个参数“是否拉伸”
- loadimage(&bg_img, _T("bgimage.png"), SCREEN_WIDTH, SCREEN_HEIGHT, true);
- putimage(0, 0, &bg_img);
- for (int i = 0; i < level.map_row; ++i) {
- for (int j = 0; j < level.map_column; ++j) {
- if (map[i][j] == MAN) {
- man.x = i;
- man.y = j;
- }
- if (map[i][j] == BG_IMAGE)
- continue;
- putimage(START_X + j * RATIO, START_Y + i * RATIO, &images[map[i][j]]);
- }
- }
- const char* str = level.name.c_str();
- setbkmode(TRANSPARENT);
- setfont(RATIO, 0, _T("华文楷体"));
- setcolor(WHITE);
- outtextxy(200, 25, str);
- }
-
- /*****************************
- * 功能:载入PNG图并去透明部分
- * 输入:
- * 无
- * 输出:
- * 无
- *****************************/
- void drawAlpha(IMAGE* picture, int picture_x, int picture_y) //x为载入图片的X坐标,y为Y坐标
- {
- // 变量初始化
- DWORD* dst = GetImageBuffer(); // GetImageBuffer()函数,用于获取绘图设备的显存指针,EASYX自带
- DWORD* draw = GetImageBuffer();
- DWORD* src = GetImageBuffer(picture); //获取picture的显存指针
- int picture_width = picture->getwidth(); //获取picture的宽度,EASYX自带
- int picture_height = picture->getheight(); //获取picture的高度,EASYX自带
- int graphWidth = getwidth(); //获取绘图区的宽度,EASYX自带
- int graphHeight = getheight(); //获取绘图区的高度,EASYX自带
- int dstX = 0; //在显存里像素的角标
-
- // 实现透明贴图 公式: Cp=αp*FP+(1-αp)*BP , 贝叶斯定理来进行点颜色的概率计算
- for (int iy = 0; iy < picture_height; iy++)
- {
- for (int ix = 0; ix < picture_width; ix++)
- {
- int srcX = ix + iy * picture_width; //在显存里像素的角标
- int sa = ((src[srcX] & 0xff000000) >> 24); //0xAArrggbb;AA是透明度
- int sr = ((src[srcX] & 0xff0000) >> 16); //获取RGB里的R
- int sg = ((src[srcX] & 0xff00) >> 8); //G
- int sb = src[srcX] & 0xff; //B
- if (ix >= 0 && ix <= graphWidth && iy >= 0 && iy <= graphHeight && dstX <= graphWidth * graphHeight)
- {
- dstX = (ix + picture_x) + (iy + picture_y) * graphWidth; //在显存里像素的角标
- int dr = ((dst[dstX] & 0xff0000) >> 16);
- int dg = ((dst[dstX] & 0xff00) >> 8);
- int db = dst[dstX] & 0xff;
- draw[dstX] = ((sr * sa / 255 + dr * (255 - sa) / 255) << 16) //公式: Cp=αp*FP+(1-αp)*BP ; αp=sa/255 , FP=sr , BP=dr
- | ((sg * sa / 255 + dg * (255 - sa) / 255) << 8) //αp=sa/255 , FP=sg , BP=dg
- | (sb * sa / 255 + db * (255 - sa) / 255); //αp=sa/255 , FP=sb , BP=db
- }
- }
- }
- }
-
- /*****************************
- * 功能:载入“恭喜通关”图片
- * 输入:
- * 无
- * 输出:
- * 无
- *****************************/
- void promot_over() {
- setbkmode(TRANSPARENT);
- drawAlpha(&images[VECTOR], 250, 130); // 载入PNG图并去透明部分
- Sleep(1100);
- }
-
- /*****************************
- * 功能:休眠
- * 输入:
- * interval - 休眠时间
- * 输出:
- * 无
- *****************************/
- void wait(int interval) {
- int count = interval / 10;
- for (int i = 0; i < count; ++i) {
- Sleep(10);
- if (_kbhit())
- return;
- }
- }
-
- /*****************************
- * 功能:游戏控制
- * 输入:
- * level - 挡墙关卡数据
- * user - 用户信息
- * 输出:
- * 无
- *****************************/
- void game_operation(levelinfo& level, userinfo& user) {
- bool quit = false;
- do {
- //判断是否有按键按下
- if (_kbhit()) {
- //无缓冲读取
- char ch = _getch();
- if (ch == KEY_UP) {
- gameControl(UP);
- }
- else if (ch == KEY_DOWN) {
- gameControl(DOWN);
- }
- else if (ch == KEY_LEFT) {
- gameControl(LEFT);
- }
- else if (ch == KEY_RIGHT) {
- gameControl(RIGHT);
- }
- else if (ch == GAME_AGAIN) {
- fetch_level_info(level, user.level_id);
- transform_map_db2array(level, map);
- show_images(level);
- }
- else if (ch == KEY_OUT) {
- closegraph();
- exit(0);
- }
- if (isGameOver()) {
- //更新用户下一关关卡信息(用户通关后直接跳转下一关)
- update_user_level(user, level.next_level);
- quit = true;
- }
- }
- wait(100);
- } while (quit == false);
- }
-
- /*****************************
- * 功能:根据“由用户ID获取关卡数据”的返回结果进行判断
- * 输入:
- * result - 返回结果(-1:获取失败 0:用户已通关 1:获取成功)
- * level - 关卡数据
- * user - 用户信息
- * 输出:
- * 无
- *****************************/
- void judge_by_result(levelinfo& level, userinfo& user) {
- show_over();
- do {
- //判断是否有按键按下
- if (_kbhit()) {
- //无缓冲读取
- char ch = _getch();
- if (ch == KEY_OUT) {
- closegraph();
- exit(0);
- }
- else if (ch == GAME_AGAIN) {
- if (!update_user_level(user, 1)) {
- std::system("pause");
- closegraph();
- exit(0);
- }
- break;
- }
- }
- Sleep(50);
- } while (1);
- fetch_level_info(level, user.level_id);
- }
- int main() {
- //作为数据初始化,只需运行一次
- resetting_data();
- load_data();
- //用户身份验证
- userinfo user;
- levelinfo level;
- if (!login(user)) {
- cout << "登录失败,请重新登录!" << endl;
- ::system("pause");
- exit(-1);
- }
- init_graph();
- //循环(读取关卡→用户操作)
- do {
- //根据用户信息加载关卡数据
- if (!fetch_level_info(level, user.level_id)) {
- judge_by_result(level, user);
- }
- //将关卡数据数据转换到map游戏地图中
- transform_map_db2array(level, map);
- //加载游戏图片
- show_images(level);
- //小人移动
- game_operation(level, user);
- //恭喜通关
- promot_over();
- } while (1);
- std::system("pause");
- closegraph();
- return 0;
- }
1.地图初始化 init_graph( ) + show_images( )
3.设计操作框架
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。