本文实例为大家分享了C语言实现数字炸弹小游戏的具体代码,供大家参考,具体内容如下

使用的是C语言

# 内容

#include

#include

int main(){

//变量

char c_TheRequest = 1;//开始界面的字符

int in_Deltar = 1,in_EnteredNumber,in_Sig;//游戏中输入数字及其判定所需要的数字

int in_GivenNum = 0,in_An = 0,in_Bn = 0;//出的数字,和数字区间

int in_Mid1,in_Mid2;//用来交换An、Bn的值以满足An

int in_DistantAn,in_DistantBn;//An与Bn离num的距离

int in_TemporaryAnSaver,in_TemporaryBnSaver;//临时用于比较的An、Bn储存器

//开始界面

printf("If you just happen to open the game and do not have the intention to play it.

");

printf("You can enter a q to quit or you can enter an s to start the game now!

");

scanf("%c",&c_TheRequest);

getchar();

while (c_TheRequest != "s" && c_TheRequest != "q"){

printf("Please do not enter a irrelevant letter.

");

scanf("%c",&c_TheRequest);

getchar();

}

if(c_TheRequest == "q"){

printf("So sad then.Hope you can play with me next time.

");

getchar();

}

//游戏

if(c_TheRequest == "s"){

//输入“数字炸弹”

system("cls");

printf("(^ o ^) # *** NOW LET"S PLAY! *** # (^ o ^)

Attention!You can only enter numbers in the following steps.

Enter to start.

");

getchar();

system("cls");

printf("Game : The number boom!(Another Life.)

");

printf("Rule:

");

printf("The first player should enter a number.Then he should give to numbers and guarantee the number above is between them.

");

printf("The rest should guess and enter the numbers.And the one who enter the exact number the first player entered

");

printf("is supported to be the winner!

");

printf("Please Enter a number to start the game.(You is ought not to expose it to other players.The number should bigger than 0.)

");

printf("__________");

while(scanf("%d",&in_GivenNum) != 1 || in_GivenNum < 0){

system("cls");

printf("Please Enter a NUMBER which is bigger than 0.

");

printf("num:___________");

getchar();

}

system("cls");

//判定是否为数字

//输入“数字炸弹”所在的区间

printf("And where is the number?Please enter two numbers,and ensure that the number above is between them.

");

printf("Additionally,there should be at least 100 numbers between the two numbers you will enter.

");

do{

printf("num = %d

",in_GivenNum);

printf("A:__________");

while(scanf("%d",&in_An)!=1){

printf("Please Enter a NUMBER which is bigger or smaller than the "num"!!!!

");

printf("A:__________");

scanf("%d",&in_An);

getchar();

}

printf("B:__________");

while(scanf("%d",&in_Bn)!=1){

printf("Please Enter a NUMBER which is bigger or smaller than the "num"!!!!

");

printf("B:__________");

scanf("%d",&in_Bn);

getchar();

}//记录An和Bn

if(!(( in_An < in_GivenNum && in_Bn > in_GivenNum ) || ( in_An > in_GivenNum && in_Bn < in_GivenNum ))){

system("cls");

printf("Your math is so poor.Enter a again!

The "num" must be between the two numbers.

");

printf("Enter to restart.

");

getchar();

getchar();

system("cls");

}//区间如果错误就会报错

}while(!(( in_An < in_GivenNum && in_Bn > in_GivenNum ) || ( in_An > in_GivenNum && in_Bn < in_GivenNum )));//判定区间是不是对的

//排序

in_Mid1 = (in_An > in_Bn)?in_Bn : in_An;

in_Mid2 = (in_Bn > in_An)?in_Bn : in_An;

in_An = in_Mid1;

in_Bn = in_Mid2;

//开始猜数字

system("cls");

printf("Now the game starts!

");

printf("The number is somewhere between %d and %d

",in_An,in_Bn);

printf("Please enter the number.

");

printf("__________");

while(in_Deltar != 0){

while(scanf("%d",&in_EnteredNumber)!=1){

printf("Please Enter a NUMBER!!!!

");

scanf("%d",&in_EnteredNumber);

getchar();

}//判断是否为数字

//差的运算

in_Deltar = ((in_GivenNum - in_EnteredNumber)<0)?in_EnteredNumber - in_GivenNum:in_GivenNum - in_EnteredNumber;

in_Sig = in_GivenNum - in_EnteredNumber;

in_DistantAn = in_GivenNum - in_An;

in_DistantBn = in_Bn - in_GivenNum;

//判定差的大小

if(in_Deltar >= 1000){

if(in_Sig > 0)

printf("Too small!Next!

");

else

printf("Too big!Next!

");

}

else if(in_Deltar >= 100){

if(in_Sig > 0)

printf("Small.Next!

");

else

printf("Big.Next!

");

}

else if(in_Deltar >= 10){

if(in_Sig > 0)

printf("A little small.Next!

");

else

printf("A little big.Next!

");

}

else if(in_Deltar > 0){

printf("Almost there!NEXT!!!

");

}

//临时存储,以便后面判断所给数字是否满足条件

in_TemporaryAnSaver = in_An;

in_TemporaryBnSaver = in_Bn;

if(( in_Deltar < in_DistantAn && in_Sig > 0 ) || ( in_Deltar < in_DistantBn && in_Sig < 0 )){

if(in_Sig > 0)

in_An = in_EnteredNumber;

else

in_Bn = in_EnteredNumber;

}//这是修改上下限

if((in_TemporaryAnSaver == in_An && in_TemporaryBnSaver == in_Bn) && in_Deltar){

system("cls");

printf("Do not cheat!

You should play it again.

");

}//判定所猜的数字是否在区间内

if(in_Deltar == 0)

break;//猜中

printf("Enter to continue.

");

getchar();

getchar();

system ("cls");

printf("Between %d and %d

__________",in_An,in_Bn);//区间修正

}

printf("You are the one !!!");

getchar();

getchar();

}

}

总结

学习C的时候为了巩固所学知识而编得一个小游戏,内容全英文。

小编再为大家分享一段代码:

#define _CRT_SECURE_NO_WARNINGS 1

#include

#include

#include

#include

void menu()

{

printf("###########################

");

printf("### 1. play 0. exit ###

");

printf("###########################

");

}

void game()

{

//1.生成一个随机数

int ret = 0;

int guess = 0;

//拿时间戳来设置随机数的生成起点 //时间戳――(当前计算机的时间-计算机的起始时间(1970.1.1.0时0分0秒))=(xxxx)秒

//time_t

//srand((unsigned int)time(NULL));

ret=rand()%100+1; //生成随机数 0---0x7fff(32767)

//printf("%d

",ret);

//2.猜数字

while (1)

{

printf("请猜数字: ");

scanf("%d", &guess);

if (guess > ret)

{

printf("big

");

}

else if (guess < ret)

{

printf("small

");

}

else

{

printf("you are die

");

break;

}

}

}

int main()

{

int input = 0;

srand((unsigned int)time(NULL));

do

{

menu();

printf("请输入>:");

scanf("%d", &input);

switch (input)

{

case 1:

game();

break;

case 0:

printf("退出游戏

");

break;

default:

printf("输入错误

");

break;

}

} while (input);

return 0;

}

更多有趣的经典小游戏实现专题,分享给大家:

C++经典小游戏汇总

python经典小游戏汇总

python俄罗斯方块游戏集合

JavaScript经典游戏 玩不停

java经典小游戏汇总

javascript经典小游戏汇总

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持云海天教程。

原文链接:https://blog.csdn.net/m0_52352462/article/details/109690588

c语言编程数字炸弹,C语言实现数字炸弹小游戏相关推荐

  1. c语言编程模拟选举,C语言编程题精选

    C语言编程题精选 C语言编程题精选 1. 编程实现对键盘输入的英文名句子进行加密.用加密方法为,当内容为英文字母时其在26字母中的其后三个字母代替该字母,若为其它字符时不变. 2. 编程实现将任意的十 ...

  2. 成都c语言编程培训机构,成都学c语言编程,成都学c语言编程去哪里,成都学c语言编程需要报培训班吗...

    成都学c语言编程,成都学c语言编程去哪里,成都学c语言编程需要报培训班吗 首页 > 软件 > 成都学c语言编程 作者:镀金池   发布时间:2018-09-28 14:20 近似带有序布局 ...

  3. 罗定c语言,罗定学c语言编程,罗定学c语言编程培训,罗定学c语言编程一般怎么收费...

    罗定学c语言编程,罗定学c语言编程培训,罗定学c语言编程一般怎么收费 首页 > 软件 > 罗定学c语言编程 作者:镀金池   发布时间:2018-10-04 23:40 依照c语言的法则, ...

  4. c语言编程技巧分析,C语言难点及编程技巧分析

    摘要:近些年信息技术发展迅速,社会需要大量专业的计算机人才,C语言是学习计算机知识的专业理论课程,能够为以后的学习打下专业基础.但目前C语言学习受到各方面因素的影响,学习效果不是很理想,很多时候即使努 ...

  5. 单片机c语言编程下载,单片机C语言编程.doc

    单片机C语言编程.doc 单片机C语言编程指令格式 功能简述 字节数 周期 一.数据传送类指令 MOV A, Rn 寄存器送累加器 1 1 MOV Rn,A 累加器送寄存器 1 1 MOV A ,Ri ...

  6. 基于C语言Ncurse库和链表的简单贪吃蛇小游戏

    参考:基于C语言Ncurse库和链表的简单贪吃蛇小游戏 作者:三速何时sub20 发布时间:2020-09-29 10:23:51 网址:https://blog.csdn.net/weixin_44 ...

  7. Python数字华容道--程序实现的创意数学小游戏

    下载链接:Python数字华容道--程序实现的创意数学小游戏-Python文档类资源-CSDN下载 当前的数学教育环境下,更强调的是数学素养的提升,本程序提供了一个免费的数学益智小游戏的学习和训练平台 ...

  8. c语言编程题总结,c语言编程题总结

    c语言编程题总结 1.求100之内自然数中最大的能被17整除的数. 2.已知a,b,c都是1位整数,求当三位整数abc.cba的和为1333时a.b.c的值. 3.计算并输出200-400之间不能被3 ...

  9. 的c语言编程函数题,C语言编程题及答案Word版

    <C语言编程题及答案Word版>由会员分享,可在线阅读,更多相关<C语言编程题及答案Word版(122页珍藏版)>请在人人文库网上搜索. 1.传播优秀Word版文档 ,希望对您 ...

  10. c语言编程560分钟,c语言把560分钟换成小时和分钟表示输出出来

    咋把度换成分,分换成秒, 度*60=分分*60=秒比如10°30′20"减去8°40′50"就等于1°49′30"再问:那是乘还是除 如何把数字换成时间请问WPS表格中如 ...

最新文章

  1. 取景框图片 小程序_敲敲级简单的鉴别H图片的小程序
  2. 【转载】c#多线程使用webbrowser控件
  3. ubuntu 安装星际译王词典
  4. 工作171:阅读账号里面的新增调用接口操作
  5. 跨境电商为什么需要ERP系统?
  6. 福布斯牛人×××先生的两个概念
  7. 一个Lumen多层拆分手记
  8. vagrant 错误记录
  9. hadoop jar 找不到main class_10年老架构,教你HadoopJob使用第三方依赖jar文件,不来就后悔吧...
  10. android视频实时编辑器,视频编辑器app下载
  11. echarts设置主标题和副标题样式
  12. Python3的Counter类
  13. 深蓝代表的计算机应用领域是,2002年10月高等教育自学考试计算机应用基础
  14. 我的世界服务器怎么用系统说话,我的世界语音聊天Mod安装使用教程_我的世界语音聊天Mod怎么安装使用_玩游戏网...
  15. Git服务器搭建及仓库克隆
  16. 【C++实训】基于MVC模型开发的高校教务管理系统【附完整报告+示例程序+日记+源码】
  17. ERROR [KafkaApi-1] Number of alive brokers ‘1‘ does not meet the required replication factor ‘2‘ for
  18. Binary Particle Swarm Optimization(BPSO) for Feature Selection(二进制粒子群求解特征选择)
  19. 算法笔记_227:填写乘法算式(Java)
  20. ggbiplot | 带箭头的主成分分析(PCA)图绘制

热门文章

  1. windows python文件拷贝到linux上执行问题
  2. 禁止浏览器记录 文本框之前输入过的内容
  3. 黑马程序员-学习日记(单例设计模式的两种类型)
  4. html中给select下拉框赋值
  5. [DesignPattern]各自用一句话来概括MVC、MVP、MVVM的差异特点
  6. Atlas Resources
  7. FPGA BCD计数器(一位)
  8. ae合成复制脚本_【脚本】AE脚本精选系列 | 合成复制脚本 True Comp Duplicator v3.9.7...
  9. java 日食,如何更新Java构造函数,等于,哈希等。在日食?
  10. python3 字符串编解码和UnicodeDecodeError