Tortoise and hare race (track not refreshing correctly)
i have to create a simulated race between a hare and tortoise based on a random set of moves. The two race across the screen but i can't figure out how to keep both objects on the screen at once. i'm currently trying "\r" in different places but so far it only manages to keep the tortoise on screen and erases the hare position. Here is the code.
Code:
do
{
h1.getMove(); // get the x value for the hare
Sleep(500);
t1.getMove(); // get the x value for the tortoise
Sleep(500);
displayDots(HposPtr, hareGo); // this currently refreshes only the hare line (line 8)
Console::setColour(Console::GREEN);
cout << "H"; // displays H along the race track
displayDots(TposPtr, tortGo); // refreshes the tortoise line and places a T at x position
Console::setColour(Console::LIGHT_RED);
cout << "T";
turns++;
} while (h1.xptr <= endptr); // ends the loop at the finish
Here is the refresh line.
Code:
Console::setCursorPosition(x, y); // refreshes the current line
cout << "\r";
The function then goes on to display the race track and the x position of the current objects turn. but it only displays a T and not a H.