Reputation: 331
In Visual Studio whenever I start without debugging, the .exe file that shows up does not contain the phrase "Press any key to continue..." like it usually does. The screen just has the flashing cursor at the beginning. Is there any easy fix to this? I have commented out some of my code and the phrase shows back up.
This is the code that I have commented out: I have all of the variables and classes declared correctly.
void Maze::addPaths()
{
Coordinate currentLocation;
Coordinate startLocation;
Coordinate endLocation; //not used yet
std::stack<Coordinate> stack;
currentLocation.row = (((rand() % HEIGHT) / 2) * 2);
currentLocation.column = (((rand() % WIDTH) / 2) * 2);
startLocation = currentLocation;
grid[currentLocation.row][currentLocation.column] = START;
player = currentLocation;
do
{
//drawMaze();
bool canMoveUp = !(currentLocation.row == 0 || grid[currentLocation.row - 2][currentLocation.column] != WALL);
bool canMoveDown = !(currentLocation.row == HEIGHT - 1 || grid[currentLocation.row + 2][currentLocation.column] != WALL);
bool canMoveLeft = !(currentLocation.column == 0 || grid[currentLocation.row][currentLocation.column - 2] != WALL);
bool canMoveRight = !(currentLocation.column == WIDTH - 1 || grid[currentLocation.row][currentLocation.column + 2] != WALL);
if (canMoveUp || canMoveDown || canMoveLeft || canMoveRight)
{
stack.push(currentLocation);
//choose random location to dig
bool moveFound = false;
while (!moveFound)
{
int direction = rand() % 4;
if (direction == 0 && canMoveUp)
{
moveFound = true;
grid[currentLocation.row - 2][currentLocation.column] = PATH;
grid[currentLocation.row - 1][currentLocation.column] = PATH;
currentLocation.row -= 2;
}
else if (direction == 1 && canMoveDown)
{
moveFound = true;
grid[currentLocation.row + 2][currentLocation.column] = PATH;
grid[currentLocation.row + 1][currentLocation.column] = PATH;
currentLocation.row += 2;
}
else if (direction == 2 && canMoveLeft)
{
moveFound = true;
grid[currentLocation.row][currentLocation.column - 2] = PATH;
grid[currentLocation.row][currentLocation.column - 1] = PATH;
currentLocation.column -= 2;
}
else if (direction == 3 && canMoveRight)
{
moveFound = true;
grid[currentLocation.row][currentLocation.column + 2] = PATH;
grid[currentLocation.row][currentLocation.column - 2] = PATH;
currentLocation.column += 2;
cout << "yay";
}
}
}
else if (!stack.empty())
{
currentLocation = stack.top();
stack.pop();
}
} while (!stack.empty());
//addDestinationToGrid();
cout << "no";
}
Upvotes: 0
Views: 697
Reputation: 331
The problem ended up being that I was traveling out of the bounds of the array named grid and I has also mixed up my row and columns in my for loops.
Upvotes: 0
Reputation: 61
It seems your main do-while
loops in endless cycle. How do you initialize grid?
Upvotes: 2
Reputation: 37894
On Windows, system("PAUSE");
will prompt a user with the text:
Press any key to continue...
Upvotes: 3