我提前与大家说一声“新年快乐”,我打了一下下代码送给大家:
#include <iostream>
#include <string>
#include <ctime>
#include <windows.h>
#include <Windows.h>
#include <cstdlib>
#include <random>
#include <conio.h>
using namespace std;
void color(int BackC, int ForgC) {
WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor);
}
string a[1001] = {
"",//0
"新春快乐,万事如意!",//1
"恭贺新禧,阖家幸福!",//2
"前程似锦,步步高升。",//3
"心想事成,万事如意。",//4
"让过去的成为美好回忆,未来的充满无限希望。",//5
"愿您的生活像春天一样温暖、明亮。",//6
"愿您的生活像夏天一样热情、灿烂。",//7
"愿您的生活像秋天一样丰收、喜悦。",//8
"愿您的生活像冬天一样宁静、祥和。",//9
"愿您在新的一年里事业蒸蒸日上,家庭和睦美满。",//10
"愿您笑靥如花,幸福安康。",//11
"事业蒸蒸日上,前程似锦。",//12
"愿你在新的一年里,如阳光般明媚,如花朵般绽放。",//13
"让过去的遗憾随风而去,迎接新的希望和挑战。",//14
"愿您事业如日中天,财源广进。",//15
"愿您家庭和睦美满,幸福安康。",//16
"祝您在新的一年里心想事成,万事如意!",//17
"愿你我皆能以梦为马,不负韶华。",//18
"祝您事业有成、财源广进、家庭美满、幸福安康!",//19
"恭贺新禧,恭祝新年快乐!"//20
};
void showGreeting(int n) {
color(0, 7);
cout << "* ";
color(0, 4);
cout << a[n];
color(0, 7);
cout << " *" << endl;
}
void showDynamicMessage() {
time_t now = time(0);
tm *ltm = localtime(&now);
cout << "今天是:";
cout << 1900 + ltm->tm_year << "年" << 1 + ltm->tm_mon << "月" << ltm->tm_mday << "日";
system("time /t");
cout << "\n愿新的一年,给你带来更多的快乐与成功!\n";
}
void showFireworks(int n, int x) {
cout << "\n\n\n";
for (int i = 0; i < x; i++)
cout << ' ';
if (n == 9) {
srand((unsigned)time(NULL));
color(0, rand() % 15 + 1);
cout << " ";
cout << "\\";
color(0, 0);
cout << " ";
color(0, rand() % 15 + 1);
cout << "|";
color(0, 0);
cout << " ";
color(0, rand() % 15 + 1);
cout << "/";
color(0, 0);
cout << "\n ";
for (int i = 0; i < x; i++)
cout << ' ';
color(0, rand() % 15 + 1);
cout << "— ";
color(0, 0);
color(0, rand() % 15 + 1);
cout << "—";
color(0, 0);
cout << "\n";
for (int i = 0; i < x; i++)
cout << ' ';
color(0, rand() % 15 + 1);
cout << "— ";
color(0, 0);
color(0, rand() % 15 + 1);
cout << "·";
color(0, 0);
color(0, rand() % 15 + 1);
cout << " —";
color(0, 0);
cout << "\n ";
for (int i = 0; i < x; i++)
cout << ' ';
color(0, rand() % 15 + 1);
cout << "— ";
color(0, 0);
color(0, rand() % 15 + 1);
cout << "—";
color(0, 0);
cout << "\n ";
for (int i = 0; i < x; i++)
cout << ' ';
color(0, rand() % 15 + 1);
cout << " ";
cout << "/";
color(0, 0);
cout << " ";
color(0, rand() % 15 + 1);
cout << "|";
color(0, 0);
cout << " ";
color(0, rand() % 15 + 1);
cout << "\\";
color(0, 7);
cout << "\n\n\n\n";
} else if (n == 8) {
for (int i = 0; i < x; i++)
cout << ' ';
color(0, 4);
cout << "|";
cout << "\n\n\n\n\n\n\n\n";
} else if (n == 7) {
cout << "\n";
color(0, 4);
for (int i = 0; i < x; i++)
cout << ' ';
cout << "|";
cout << "\n\n\n\n\n\n\n";
} else if (n == 6) {
cout << "\n\n";
color(0, 4);
for (int i = 0; i < x; i++)
cout << ' ';
cout << "|";
cout << "\n\n\n\n\n\n";
} else if (n == 5) {
cout << "\n\n\n";
color(0, 4);
for (int i = 0; i < x; i++)
cout << ' ';
cout << "|";
cout << "\n\n\n\n\n";
} else if (n == 4) {
cout << "\n\n\n\n";
color(0, 4);
for (int i = 0; i < x; i++)
cout << ' ';
cout << "|";
cout << "\n\n\n\n";
} else if (n == 3) {
cout << "\n\n\n\n\n";
color(0, 4);
for (int i = 0; i < x; i++)
cout << ' ';
cout << "|";
cout << "\n\n\n";
} else if (n == 2) {
cout << "\n\n\n\n\n\n";
color(0, 4);
for (int i = 0; i < x; i++)
cout << ' ';
cout << "|";
cout << "\n\n";
} else if (n == 1) {
cout << "\n\n\n\n\n\n\n";
color(0, 4);
for (int i = 0; i < x; i++)
cout << ' ';
cout << "|\n";
}
color(0, 7);
cout << "————————————————————————————";
}
int x, y;
long double N = 20;
int main() {
system("color 07");
system("title 贺新春");
srand((unsigned)time(NULL));
for (long long i = 0; i < 2e62; i++) {
if (_kbhit()) {
system("cls");
if (_getch() == 27) {
cout << "当前帧率:" << N << '\n';
cout << "现在帧率:";
cin >> N;
Sleep(2000);
system("cls");
}
}
if (i % 10 == 0) {
x = rand() % 30 + 10;
} else {
showGreeting(i / 50 % 20 + 1);
showDynamicMessage();
showFireworks(i % 10, x);
Sleep(1000 / N);
system("cls");
}
}
return 0;
}