地图数据读取:
void Map::init_map(){//初始化地图 /*当前关卡*/ current_index = 0; /*位置地图*/ memset(pos_map, 0, sizeof(pos_map)); /*地图文件读取*/ FILE *fp; fp = fopen("map_data.txt", "r"); if (fp == NULL)cout << "open failed!" << endl; int i = 0, j = 0; while (!feof(fp)){ fscanf(fp, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &this->g_map[i][j][0], &this->g_map[i][j][1], &this->g_map[i][j][2], &this->g_map[i][j][3], &this->g_map[i][j][4], &this->g_map[i][j][5], &this->g_map[i][j][6], &this->g_map[i][j][7], &this->g_map[i][j][8], &this->g_map[i][j][9], &this->g_map[i][j][10], &this->g_map[i][j][11], &this->g_map[i][j][12]); j++; if (j == 13){ j = 0; i++; } } fclose(fp); }
任务数据读取:
void TaskSystem::init(){ FILE *f1 = fopen("taskData.txt", "r+"); while (!feof(f1)){ Task now; fscanf(f1, "%s %d %d %d\n", &(now.taskName), &(now.id), &(now.award), &(now.mark)); taskList.push_back(now); } fclose(f1); }
搜索模块:
void AutoPathFinding::Dfs(Point p, int step, vector<Point> S, int type,Map* map){ //cout << "in dfs" << endl; if ((int)map->g_map[map->current_index][p.x][p.y] == type){ if (ANS > step){ ANS = step; MT.push_back(S); } return; } if (step > ANS)return; for (int i = 0; i < 4; i++){ Point p1; p1.x = p.x + dx[i]; p1.y = p.y + dy[i]; if (check(map, p1,type)){ map->vis[p1.x][p1.y] = 1; S.push_back(p1); Dfs(p1, step + 1, S, type, map); map->vis[p1.x][p1.y] = 0; S.pop_back(); } } }
PlaySound音乐播放:
//需要的头文件 #include<windows.h> #include<Mmsystem.h> #pragma comment(lib,"winmm.lib") using namespace std; //播放函数 PlaySound(TEXT("C:\\SoundEffect\\bg.wav"), NULL, SND_FILENAME | SND_ASYNC);
输出光标的位置改变:
//定义光标位置 COORD coord; coord.X = 30; //第3行 coord.Y = 15; //第3列 //获取控制台缓冲区句柄,固定写法 HANDLE ConsoleHandle = GetStdHandle(STD_OUTPUT_HANDLE); //设置光标位置,固定写法 //coord.Y += 1; SetConsoleCursorPosition(ConsoleHandle, coord);
魔塔项目中的问题解决
猜你喜欢
转载自blog.csdn.net/love_phoebe/article/details/101262055
今日推荐
周排行