Mike_29 0 Newbie Poster

I'm developing a game that has a word falling to the bottom of the screen and the user typing that word before it hits the bottom. So you'll be able to type input while the word is falling. Right now I have a timer that waits 5 seconds, prints the word, runs timer again, clears the screen, and prints the word down 10 units.

int main()
for (int i = 0; i < 6; i++)
    movexy(x, y);
    cout << "hello\n";
    y = y + 10;

Very basic I know. Which is why I thought multithreading would be a good idea so that way I could have the word falling while I still type input at the bottom. This is my attempt at that so far:

    vector<std::thread> threads;

for (int i = 0; i < 5; ++i) {
    threads.push_back(std::thread(task1, "hello\n"));


for (auto& thread : threads) {

However this only prints hello 4 times to the screen, then prints 55, then prints hello again, then counts-down 3 more times. So is there a way to have a string falling towards the bottom of the screen without changing the cursor position? I've already done research and asked on stack overflow. Just a few of the links I checked out that didn't help:

Multithreaded console I/O

C++11 Multithreading: Display to console

Render Buffer on Screen in Windows

Threading console application in c++

Create new console from console app? C++

Console output from thread




Here is wordTimer()

    int wordTimer()
    _timeb start_time;
    _timeb current_time;

    int i = 5;
    for (; i > 0; i--)
        cout << i << endl;

        current_time = start_time;
        while (elapsed_ms(&start_time, &current_time) < 1000)

        start_time = current_time;
    cout << " 5 seconds have passed." << endl;
    return 0;

this is also necessary for wordTimer()

    unsigned int elapsed_ms(_timeb* start, _timeb* end)

        return (end->millitm - start->millitm) + 1000 * (end->time - start->time);

and task1

    void task1(string msg)

    movexy(x, y);
    cout << msg;
    y = y + 10;


and void movexy(int x, int y)

void movexy(int column, int line)
    COORD coord;
    coord.X = column;
    coord.Y = line;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.