I worked through the Stanford CS106B course, and while doing the Boggle job, I noticed that the Sleep () function on Windows behaves differently than the Pause () function. For testing purposes, I just installed the board and used the provided gboggle.h file to select the Boggle cubes and then remove the selection. Below is the corresponding code:
for(int row = 0; row < board.numRows(); row++) { for(int col = 0; col < board.numCols(); col++) { HighlightCube(row, col, true); } } Pause(0.5); for(int row = 0; row < board.numRows(); row++) { for(int col = 0; col < board.numCols(); col++) { HighlightCube(row, col, false); } }
If I use Pause (), the cubes are allocated and then returned to their normal state. If I use Sleep () or Wait (), the cubes are never allocated, and the delay in the program occurs before the board is drawn, and not between for loops. Corresponding Wait () function:
void wait ( int seconds ) { clock_t endwait; endwait = clock () + seconds * CLOCKS_PER_SEC ; while (clock() < endwait) {} }
taken from here . I am using Visual Studio 2005 on Windows XP.
What is the difference between these functions that makes them act this way?
Edit: I know Sleep and wait require integers. I checked them with integers and saw a delay, but this happens before the squares are written. Sorry, I didnβt know about this before.
Edit2: After looking at some of the other libraries that I used, I found that Pause is actually part of a graphics library that simply pauses the graphics buffer.
source share