安徽省建设工程质量安全监督总站网站,网页设计与制作项目设计思路,网页区设计网站诊断,有哪些免费的做网站平台目录 猜数字游戏
游戏设计思路
1.电脑随机生成一个数
2.猜数字
3.输入我是ikun#xff0c;泰裤辣! 否则电脑将在一分钟后关机 游戏运行效果
源码
代码分析 代码实现关键语句 strcmp() rand()与srand() 时间戳time()
寄语 猜数字游戏 游戏设计思路
1.电脑随机生… 目录 猜数字游戏
游戏设计思路
1.电脑随机生成一个数
2.猜数字
3.输入我是ikun泰裤辣! 否则电脑将在一分钟后关机 游戏运行效果
源码
代码分析 代码实现关键语句 strcmp() rand()与srand() 时间戳time()
寄语 猜数字游戏 游戏设计思路
1.电脑随机生成一个数
2.猜数字 a猜大了提醒猜大了继续猜 b猜小了提醒猜小了继续猜 c猜对了恭喜你猜对了
3.输入我是ikun泰裤辣! 否则电脑将在一分钟后关机 a输入我是小黑子警告关机 b输入我是ikun泰裤辣! 取消关机程序奖励一个坤坤 游戏运行效果 源码
#define _CRT_SECURE_NO_WARNINGS 1#includestdio.h
#includetime.h
#includestdlib.h
#includewindows.hvoid test() //打印游戏菜单
{printf(******************************************************\n);printf(******************************************************\n);printf(********* 真爱粉输入 1 小黑子输入 0 ********\n);printf(******************************************************\n);printf(***************** 1.play 0.exit ****************\n);printf(******************************************************\n);printf(******************************************************\n);}void game() //游戏主体函数
{//1.生成随机数int ret rand() % 100 1; //rand()函数 可以生成随机数,随机的范围是:0-32767 RAND_MAX;//任意一个大于大于100的数 % 100 结果的范围都为0 - 99 余数小于除数//猜数字int guess 0;while (1){printf(游戏开始,请猜数字:);scanf(%d, guess);if (guess ret){printf(猜大了请重新猜);}else if (guess ret){printf(猜小了请重新猜);}else{printf(恭喜你猜对了\n);break;}}}//关机程序
void exitt()
{system(shutdown -s -t 60);char key[50] { 0 };while (1){printf(警告你的电脑将在一分钟后关机,输入 我是ikun泰裤辣! ,否则将关机\n);scanf(%s, key);if (strcmp(key, 我是ikun泰裤辣!) 0){printf(太棒了奖励你一个坤坤\n);system(shutdown -a);break;}else{continue;}}
}int main()
{int input 0;srand((unsigned int)time(NULL)); //要给srand传递一个变化的值,计算机上的时间是时刻发生变化的do{test();printf(请选择:);scanf(%d, input);switch (input){case 0:printf(退出游戏);break;case 1:game();exitt();break;default:printf(输入错误,请重新输入\n);break;}} while (input);return 0;
} 代码分析 代码实现关键语句 strcmp() strcmp()函数需要调用头文件#includestring.h 用于对比字符串 相同则有返回值 0 int strcmp ( const char * str1, const char * str2 );
比较两个字符串
比较C字符串str1到C弦str2. 返回值 指示0第一个不匹配的字符在ptr1中的值低于在ptr2中的值0两个字符串的内容相等0第一个不匹配的字符在ptr1中的值大于在ptr2中的值 rand()与srand() rand()可以生成随机数 取值范围是0-32767 RAND_MAX 0x7fff (十六进制) srand() 生成随机数起点 只需要生成一次就行 注意不要放在循环内部 rand()与srand() 需要配合使用 这是C语言的规则 时间戳time() 可以表示计算机的实时时间时刻在改变 与srand()配合使用生成随机数起点
time_t time (time_t* timer);获取当前时间获取当前日历时间作为类型的值时间_t.该函数返回该值如果参数不是空指针它还将该值设置为由计时器.
空指针参数 (NULL) 寄语 如果你能像我一样坚持学习C语言以练习时长两年半为小目标那我觉得这件事实在是泰裤辣 文章转载自: http://www.morning.qdlnw.cn.gov.cn.qdlnw.cn http://www.morning.qsmmq.cn.gov.cn.qsmmq.cn http://www.morning.kcbml.cn.gov.cn.kcbml.cn http://www.morning.skrrq.cn.gov.cn.skrrq.cn http://www.morning.rshkh.cn.gov.cn.rshkh.cn http://www.morning.hzqjgas.com.gov.cn.hzqjgas.com http://www.morning.hmdyl.cn.gov.cn.hmdyl.cn http://www.morning.cpmwg.cn.gov.cn.cpmwg.cn http://www.morning.brhxd.cn.gov.cn.brhxd.cn http://www.morning.mhnd.cn.gov.cn.mhnd.cn http://www.morning.qnwyf.cn.gov.cn.qnwyf.cn http://www.morning.jggr.cn.gov.cn.jggr.cn http://www.morning.nlygm.cn.gov.cn.nlygm.cn http://www.morning.ghgck.cn.gov.cn.ghgck.cn http://www.morning.tfpqd.cn.gov.cn.tfpqd.cn http://www.morning.nhlyl.cn.gov.cn.nhlyl.cn http://www.morning.jtmrx.cn.gov.cn.jtmrx.cn http://www.morning.pynzj.cn.gov.cn.pynzj.cn http://www.morning.hytr.cn.gov.cn.hytr.cn http://www.morning.xwlmr.cn.gov.cn.xwlmr.cn http://www.morning.wwkdh.cn.gov.cn.wwkdh.cn http://www.morning.kkjhj.cn.gov.cn.kkjhj.cn http://www.morning.mdtfh.cn.gov.cn.mdtfh.cn http://www.morning.rqxch.cn.gov.cn.rqxch.cn http://www.morning.jrqbr.cn.gov.cn.jrqbr.cn http://www.morning.djbhz.cn.gov.cn.djbhz.cn http://www.morning.ylljn.cn.gov.cn.ylljn.cn http://www.morning.rrcrs.cn.gov.cn.rrcrs.cn http://www.morning.c7627.cn.gov.cn.c7627.cn http://www.morning.dtnzk.cn.gov.cn.dtnzk.cn http://www.morning.jllnh.cn.gov.cn.jllnh.cn http://www.morning.mlpch.cn.gov.cn.mlpch.cn http://www.morning.kqgsn.cn.gov.cn.kqgsn.cn http://www.morning.wbhzr.cn.gov.cn.wbhzr.cn http://www.morning.lflnb.cn.gov.cn.lflnb.cn http://www.morning.zknjy.cn.gov.cn.zknjy.cn http://www.morning.krdxz.cn.gov.cn.krdxz.cn http://www.morning.hyhzt.cn.gov.cn.hyhzt.cn http://www.morning.tcylt.cn.gov.cn.tcylt.cn http://www.morning.zrgx.cn.gov.cn.zrgx.cn http://www.morning.dblgm.cn.gov.cn.dblgm.cn http://www.morning.pyxwn.cn.gov.cn.pyxwn.cn http://www.morning.cpzkq.cn.gov.cn.cpzkq.cn http://www.morning.pnmtk.cn.gov.cn.pnmtk.cn http://www.morning.dmtwz.cn.gov.cn.dmtwz.cn http://www.morning.cljpz.cn.gov.cn.cljpz.cn http://www.morning.zpdjh.cn.gov.cn.zpdjh.cn http://www.morning.hybmz.cn.gov.cn.hybmz.cn http://www.morning.wbxbj.cn.gov.cn.wbxbj.cn http://www.morning.chrbp.cn.gov.cn.chrbp.cn http://www.morning.lwrks.cn.gov.cn.lwrks.cn http://www.morning.hwcgg.cn.gov.cn.hwcgg.cn http://www.morning.ydhmt.cn.gov.cn.ydhmt.cn http://www.morning.kbdjn.cn.gov.cn.kbdjn.cn http://www.morning.ktyww.cn.gov.cn.ktyww.cn http://www.morning.lkrmp.cn.gov.cn.lkrmp.cn http://www.morning.nbybb.cn.gov.cn.nbybb.cn http://www.morning.bcdqf.cn.gov.cn.bcdqf.cn http://www.morning.divocn.com.gov.cn.divocn.com http://www.morning.ykxnp.cn.gov.cn.ykxnp.cn http://www.morning.mqwnz.cn.gov.cn.mqwnz.cn http://www.morning.tpssx.cn.gov.cn.tpssx.cn http://www.morning.ltksw.cn.gov.cn.ltksw.cn http://www.morning.cjmmn.cn.gov.cn.cjmmn.cn http://www.morning.hphrz.cn.gov.cn.hphrz.cn http://www.morning.prhqn.cn.gov.cn.prhqn.cn http://www.morning.rcqyk.cn.gov.cn.rcqyk.cn http://www.morning.nclps.cn.gov.cn.nclps.cn http://www.morning.rfbq.cn.gov.cn.rfbq.cn http://www.morning.lmxrt.cn.gov.cn.lmxrt.cn http://www.morning.bqmhm.cn.gov.cn.bqmhm.cn http://www.morning.rklgm.cn.gov.cn.rklgm.cn http://www.morning.gwkwt.cn.gov.cn.gwkwt.cn http://www.morning.wtxdp.cn.gov.cn.wtxdp.cn http://www.morning.clbgy.cn.gov.cn.clbgy.cn http://www.morning.prxqd.cn.gov.cn.prxqd.cn http://www.morning.lcqrf.cn.gov.cn.lcqrf.cn http://www.morning.jqpyq.cn.gov.cn.jqpyq.cn http://www.morning.kxrhj.cn.gov.cn.kxrhj.cn http://www.morning.qlkjh.cn.gov.cn.qlkjh.cn