“瞎写”的代码
下面是我“瞎写”的C++代码(只能用Windows系统写)
#include <bits/stdc++.h>
#include <windows.h>
#include <conio.h>
#define white SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
#define original SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
#define red SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_RED);
#define green SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_GREEN);
#define blue SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_BLUE);
#define yellow SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_RED |FOREGROUND_GREEN);
#define pink SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_RED |FOREGROUND_BLUE);
#define ching SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_GREEN |FOREGROUND_BLUE);
using namespace std;
int greentime,yellowtime,redtime;
string getTime()
{
time_t timep;
time (&timep);
char tmp[64];
strftime(tmp, sizeof(tmp), "%Y.%m.%d %H:%M:%S %A",localtime(&timep) );
return tmp;
}
int main()
{
SetConsoleTitle("红绿灯系统");
CONSOLE_CURSOR_INFO cursor_info = {1, 0};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
begin:
ching
cout<<" 红绿灯系统设置模式"<<endl<<endl<<endl;
green
cout<<" 请设置绿灯时间:";
cin>>greentime;
yellow
cout<<" 请设置黄灯时间:";
cin>>yellowtime;
red
cout<<" 请设置红灯时间:";
cin>>redtime;
Sleep(1000);
system("cls");
while(1)
{
white
cout<<" Camera 1 Time: ";
string time = getTime();
cout << time <<endl;
for(int i=redtime;i>=1;i--)
{
red
cout<<"\n\n\n\n\n ";
red
cout<<"●";
white
cout<<" ●";
cout<<" ●";
red
cout<<" Time:"<<i;
Sleep(1000);
system("cls");
white
cout<<" Camera 1 Time: ";
string time = getTime();
cout << time <<endl;
}
for(int i=greentime;i>=1;i--)
{
green
cout<<"\n\n\n\n\n ";
white
cout<<"●";
cout<<" ●";
green
cout<<" ●";
green
cout<<" Time:"<<i;
Sleep(1000);
system("cls");
white
cout<<" Camera 1 Time: ";
string time = getTime();
cout << time <<endl;
}
for(int i=yellowtime;i>=1;i--)
{
white
cout<<"\n\n\n\n\n ";
cout<<"●";
yellow
cout<<" ●";
white
cout<<" ●";
yellow
cout<<" Time:"<<i;
Sleep(1000);
system("cls");
white
cout<<" Camera 1 Time: ";
string time = getTime();
cout << time <<endl;
}
system("cls");
}
return 0;
}