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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
#include<iostream>
#include<thread>
#include<chrono>
#include<windows.h>
using namespace std;
HANDLE h = GetStdHandle( STD_OUTPUT_HANDLE );
short BLACK = 0, GREEN = 2, YELLOW = 6, RED = 4, WHITE = 15;
//======================================
void gotoxy( short x, short y ) { SetConsoleCursorPosition( h, COORD{ x, y } ); }
void colour( short n ) { SetConsoleTextAttribute( h, n ); }
//======================================
struct State
{
short top, middle, bottom;
int time;
};
//--------------------------------------
void display( State st )
{
gotoxy( 1, 10 ); colour( WHITE ); cout << "---";
gotoxy( 2, 11 ); colour( st.top ); cout << 'O';
gotoxy( 2, 12 ); colour( st.middle ); cout << 'O';
gotoxy( 2, 13 ); colour( st.bottom ); cout << 'O';
gotoxy( 1, 14 ); colour( WHITE ); cout << "---";
}
//--------------------------------------
int main()
{
short OFF = BLACK;
State states[] = { { RED, OFF, OFF, 2 }, { RED, YELLOW, OFF, 1 }, { OFF, OFF, GREEN, 2 }, { OFF, YELLOW, OFF, 1 } };
int i = 0;
while( true )
{
display( states[i] );
this_thread::sleep_for( chrono::seconds( states[i].time ) );
i = ( i + 1 ) % 4;
}
}
| |