>>16140440>>16140160大概先蔗樣,下面那段GOAL的部分窩感覺跟任務選取沒有太直接的關係,泥可能要重新思考一下大段邏輯。
[aa]
ifstream openDungeonMap()
{
string file = "", line = "";
ifstream input( file ) ;
do{
cout << "Please Input DungeonMap file name :" ;
cin >> line ;
file = "input" + line + ".txt" ;
input.open( file ) ;
}while ( !input )
return input;
}
bool missionChecker(int mission,int goal){
switch(mission)
{
case 2:
//mission_2 must select goal
return goal != -1;
default:
return true;
}
}
missionSelector(){
}
std::tuple<int, int> getDungeonMapSize(string mapInfo)
{
int test = 0 ;
int mapSizeX,mapSizeY;
string str_x = "", str_y = "" ;
for ( int check = 0 ; check < mapInfo.size() && test != -1 ; check++ ) { // 紀錄xy軸
if ( mapInfo.at( check ) != ' ' ) // 找到x的數字
test++ ;
if ( mapInfo.at( check ) == ' ' && test != 0 ) {
// 找完x的數字後把第一行拆兩部分並轉成數字
test = -1 ;
str_y = str_y.assign( mapInfo, check, mapInfo.size() - check ) ;
str_x = str_x.assign( mapInfo, 0, check ) ;
mapSizeX = stoi(str_x) ;
mapSizeY = stoi(str_y) ;
}
}
return std::make_tuple(mapSizeX, mapSizeY);
}
int getMapTokenEnum(string token)
{
switch(token)
{
case 'O':
return 1;
case 'E':
return 2;
case 'G':
return 0;
default:
return -1;
}
}
void setDungeonMap(ifstream dungeonMap)
{
string dungeonInfo;
getline( dungeonMap, dungeonInfo );
std::tuple<int, int> dungeonMapSize = getDungeonMapSize(dungeonInfo);
int sizeX = std::get<0>(dungeonMapSize);
int sizeY = std::get<1>(dungeonMapSize);
//----
map.resize(sizeY);
string mapTokenPerLine;
for ( int now_y = 0 ; getline( dungeonMap, mapTokenPerLine ) ; now_y++ ) { // 記錄地圖( 跑y軸部分 )
map[now_y].resize( sizeX ) ;
for ( int now_x = 0 ; now_x < mapTokenPerLine.size() ; now_x++ ) {
string mapToken = mapTokenPerLine.at( now_x );
map[now_y][now_x] = getMapTokenEnum(mapToken);
}
}
}
void Dungeon::Read( int mission ) {
ifstream dungeonMap = openDungeonMap();
setDungeonMap(dungeonMap);
//----
//TODO:邏輯有點微妙,需要釐清Decide_Error_or_number到底是幹嘛的才能整理下去。
int goal;
do{
cout << "Please Input number of goal :" ;
goal = Decide_Error_or_number();
}while ( false == missionChecker(mission,goal))
bool isEnterMission2 = goal != -1;
if(isEnterMission2)
{
Mission2(goal);
}
else{
Mission1();
}
}
[/aa]