C/C++项目——圣诞节快乐!

2023-12-26 04:33:42
#include<stdio.h>
#include<easyx.h>//需要安装
#include<Windows.h>
#include<mmsystem.h>
#pragma comment(lib,"winmm.lib")
#include"tool.h"
//图片相关操作
IMAGE imgLand;//雪地
IMAGE imgTree[20];//圣诞树
IMAGE imgOldman[14];//老人
IMAGE imgsnow[50];//雪花
//加载资源
void loadResource() {
	//加载图片
	loadimage(&imgLand, "./Resource/xuedi/2.jpg", getwidth(), 360);
	for (int i = 0; i < 20; i++) {
	char imgFile[100] = {0};
		sprintf_s(imgFile,"./Resource/tree/%d.jpg",i+1);
		loadimage(imgTree + i, imgFile, 400, 300);
	}
	for (int i = 0; i <14; i++) {
		char imgFile[100] = { 0 };
		sprintf_s(imgFile, "./Resource/oldman/%d.jpg", i + 1);
		loadimage(imgOldman + i, imgFile, 400, 300);
	}
	for (int i = 0; i <22; i++) {
		//随机生成雪花坐标rand()
		char imgFile[50] = { 0 };
		sprintf_s(imgFile, "./Resource/xuehua/%d.jpg", i + 1);
		loadimage(imgsnow + i, imgFile,25, 28);
	}
}
//初始化
void init() {
	loadResource();
}
//绘制
void draw() {
	//输出图片
	putimage(0, 475, &imgLand);
	//圣诞老人滑雪动画
	static int i = 0;
	static int k = 650;
	static int j = 0;
	static int y = rand() % getheight();
		putimage(525, 400, imgTree + i, SRCAND);
		putimage(k, 475, imgOldman + i, SRCAND);
		i = (i + 1) % 14;
		putimage(525, 400, imgTree + i, SRCPAINT);
		putimage(k, 475, imgOldman + i, SRCPAINT);
		i = (i + 1) % 14;
		if (k + 200 < 0) {
			k = 1024;
		}
		k -= 20;
	putimage(rand() % getwidth(), rand() % getheight(), imgsnow + j, SRCAND);
	putimage(rand() % getwidth(), rand() % getheight(), imgsnow + j, SRCAND);
	putimage(rand() % getwidth(), rand() % getheight(), imgsnow + j, SRCAND);
	putimage(rand() % getwidth(), rand() % getheight(), imgsnow + j, SRCAND);
	putimage(rand() % getwidth(), rand() % getheight(), imgsnow + j, SRCAND);
	putimage(rand() % getwidth(), rand() % getheight(), imgsnow + j, SRCAND);
	putimage(rand() % getwidth(), rand() % getheight(), imgsnow + j, SRCAND);
	putimage(rand() % getwidth(), rand() % getheight(), imgsnow + j, SRCAND);
	putimage(rand() % getwidth(), rand() % getheight(), imgsnow + j, SRCAND);
	putimage(rand() % getwidth(), rand() % getheight(), imgsnow + j, SRCAND);
	j = (j + 1) % 22;
	putimage(rand() % getwidth(), rand() % getheight(), imgsnow + j, SRCPAINT);
	putimage(rand() % getwidth(), rand() % getheight(), imgsnow + j, SRCPAINT);
	putimage(rand() % getwidth(), rand() % getheight(), imgsnow + j, SRCPAINT);
	putimage(rand() % getwidth(), rand() % getheight(), imgsnow + j, SRCPAINT);
	putimage(rand() % getwidth(), rand() % getheight(), imgsnow + j, SRCPAINT);
	putimage(rand() % getwidth(), rand() % getheight(), imgsnow + j, SRCPAINT);
	putimage(rand() % getwidth(), rand() % getheight(), imgsnow + j, SRCPAINT);
	putimage(rand() % getwidth(), rand() % getheight(), imgsnow + j, SRCPAINT);
	putimage(rand() % getwidth(), rand() % getheight(), imgsnow + j, SRCPAINT);
	putimage(rand() % getwidth(), rand() % getheight(), imgsnow + j, SRCPAINT);
	j = (j + 1) % 22;
	if (y > 768) {
		y = 0;
	}
	Sleep(200);
}
int main() {
	//界面,绘图
	//创建窗口
	initgraph(1024, 768);
	init();
	BeginBatchDraw();
	while (1) {
		cleardevice();
		settextcolor(YELLOW);
		settextstyle(70, 0, "华文行楷");
		outtextxy(350, 50, "圣诞节快乐!");
		settextstyle(40, 0, "华文行楷");
		outtextxy(220, 180, "学以致用,将平时所学知识变现,用");
		outtextxy(220, 250, "图形化编程编写圣诞树代码,以祝愿");
		outtextxy(220, 320, "我的老师、同学,家人们圣诞节快乐!");
		draw();
		FlushBatchDraw();
		mciSendString("open music/music.mp3", NULL, 0, NULL);
		mciSendString("play music/music.mp3", NULL, 0, NULL);
	}
	while (1);
	EndBatchDraw();
	closegraph();
	return 0;
}

文章来源:https://blog.csdn.net/2301_80585598/article/details/135211383
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。