上升星河(C/C++)
#include <graphics.h> #include <Windows.h> #include <iostream> #include <stdio.h> #include <stdlib.h> #include <mmsyscom.h> #pragma comment(lib,"winmm.lib") #define int_MAX 100//星星最大值 #define HIGH 640//高 #define WIDE 560//宽 #define RADIUS_MAX 3//半径 #define INTERVAL_MAX 5//间隔 void initStart(int MAx); struct STARS { int x; int y; unsigned radius;//半径 int mobile;//移动距离 int color; enum STATE stat; }; struct STARS stars[int_MAX]; enum STATE{ STOP, UP, DOWN, LEFT, RIGHT, RANDOM, ALL_STATUS }; bool isEnd() { for (int i = 0; i < int_MAX; i++) { if (stars[int_MAX].x > 0 && stars[int_MAX].x < WIDE && WIDE && stars[int_MAX].y>0 && stars[int_MAX].y < HIGH) { return false; } } return true; } void MoveStars(int Number) { if (stars[Number].stat == STOP) return; //擦除原来的星星 setfillcolor(BLACK); solidcircle(stars[Number].x, stars[Number].y, stars[Number].radius); if (stars[Number].stat == DOWN) { stars[Number].y = stars[Number].y + stars[Number].radius; if (stars[Number].y > HIGH) stars[Number].y = 0; } else if (stars[Number].stat == UP) { stars[Number].y -= stars[Number].radius; if (stars[Number].y < 0)stars[Number].y = HIGH; } else if (stars[Number].stat == LEFT) { stars[Number].x -= stars[Number].radius; if (stars[Number].x < 0)stars[Number].x = WIDE; } else if (stars[Number].stat == RIGHT) { stars[Number].x += stars[Number].radius; if (stars[Number].x > WIDE) stars[Number].x = 0; }
//重新绘制 setfillcolor(stars[Number].color); solidcircle(stars[Number].x, stars[Number].y, stars[Number].radius); } void initStart(int MAx) { if (MAx > int_MAX) { fprintf(stderr, "超出总数[%d]", MAx); return; } int rgb; stars[MAx].x = rand() % WIDE; stars[MAx].y = (rand() % (HIGH - 100)); stars[MAx].radius = rand() % (RADIUS_MAX+1);//半径1-3 stars[MAx].mobile = rand() % (INTERVAL_MAX + 1);//移动距离1-5 rgb = 255 * stars[MAx].mobile / INTERVAL_MAX; stars[MAx].color = RGB(rgb, rgb, rgb); stars[MAx].stat =UP; } int main(void) { initgraph(WIDE, HIGH); mciSendString("play 中国交响乐团 - 春节序曲.mp3 repeat", 0, 0, 0); HWND window = GetHWnd(); SetWindowText(window, "上升");
//产生随机值 for (int i = 0; i < int_MAX; i++) { initStart(i); } //绘制 for (int i = 0; i < int_MAX; i++) { setfillcolor(stars[i].color); solidcircle(stars[i].x, stars[i].y, stars[i].radius); } bool quit = false; while (quit==false) { for (int i = 0; i < int_MAX; i++) { MoveStars(i); } if (isEnd()) { quit == true; } Sleep(50); } //system("pause"); std::cin.get(); return 0; }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!