当前位置: 首页 > news >正文

建筑工程网站开发网址创作

建筑工程网站开发,网址创作,深圳市龙华区地图全图,网站 整站 抓取起因是我在学习C语言完成老师布置C语言写一个猜数字的作业#xff0c;突发奇想#xff0c;能不能在这个猜对了之后弹出一个不一样的页面#xff0c;然后就试试看能不能实现。基本思路是这样的#xff1a; 1#xff1a;先写一个C语言的猜数字的小游戏#xff0c;在我上个文…         起因是我在学习C语言完成老师布置C语言写一个猜数字的作业突发奇想能不能在这个猜对了之后弹出一个不一样的页面然后就试试看能不能实现。基本思路是这样的 1先写一个C语言的猜数字的小游戏在我上个文章有思路代码如下链接挂这了C语言猜数字小游戏-CSDN博客 #includestdio.h #includestdlib.h #includetime.h void menu() {printf(**** 猜数字游戏! ****\n);printf(**** 按1开始游戏 ****\n);printf(**** 按0退出游戏 ****\n); } void game() {int ret rand()%1001;//printf(%d\n, ret);int num 0;int cnt 10;int sum cnt;while (1){printf(你还有%d次机会\n, cnt);printf(请输入一个1-100之间的数:);scanf(%d, num);if (num ret){printf(数字太大了\n);}else if (num ret){printf(数字太小了\n);}else{printf(恭喜你猜对了\n);printf(猜对用了%d次\n, sum-cnt);break;}cnt--;if (cnt 0){printf(你的机会用完了游戏结束\n);printf(正确的数字是%d\n\n\n, ret);break;}} } int main() {srand((unsigned int)time(NULL));int input 0;do {menu();printf(请选择你需要的操作:);scanf(%d, input);switch (input){case 1:game();break;case 0:printf(退出游戏!\n);break;default:printf(输入错误请重新输入\n);break;}} while (input);return 0; } 2在此代码的基础上添加一些函数在game函数完成后实现弹出动画心形的思路         2.1首先要定义出这个心形的基本参数 float f(float x, float y, float z) {float a x * x 9.0f / 4.0f * y * y z * z - 1;return a * a * a - x * x * z * z * z - 9.0f / 80.0f * y * y * z * z * z; }float h(float x, float z) {for (float y 1.0f; y 0.0f; y - 0.001f)if (f(x, y, z) 0.0f)return y;return 0.0f; }void color() {system(color c); }  3这三个函数就可以实现一个跳动的心然后在心形的下面放置你想对他说的话代码如下 void sentance() {char title1[] 2021 12 05 ;char title2[] 2023 12 05 ; //输入标题char word[] 两周年快乐我爱你宝贝!; //输入想说的文字printf(\n\t ); //调整格式printf(%s, title1);printf(\n\t ); //调整格式printf(%s, title2);printf(\n\t );printf(%s, word); }4文字都可以自己添加你想再多加几行也可以直接多写几个char字符串最后再打印出来就可以。然后就是函数调用的问题 我们可以在设置一个函数这个函数可以让你的心形具有跳动的功能代码如下 int langman() {HANDLE o GetStdHandle(STD_OUTPUT_HANDLE);_TCHAR buffer[25][80] { _T( ) };_TCHAR ramp[] _T(.:-*#%);for (float t 0.0f;; t 0.1f) {int sy 0;float s sinf(t);float a s * s * s * s * 0.2f;for (float z 1.3f; z -1.2f; z - 0.1f) {_TCHAR* p buffer[sy][0];float tz z * (1.2f - a);for (float x -1.5f; x 1.5f; x 0.05f) {float tx x * (1.2f a);float v f(tx, 0.0f, tz);if (v 0.0f) {float y0 h(tx, tz);float ny 0.01f;float nx h(tx ny, tz) - y0;float nz h(tx, tz ny) - y0;float nd 1.0f / sqrtf(nx * nx ny * ny nz * nz);float d (nx ny - nz) * nd * 0.5f 0.5f;*p ramp[(int)(d * 5.0f)];}else*p ;}}for (sy 0; sy 25; sy) {COORD coord { 0, sy };SetConsoleCursorPosition(o, coord);WriteConsole(o, buffer[sy], 79, NULL, 0);}Sleep(33);color();sentance();} } 5写到这函数基本就成形了只差一个主函数了我们再把主函数给它加上 代码如下 int main() {srand((unsigned int)time(NULL));int input 0;do{menu();printf(请选择你需要的操作-);if (scanf(%d, input) ! 1 || (input ! 0 input ! 1)){printf(输入错误请重新输入\n);while (getchar() ! \n);continue;}switch (input){case 1:game();break;case 0:printf(退出游戏!\n);break;default:/*printf(输入错误请重新输入\n);*/break;}} while (input ! 0);return 0; } 当然还有猜数字游戏的主体函数以及菜单函数这个我们先不着急感兴趣的朋友可以直接复制下面的完整代码运行试试 #includestdio.h #includestdlib.h #includetime.h #include math.h #include windows.h #include tchar.hvoid menu() {printf(*********************************\n);printf(**** 玩一个猜数字游戏吧 ****\n);printf(**** 规定步数内完成有惊喜 ****\n);printf(**** 请按1可以开始游戏 ****\n);printf(**** 请按0可以退出游戏 ****\n);printf(*********************************\n); }void game() {int ret rand() % 100 1;int num 0;int cnt 10;int sum cnt;while (cnt 0){printf(你还有%d次机会\n, cnt);printf(请输入一个1-100之间的数:);if (scanf(%d, num) ! 1 || num 1 || num 100){printf(输入错误请重新输入一个1-100之间的数\n);while (getchar() ! \n);continue;}if (num ret){printf(\n数字太大了\n\n);}else if (num ret){printf(\n数字太小了\n\n);}else{printf(\n恭喜你猜对了\n\n);langman();printf(\n猜对用了%d次\n\n\n, sum - cnt 1);return;}cnt--;}printf(你的机会用完了游戏结束\n);printf(正确的数字是%d\n\n\n, ret); }float f(float x, float y, float z) {float a x * x 9.0f / 4.0f * y * y z * z - 1;return a * a * a - x * x * z * z * z - 9.0f / 80.0f * y * y * z * z * z; }float h(float x, float z) {for (float y 1.0f; y 0.0f; y - 0.001f)if (f(x, y, z) 0.0f)return y;return 0.0f; }void color() {system(color c); }void sentance() {char title1[] 2021 12 05 ;char title2[] 2023 12 05 ; //输入标题char word[] 两周年快乐我爱你宝贝!; //输入想说的文字printf(\n\t ); //调整格式printf(%s, title1);printf(\n\t ); //调整格式printf(%s, title2);printf(\n\t );printf(%s, word); }int langman() {HANDLE o GetStdHandle(STD_OUTPUT_HANDLE);_TCHAR buffer[25][80] { _T( ) };_TCHAR ramp[] _T(.:-*#%);for (float t 0.0f;; t 0.1f) {int sy 0;float s sinf(t);float a s * s * s * s * 0.2f;for (float z 1.3f; z -1.2f; z - 0.1f) {_TCHAR* p buffer[sy][0];float tz z * (1.2f - a);for (float x -1.5f; x 1.5f; x 0.05f) {float tx x * (1.2f a);float v f(tx, 0.0f, tz);if (v 0.0f) {float y0 h(tx, tz);float ny 0.01f;float nx h(tx ny, tz) - y0;float nz h(tx, tz ny) - y0;float nd 1.0f / sqrtf(nx * nx ny * ny nz * nz);float d (nx ny - nz) * nd * 0.5f 0.5f;*p ramp[(int)(d * 5.0f)];}else*p ;}}for (sy 0; sy 25; sy) {COORD coord { 0, sy };SetConsoleCursorPosition(o, coord);WriteConsole(o, buffer[sy], 79, NULL, 0);}Sleep(33);color();sentance();} }int main() {srand((unsigned int)time(NULL));int input 0;do{menu();printf(请选择你需要的操作-);if (scanf(%d, input) ! 1 || (input ! 0 input ! 1)){printf(输入错误请重新输入\n);while (getchar() ! \n);continue;}switch (input){case 1:game();break;case 0:printf(退出游戏!\n);break;default:/*printf(输入错误请重新输入\n);*/break;}} while (input ! 0);return 0; } 试运行之后我们发现有一个问题就是猜出来数字之后图像立马就出现了没有惊喜感那我们就再加一个定时器函数让猜对了之后屏幕上暂停几秒最好能在暂停的时候屏幕上出现一些文字提示说干就干代码如下 void settime(int seconds) {for (int i seconds; i 0; i--){system(cls); // 清空屏幕printf(\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n);printf(\t\t\t\t\t\t\t%d\n\n\n\n\n\n\n\n\n, i); // 放大居中显示倒计时数字Sleep(1000); // 暂停1秒}system(cls); // 清空屏幕}         这样屏幕上会短暂的出现自定义秒数的倒计时如果你想添加别的文字也可以直接在函数中printf接下哎代码基本上就大功告成了。 完整代码如下 #includestdio.h #includestdlib.h #includetime.h #include math.h #include windows.h #include tchar.hvoid menu() {printf(*********************************\n);printf(**** 玩一个猜数字游戏吧 ****\n);printf(**** 规定步数内完成有惊喜 ****\n);printf(**** 请按1可以开始游戏 ****\n);printf(**** 请按0可以退出游戏 ****\n);printf(*********************************\n); }void settime(int seconds) {for (int i seconds; i 0; i--){system(cls); // 清空屏幕printf(\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n);printf(\t\t\t\t\t\t\t%d\n\n\n\n\n\n\n\n\n, i); // 放大居中显示倒计时数字Sleep(1000); // 暂停1秒}system(cls); // 清空屏幕}void game() {int ret rand() % 100 1;int num 0;int cnt 10;int sum cnt;while (cnt 0){printf(你还有%d次机会\n, cnt);printf(请输入一个1-100之间的数:);if (scanf(%d, num) ! 1 || num 1 || num 100){printf(输入错误请重新输入一个1-100之间的数\n);while (getchar() ! \n);continue;}if (num ret){printf(\n数字太大了\n\n);}else if (num ret){printf(\n数字太小了\n\n);}else{printf(\n恭喜你猜对了\n\n);settime(3);langman();printf(\n猜对用了%d次\n\n\n, sum - cnt 1);return;}cnt--;}printf(你的机会用完了游戏结束\n);printf(正确的数字是%d\n\n\n, ret); }float f(float x, float y, float z) {float a x * x 9.0f / 4.0f * y * y z * z - 1;return a * a * a - x * x * z * z * z - 9.0f / 80.0f * y * y * z * z * z; }float h(float x, float z) {for (float y 1.0f; y 0.0f; y - 0.001f)if (f(x, y, z) 0.0f)return y;return 0.0f; }void color() {system(color c); }void sentance() {char title1[] 2021 12 05 ;char title2[] 2023 12 05 ; //输入标题char word[] 两周年快乐我爱你宝贝!; //输入想说的文字printf(\n\t ); //调整格式printf(%s, title1);printf(\n\t ); //调整格式printf(%s, title2);printf(\n\t );printf(%s, word); }int langman() {HANDLE o GetStdHandle(STD_OUTPUT_HANDLE);_TCHAR buffer[25][80] { _T( ) };_TCHAR ramp[] _T(.:-*#%);for (float t 0.0f;; t 0.1f) {int sy 0;float s sinf(t);float a s * s * s * s * 0.2f;for (float z 1.3f; z -1.2f; z - 0.1f) {_TCHAR* p buffer[sy][0];float tz z * (1.2f - a);for (float x -1.5f; x 1.5f; x 0.05f) {float tx x * (1.2f a);float v f(tx, 0.0f, tz);if (v 0.0f) {float y0 h(tx, tz);float ny 0.01f;float nx h(tx ny, tz) - y0;float nz h(tx, tz ny) - y0;float nd 1.0f / sqrtf(nx * nx ny * ny nz * nz);float d (nx ny - nz) * nd * 0.5f 0.5f;*p ramp[(int)(d * 5.0f)];}else*p ;}}for (sy 0; sy 25; sy) {COORD coord { 0, sy };SetConsoleCursorPosition(o, coord);WriteConsole(o, buffer[sy], 79, NULL, 0);}Sleep(33);color();sentance();} }int main() {srand((unsigned int)time(NULL));int input 0;do{menu();printf(请选择你需要的操作-);if (scanf(%d, input) ! 1 || (input ! 0 input ! 1)){printf(输入错误请重新输入\n);while (getchar() ! \n);continue;}switch (input){case 1:game();break;case 0:printf(退出游戏!\n);break;default:/*printf(输入错误请重新输入\n);*/break;}} while (input ! 0);return 0; } 运行兄弟们自己试试绝对惊喜
http://www.yutouwan.com/news/270226/

