So, I am doing a snake game with teleporters and regular mice. I had such a loop:
while(snake.alive() && miceEaten < micePerLevel)
{
displayInfo(lives, score, level, micePerLevel - miceEaten);
if(miceEaten())
{
}
}
The problem with the code above was that it was displayInfocalled before the score was updated, and therefore, after eating, the mouse had to wait until the cycle started again to see how its score was updated. So I moved one line of code to the bottom of the function:
while(snake.alive() && miceEaten < micePerLevel)
{
if(miceEaten())
{
}
displayInfo(lives, score, level, micePerLevel - miceEaten);
}
and teleporters stop working! The program crashes whenever a snake reaches a teleport. And displayInfouses the following code:
stringstream s;
s << "LEVEL " << left << setw(12) << level << "LIVES: " << setw(12) << lives << "MICE LEFT: " << setw(12) << miceLeft
<< "SCORE: " << setw(13) << score;
printLine(0, s.str(), WHITEONBLUE);
Where printLinehas only color_set, mvprintwand refresh(). Nothing to do with Teleports. Weird
So, I went to the snake function, where the snake gets its next location from the teleport:
body.push_back(teleports[overlap(next)]->teleportFrom(dir));
teleports[overlap(next)]->teleportFrom(dir) , . , (, Teleport - ?), :
Location l = teleports[overlap(next)]->teleportFrom(dir);
mvprintw(1, 0, "(%i, %i)", l.x, l.y);
refresh();
!
, . mvprintw(1, 0, "(%i, %i)", l.x, l.y);, refresh();, , , , , .
, ?
UPDATE: ( / ), 1:
warning: reference to local variable 'other' returned
:
Location& Location::operator = (Location other)
{
if(this == &other)
return other;
x = other.x;
y = other.y;
return *this;
}
, ?