声明:因本人为非科班转码,个人水平有限,博客中难免有不准确之处,如有读者发现,本人恳请大家积极指出,本人也想知道自己的错误在哪里。欢迎大家一起指正,共同进步。
- 联系方式:3146367553@qq.com
想直接看源代码的小可爱可以直接跳转至3.源代码。
目录
1.程序功能大致描述
由系统生成1-100的随机数(整型),由玩家在键盘上进行猜测,玩家无论猜大猜小电脑都会告知你,如果猜对了会恭喜你。同时,玩家可以在玩游戏的中途退出游戏。个人设置了简单和困难两种模式可以选择。
2.代码编写思路分析
2.1 整体框架分析
①首先,我们可以联系一下以前打过的小游戏(不是小游戏也可以),我们是不是进入游戏会有一个开始游戏和退出游戏的选项?点击屏幕其他部分是不是没有反应?因此,我们可以设立一个主菜单函数,打印游戏界面(因为界面可能不止见到一次)。同时,我们站在玩家的角度想一想,我们是不是有很大概率猜对了一把还想猜测的欲望,直到自己不想打就退出游戏?因此,游戏刚开始的选择是否游戏其实很符合循环。另外,用户第一次进游戏肯定得选择,小可爱,你说是不是?