前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【精选】表白小姐姐(C语言)

【精选】表白小姐姐(C语言)

作者头像
命运之光
发布2024-03-20 09:21:18
420
发布2024-03-20 09:21:18
举报

【精选】表白小姐姐

一、项目环境

1.Visual Studio 2022 2.安装easyx图形库,可以调用头文件

#include<easyx.h>

简单介绍一下easyx图形库

EasyX库是一个基于C语言的图形界面库,可以用于Windows操作系统下的图形界面应用程序开发。该库提供了一些易于使用的图形绘制函数和简单的事件处理功能,可以帮助开发者快速地创建各种图形应用程序,如游戏、图形编辑器等。 EasyX库提供了丰富的绘图功能,如直线、矩形、圆形、椭圆、多边形等基本形状的绘制,同时还支持图片、文字、音频等多种媒体资源的加载和处理。此外,EasyX库还支持鼠标、键盘等多种事件的处理,可以让用户与应用程序进行交互。 EasyX库的另一个特点是易于学习和使用。它提供了简单的API,使得初学者也可以轻松地入门,并且具有丰富的在线文档和示例程序,帮助开发者快速地学习和理解如何使用这个库。除此之外,EasyX库还可以和Visual Studio等常见的集成开发环境进行配合使用,使得开发工作更加高效。 总之,EasyX库是一款简单易用、功能强大的图形界面库,适用于初学者和有一定编程基础的开发者,可以用于快速开发各种图形应用程序。

Easyx图形库

点击此处跳转到Easyx下载官网

二、程序介绍

一款表白小姐姐的程序,点击YES进行关闭(需自行写一个closegraph()用来关闭),而点击NO则不会关闭窗口,并且NO会生成新的矩形(NO)

三、运行效果展示

主页面展示:

功能1:点击NO会生成新的矩形(NO)

功能2:点击YES会关闭程序

此处需写一个close()试着自己写一下看看吧🤭

四、源代码分享
代码语言:javascript
复制
#include<stdio.h>
#include<easyx.h>
#include<graphics.h>
#include <windows.h>
#include <stdlib.h>
#include <string.h>
#include<iostream>
using namespace std;
typedef struct {
	int left;
	int top;
	int right;
	int bottom;
}n;
//setlinecolor(BLACK);
//fillrectangle(700, 600, 1000, 700);
//RECT no;
//no.left = 700;
//no.top = 600;
//no.right = 1000;
//no.bottom = 700;
//settextstyle(60, 0, "微软雅黑");
setfillcolor(BLACK);
fillrectangle(100, 50, 800, 250);
//LOGFONT fontstyle4;
//gettextstyle(&fontstyle4);
//fontstyle4.lfQuality = ANTIALIASED_QUALITY;
//settextstyle(&fontstyle4);
//const char* pstr4 = "NO";
settextstyle(120, 0, "微软雅黑");
//settextcolor(RED);
//drawtext(pstr4, &no, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
void non(int left,int top,int right,int bottom)
{
	setlinecolor(BLACK);
	fillrectangle(left, top, right, bottom);
	RECT no;
	no.left = left;
	no.top = top;
	no.right = right;
	no.bottom = bottom;
	settextstyle(60, 0, "微软雅黑");
	//setfillcolor(BLACK);
	//fillrectangle(100, 50, 800, 250);
	LOGFONT fontstyle4;
	gettextstyle(&fontstyle4);
	fontstyle4.lfQuality = ANTIALIASED_QUALITY;
	settextstyle(&fontstyle4);
	const char* pstr4 = "NO";
	//settextstyle(120, 0, "微软雅黑");
	settextcolor(RED);
	drawtext(pstr4, &no, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
}
int main()
{
	n m;
	initgraph(1200, 800, EW_SHOWCONSOLE);
	setbkcolor(WHITE);
	cleardevice();
	//图片
	IMAGE img;
	loadimage(&img, "1.jpg",400,400);
	putimage(800, 0, &img);
	RECT rect;
	rect.left = 100;
	rect.top = 50;
	rect.right = 800;
	rect.bottom = 250;
	settextstyle(60, 0, "微软雅黑");
	//setfillcolor(BLACK);
	//fillrectangle(100, 50, 800, 250);
	LOGFONT fontstyle;
	gettextstyle(&fontstyle);
	fontstyle.lfQuality = ANTIALIASED_QUALITY;
	settextstyle(&fontstyle);
	const char* pstr = "小姐姐,我观察你很久了";
	//settextstyle(120, 0, "微软雅黑");
	settextcolor(BLACK);
	drawtext(pstr, &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
	RECT rect1;
	rect1.left = 100;
	rect1.top = 250;
	rect1.right = 800;
	rect1.bottom = 300;
	settextstyle(50, 0, "微软雅黑");
	//setfillcolor(BLACK);
	//fillrectangle(100, 50, 800, 250);
	LOGFONT fontstyle2;
	gettextstyle(&fontstyle2);
	fontstyle2.lfQuality = ANTIALIASED_QUALITY;
	fontstyle2.lfWeight = FW_HEAVY;
	fontstyle2.lfUnderline = true;
	settextstyle(&fontstyle2);
	const char* pstr1 = "做我女朋友好不好?";
	//settextstyle(120, 0, "微软雅黑");
	settextcolor(RED);
	drawtext(pstr1, &rect1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
	setlinecolor(BLACK);
	setlinestyle(PS_ENDCAP_ROUND,4);
	fillrectangle(200, 600, 500, 700);
	RECT yes;
	yes.left = 200;
	yes.top = 600;
	yes.right = 500;
	yes.bottom = 700;
	settextstyle(60, 0, "微软雅黑");
	//setfillcolor(BLACK);
	//fillrectangle(100, 50, 800, 250);
	LOGFONT fontstyle3;
	gettextstyle(&fontstyle3);
	fontstyle3.lfQuality = ANTIALIASED_QUALITY;
	settextstyle(&fontstyle3);
	const char* pstr3 = "YES";
	//settextstyle(120, 0, "微软雅黑");
	settextcolor(RED);
	drawtext(pstr3, &yes, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
	m.left = 700;
	m.top = 600;
	m.right = 1000;
	m.bottom = 700;
	non(m.left, m.top, m.right, m.bottom);
	while (1)
	{
		if (MouseHit())//判断是否有鼠标信息
		{
			MOUSEMSG msg = GetMouseMsg();//接收鼠标信息 
			printf("坐标为(%d,%d)\n", msg.x, msg.y);
			switch (msg.uMsg)
			{
			case WM_LBUTTONDOWN:
				//NO的区域
				if (msg.x > m.left && msg.x < m.right && msg.y>m.top && msg.y < m.bottom)
				{
					printf("坐标为(%d,%d)我是天才\n", msg.x, msg.y);
					m.left = rand() % 900;
					m.top = rand() % 700;
					m.right = m.left + 300;
					m.bottom = m.top + 100;
					non(m.left, m.top, m.right, m.bottom);
				}
			}
		}
	}
	getchar();
	closegraph();
	return 0;
}
总结与思考

此程序有许多可操作空间,这里就留给各位感兴趣的猿子们自行探索修改吧🤭

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2024-03-19,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 【精选】表白小姐姐
    • 一、项目环境
      • 简单介绍一下easyx图形库
        • Easyx图形库
          • 二、程序介绍
            • 三、运行效果展示
              • 四、源代码分享
                • 总结与思考
                领券
                问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档