Visual C++ 报错
  • 板块学术版
  • 楼主simayichen
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/12/30 16:03
  • 上次更新2024/12/30 22:26:04
查看原帖
Visual C++ 报错
1146716
simayichen楼主2024/12/30 16:03
#include<graphics.h>
#include<conio.h>
#include<stdio.h>
#pragma comment(lib,"winmm.lib")
#include<Windows.h>
#include<time.h>
#include<string>
#include <iostream>
#define MAXSTAR1 600
#define MAXSTAR 1000

#undef UNICODE
#undef _UNICODE
struct STAR
{
    int x, y, step, style;
}star[MAXSTAR];
struct STAR1
{
    int x, y, step, color;
}star1[MAXSTAR1];
IMAGE image;


// 初始化星星1
void initStar1(int i)
{
    // 在这里添加初始化逻辑,例如:
    star1[i].x = rand() % 640;
    star1[i].y = rand() % 640;
    star1[i].step = rand() % 5;
    star1[i].color = RGB(rand() % 256, rand() % 256, rand() % 256);
}


// 移动星星1
void moveStar1(int i)
{
    // 在这里添加移动逻辑,例如:
    star1[i].y += star1[i].step;
    if (star1[i].y > 640)
    {
        initStar1(i);
    }
}


// 初始化星星
void initstar(int i)
{
    // 在这里添加初始化逻辑,例如:
    star[i].x = rand() % 640;
    star[i].y = rand() % 640;
    star[i].step = rand() % 5;
    star[i].style = rand() % 2;
}


// 移动星星
void moveStar(int x)
{
    for (int i = 0; i < MAXSTAR; ++i)
    {
        star[i].y += star[i].step;
        if (star[i].y > 640)
        {
            initstar(i);
        }
    }
}


// 绘制星星
void drawStar()
{
    for (int i = 0; i < MAXSTAR; ++i)
    {
        // 在这里添加绘制逻辑,例如:
        putpixel(star[i].x, star[i].y, RGB(255, 255, 255));
    }
}


// 初始化数据
void initData()
{
    srand((unsigned int)time(NULL));
    for (int i = 0; i < MAXSTAR; ++i)
    {
        initstar(i);
    }
    for (int i = 0; i < MAXSTAR1; ++i)
    {
        initStar1(i);
    }
}


int main()
{
    initgraph(800, 600);  // 初始化图形界面,根据需要调整尺寸
    IMAGE image;  // 创建图像对象
    std::string filePath = "2.jpg";
    // 尝试加载图像
    if (loadimage(&image, filePath.c_str(), 640, 640) == NULL) {
        std::cerr << "Failed to load image." << std::endl;
    }
    else {
        putimage(0, 0, &image);  // 显示图像,根据需要调整显示位置
    }
    getch();  // 等待按键,防止程序立即关闭
    closegraph();  // 关闭图形界面
    putimage(0, 0, &image);


    while (1)
    {
        cleardevice();
        putimage(0, 0, &image);
        moveStar(0);
        drawStar();
        moveStar1(0);
        Sleep(10);
    }


    closegraph();
    return 0;
}
2024/12/30 16:03
加载中...