上升星河(C/C++)

静态效果图


上升星河(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;
}

原文链接: https://www.cnblogs.com/WU20/p/15817339.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/186424

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月12日 上午11:07
下一篇 2023年2月12日 上午11:07

相关推荐