Tic Tac Toe animation

I wrote a Tic Tac Toe program and it works perfectly except I'd like to improve it a bit better by having the board refresh slowly instead of just clearing the console and redrawing it. I've tried using the Sleep() command but that only delays the output, i'd like the board to slowly output on the screen.

Heres my code for my class function that draws the board:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
void Tic::drawboard() //draws tic tac toe board
{
     cout<<"  **************  ************     *********\n"
         <<"        **             **          **       \n"          //program template
         <<"        **             **          **       \n"
         <<"        **        ***********      *********\n\n\n\n";
    

Sleep(100);
cout.flush();

     cout<<"\t           |           |           \n"
         <<"\t      "<<position[0][0]<<"    |     "<<position[0][1]<<"     |     "<<position[0][2]<<endl
         <<"\t           |           |           \n"
         <<"\t ---------- ----------- -----------\n" 
         <<"\t           |           |           \n"
         <<"\t      "<<position[1][0]<<"    |     "<<position[1][1]<<"     |     "<<position[1][2]<<endl   
         <<"\t           |           |           \n"
         <<"\t ---------- ----------- -----------\n"
         <<"\t           |           |           \n"
         <<"\t      "<<position[2][0]<<"    |     "<<position[2][1]<<"     |     "<<position[2][2]<<endl  
         <<"\t           |           |           \n\n\n\n\n";   
         
         
}


Any help would be greatly appreciated. Thanks.
What do you mean by "slowly output"? Like output each line and then pause or what?
Hmm, the best way i can describe it is by having random pixels disappear until they are all gone and then have them randomly output few by few until the board is redrawn.
Consoles don't do "slow" outputs. Provided I understood what you meant, you need a fully certified multimedia library for that.

EDIT: and seeing as I did understand what you meant, you need a multimedia library for that. Try SDL.

-Albatross
Last edited on
Topic archived. No new replies allowed.