我试图在迷宫中标记路径。我被困在这一点上。它只标记一个向右的方向。但我写出来的位置是X = 1 Y = 2。真的很奇怪。我的想法是为if语句创建一个while循环但是if语句甚至没有运行..请给我一些想法。
if (strcmp(argv[1], "-input") == 0)
{
ifstream ifs(argv[2]);
if(!ifs)
{
cout << "Felaktig textfil";
}
vector<vector<char>> maze;
vector<vector<char>> path;
string line;
unsigned int j=0;
while (!ifs.eof())
{
getline(ifs, line);
maze.push_back(vector<char>());
for (int i=0; i < line.size(); i++)
{
maze[j].push_back(line[i]);
}
j++;
}
//cout << maze.size();
int startX,startY;
for (int i = 0; i < maze.size(); i++)
{
for (int j = 0; j < maze[i].size(); j++)
{
if (maze[i][j] == 'S')
{
startX = j;
startY = i;
break;
}
}
}
if (startX + 1 < maze.size() && maze[startX + 1][startY] != '*')
{
startX++;
maze[startY][startX]='x';
}
if (startX - 1 > 0 && maze[startX - 1][startY] != '*')
{
startX++;
maze[startY][startX] = 'x';
}
if (startY - 1 > 0 && maze[startX][startY - 1] != '*')
{
startY--;
maze[startY][startX] = 'x';
}
if (startY + 1 < maze.size() && maze[startX][startY + 1] != '*')
{
startY++;
maze[startY][startX]='x';
}
if (maze[startY][startX]=='X')
{
cout << "done";
}
cout << startX <<startY << endl;
PrintMaze(maze);
}