we give boardnumber as 1 to the above function and boardsDir contains a directory called boards which contains 1.txt,2.txt,... as levels .
we increase the boardnumber as game progresses.
I have very hard time understanding the code present in the lines 4 and 5 .
Another thing is that line 7 is printing "Loading board boards/1.txt" on console.
//define keyboardcontroller member method loadBoard, returning a boolean value and taking an int as an argument
bool keyboardcontroller::loadboard(int boardnumber)
{
//declare a stringstream called sin
stringstream sin;
//concatenate boardsDir, boardsNumber and ".txt" and insert into the stringstream
sin<<boardsDir<<boardNumber<<".txt";
//stat() returns 0 if it can load the file's information, i.e. if it exists
if(stat(sin.str().c_str(),&st) == 0)
{
//if the file exists, print "Loading Board =" + the c-character sequence of stringstream sin
printf("Loading board = %s \n",sin.str().c_str());\
//return true and exit function
returntrue;
}
// if the file does not exist, return false and exit the function
else
{
returnfalse;
}
}
If you need further information on the functions used, check out these links: