Dev-C++编写一个爱心同时进行屏闪
时间: 2024-01-16 22:02:26 浏览: 79
以下是Dev-C++中的代码,可以实现一个爱心同时进行屏闪的效果:
```c++
#include <iostream>
#include <windows.h>
using namespace std;
int main() {
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); // 获取控制台句柄
CONSOLE_CURSOR_INFO cursorInfo; // 定义控制台光标结构体
cursorInfo.dwSize = 100;
cursorInfo.bVisible = false; // 隐藏控制台光标
SetConsoleCursorInfo(hOut, &cursorInfo);
while (true) {
system("cls"); // 清空屏幕
SetConsoleTextAttribute(hOut, FOREGROUND_RED | FOREGROUND_INTENSITY); // 设置控制台字符前景色为红色
cout << " ** **" << endl;
cout << " ** ** ** **" << endl;
cout << " ** ** **" << endl;
cout << " ** **" << endl;
cout << "** **" << endl;
cout << "** **" << endl;
cout << " ** **" << endl;
cout << " ** **" << endl;
cout << " ** **" << endl;
cout << " ** **" << endl;
cout << " ** **" << endl;
cout << " **" << endl;
Sleep(500); // 等待500毫秒
system("cls"); // 清空屏幕
SetConsoleTextAttribute(hOut, FOREGROUND_GREEN | FOREGROUND_INTENSITY); // 设置控制台字符前景色为绿色
cout << " ** **" << endl;
cout << " ** ** ** **" << endl;
cout << " ** ** **" << endl;
cout << " ** **" << endl;
cout << "** **" << endl;
cout << "** **" << endl;
cout << " ** **" << endl;
cout << " ** **" << endl;
cout << " ** **" << endl;
cout << " ** **" << endl;
cout << " ** **" << endl;
cout << " **" << endl;
Sleep(500); // 等待500毫秒
}
return 0;
}
```
上述代码通过控制台API函数实现了隐藏控制台光标和设置控制台字符前景色的功能,从而实现了爱心同时进行屏闪的效果。
阅读全文