魔塔項目中的問題解決

地圖數據讀取:
 

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);

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章