新年祝福c++代码奉上!

· · 休闲·娱乐

include <iostream>

include <windows.h>

include <conio.h>

include <cstdlib>

include <ctime>

using namespace std;

// 设置颜色 void color(int c) { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), c); }

// 移动光标 void gotoxy(int x, int y) { COORD pos = {SHORT(x), SHORT(y)}; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos); }

// 隐藏光标 void hideCursor() { CONSOLE_CURSOR_INFO info = {1, 0}; SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info); }

// 逐字输出 void print(const char* s, int ms = 40) { for (int i = 0; s[i]; i++) { cout << s[i] << flush; Sleep(ms); } }

// 单个烟花 void fire(int x, int y) { color(12); gotoxy(x, y); cout << "★"; Sleep(100); color(14); gotoxy(x-1,y); cout << "★"; gotoxy(x+1,y); cout << "★"; gotoxy(x,y-1); cout << "★"; gotoxy(x,y+1); cout << "★"; Sleep(100); color(10); gotoxy(x-2,y); cout << "★"; gotoxy(x+2,y); cout << "★"; gotoxy(x,y-2); cout << "★"; gotoxy(x,y+2); cout << "★"; Sleep(100); color(7); }

int main() { system("mode con cols=60 lines=30"); system("title 2026马年快乐·彩色雪花烟花版"); hideCursor(); srand(time(0));

// 雪花飘落
for (int t = 0; t < 40; t++) {
    for (int i = 0; i < 20; i++) {
        color(11);
        int x = rand() % 58;
        int y = rand() % 15;
        gotoxy(x, y); cout << "❄";
        Sleep(10);
    }
}

system("cls");
color(12);
print("            =========================", 30);
color(14);
print("                   2026 马年大吉", 30);
color(12);
print("            =========================\n", 30);
Sleep(500);

color(10);
print("        爆竹声声辞旧岁,代码行行迎新春", 50);
print("        骏马奔腾开新局,前程似锦步步赢", 50);
print("        程序无错运行稳,人生如意万事顺", 50);
color(11);
print("        烦恼全被注释掉,幸福永久编译好\n", 50);
Sleep(500);

// 烟花秀
fire(rand()%40+10, rand()%8+5);
fire(rand()%40+10, rand()%8+5);
fire(rand()%40+10, rand()%8+5);
Sleep(500);

color(14);
print("              祝:学业进步 平安喜乐 万事胜意\n", 40);
color(12);
print("                     新年快乐!🎉", 40);

color(7);
getch();
return 0;

}