相关文章:

  • 闸北区网站建设网页设计济南广告公司
  • 南京制作网站优化wordpress 最受欢迎文章
  • 如何在网站做404页面去视频网站做编辑器
  • 网站建设中的服务器搭建方式建筑网格布
  • 网站开发技术人员怎样设置网站关键词
  • 网站加载进度条作风建设年 网站
  • htm5网站ai效果图网站
  • 深圳微信网站设计东莞网站建设流程图
  • xyz域名的网站有哪些苏州网站建设招聘
  • 网站维护 上海软件平台制作
  • ks2e做网站做网站阿里云买哪个服务器好点
  • 温州建设小学 网站首页博客网站入口
  • 旅游示范校建设专题网站wordpress是什么平台
  • 我英文网站建设开网店怎么开的
  • 做网站能用本地的数据库嘛视频网站管理系统
  • 杂志社网站建设方案广告公司管理系统软件
  • 淮安市建设银行网站360网站推广官网硅钙钾镁肥
  • 常用博客建站程序广西网站建设价格多少
  • 企业网站栏目设计网站制作系统哪个好
  • 海外自建站服务器维护中是什么意思
  • 广州网站建设电话销售方案
  • 有免费做推广的网站吗惠州做学校网站
  • 网站 版式wordpress 使用ajax
  • 班级网站界面用什么网站做框架图
  • 二手服务器做网站WordPress无图片主题
  • 网站备案账号密码网站建设系统
  • 军队 网站备案网站seo文章该怎么写
  • 个人网站主页花生棒 做网站
  • 企业管理系统网站专业网站的建设设行吗
  • 网站建设哪里有学2022中国互联网公司排名