C语言编程轰炸,C语言实现数字炸弹小游戏
本文实例为大家分享了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.\n");
printf("you can enter a q to quit or you can enter an s to start the game now!\n");
scanf("%c",&c_therequest);
getchar();
while (c_therequest != 's' && c_therequest != 'q'){
printf("please do not enter a irrelevant letter.\n");
scanf("%c",&c_therequest);
getchar();
}
if(c_therequest == 'q'){
printf("so sad then.hope you can play with me next time.\n");
getchar();
}
//游戏
if(c_therequest == 's'){
//输入“数字炸弹”
system("cls");
printf("(^ o ^) # *** now let\'s play! *** # (^ o ^)\nattention!you can only enter numbers in the following steps.\nenter to start.\n");
getchar();
system("cls");
printf("game : the number boom!(another life.)\n");
printf("rule:\n");
printf("the first player should enter a number.then he should give to numbers and guarantee the number above is between them.\n");
printf("the rest should guess and enter the numbers.and the one who enter the exact number the first player entered\n");
printf("is supported to be the winner!\n");
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.)\n");
printf("__________\b\b\b\b\b\b\b\b\b\b\b");
while(scanf("%d",&in_givennum) != 1 || in_givennum < 0){
system("cls");
printf("please enter a number which is bigger than 0.\n");
printf("num:___________\b\b\b\b\b\b\b\b\b\b\b");
getchar();
}
system("cls");
//判定是否为数字
//输入“数字炸弹”所在的区间
printf("and where is the number?please enter two numbers,and ensure that the number above is between them.\n");
printf("additionally,there should be at least 100 numbers between the two numbers you will enter.\n");
do{
printf("num = %d\n",in_givennum);
printf("a:__________\b\b\b\b\b\b\b\b\b\b");
while(scanf("%d",&in_an)!=1){
printf("please enter a number which is bigger or smaller than the \"num\"!!!!\n");
printf("a:__________\b\b\b\b\b\b\b\b\b\b");
scanf("%d",&in_an);
getchar();
}
printf("b:__________\b\b\b\b\b\b\b\b\b\b");
while(scanf("%d",&in_bn)!=1){
printf("please enter a number which is bigger or smaller than the \"num\"!!!!\n");
printf("b:__________\b\b\b\b\b\b\b\b\b\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!\nthe \"num\" must be between the two numbers.\n");
printf("enter to restart.\n");
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!\n");
printf("the number is somewhere between %d and %d\n",in_an,in_bn);
printf("please enter the number.\n");
printf("__________\b\b\b\b\b\b\b\b\b\b");
while(in_deltar != 0){
while(scanf("%d",&in_enterednumber)!=1){
printf("please enter a number!!!!\n");
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!\n");
else
printf("too big!next!\n");
}
else if(in_deltar >= 100){
if(in_sig > 0)
printf("small.next!\n");
else
printf("big.next!\n");
}
else if(in_deltar >= 10){
if(in_sig > 0)
printf("a little small.next!\n");
else
printf("a little big.next!\n");
}
else if(in_deltar > 0){
printf("almost there!next!!!\n");
}
//临时存储,以便后面判断所给数字是否满足条件
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!\nyou should play it again.\n");
}//判定所猜的数字是否在区间内
if(in_deltar == 0)
break;//猜中
printf("enter to continue.\n");
getchar();
getchar();
system ("cls");
printf("between %d and %d\n__________\b\b\b\b\b\b\b\b\b\b",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("###########################\n");
printf("### 1. play 0. exit ###\n");
printf("###########################\n");
}
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\n",ret);
//2.猜数字
while (1)
{
printf("请猜数字: ");
scanf("%d", &guess);
if (guess > ret)
{
printf("big\n");
}
else if (guess < ret)
{
printf("small\n");
}
else
{
printf("you are die\n");
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("退出游戏\n");
break;
default:
printf("输入错误\n");
break;
}
} while (input);
return 0;
}
更多有趣的经典小游戏实现专题,分享给大家:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持萬仟网。
C语言编程轰炸,C语言实现数字炸弹小游戏相关推荐
- python数字炸弹小游戏
数字炸弹小游戏就是给定一个数字范围,然后在范围内进行数字猜测,不断更新范围的界限,直到有人猜中随机生成的数字结束游戏. 因为需要不断地进行循环,所以采用while语句根据猜的数不断更新值,并循环执行, ...
- Python数字炸弹小游戏代码
#Python数字炸弹小游戏代码 import random import time bomb = random.randint(1, 99) print(bomb) start = 0 end = ...
- [C]数字炸弹小游戏
数字炸弹 使用的是C语言 # 内容 #include<stdio.h> #include<stdlib.h> int main(){//变量char c_TheRequest ...
- c语言中求匀加速直线速度,速求C语言编程题 c语言编程速度求
导航:网站首页 > 速求C语言编程题 c语言编程速度求 速求C语言编程题 c语言编程速度求 相关问题: 匿名网友: #include //计算行元素和 void CountRow(int a[] ...
- c语言设置一个选择数字的程序,C语言编一个数字益智小游戏
程序功能及运行情况 设计的程序是一个数字益智游戏,旨在培养小朋友玩家的数学思维,提高玩家的数学能力.游戏共设有四个不同的小游戏,分别是一位数四则运算.两位数四则运算.找最值游戏.排序游戏.程序能实现产 ...
- C语言:数字益智小游戏
程序功能及运行情况 设计的程序是一个数字益智游戏,旨在培养小朋友玩家的数学思维,提高玩家的数学能力.游戏共设有四个不同的小游戏,分别是一位数四则运算.两位数四则运算.找最值游戏.排序游戏.程序能实现产 ...
- c语言编程心得,C语言编程心得
记录这些是为了日后自己想查阅以前经验的方便,同时若能给其他网友带来一些帮助,就更好了~ C语言,自己经常遇到的问题: 1.段错误 段错误一般是由于访问了不存在的地址造成的,具体的原因有文件路径不存在, ...
- C语言开发数字华容道实现,jQuery实现数字华容道小游戏(实例代码)
数字华容道 *{ padding: 0px; margin: 0px; } #btns>button{ width: 100px; height: 30px; border: none; bac ...
- 使用Dart/Flutter语言开发的命令行文字RPG类型小游戏
使用Dart/Flutter语言开发的命令行文字RPG类型小游戏 项目源码:https://gitee.com/FantasyWind/word_game 介绍 项目背景 本项目为使用Dart/Flu ...
- 玩一个猜数字的小游戏吧
前言 大家一定都在聚会中玩过一个猜数字的小游戏吧? 就是主持人写下一个数字,在100以内,然后呢,大家就开始猜,每当一个人说出一个数字,主持人就说太大或者太小,然后慢慢的缩小范围,最后说对的人要接受惩 ...
最新文章
- linux apache 手动安装教程,linux下手动安装apache
- 关于ping telnet
- python封装api给vue_vue的封装
- Linux文件目录类命令
- 灯泡四个闪烁c语言程序设计教程课后答案,c语言编程题及答案4.doc
- linux下清空c++ cin无效流的方式
- 接口中的成员只有静态常量和什么_为什么阿里工程师代码写的好?看看他的代码规范就知道了...
- sublime3 ctrl+shift+p没用_电脑键盘上的Ctrl指的是啥英文?Alt,Tab又是什么?
- cadence SPB16.6原理图库(.olb)集合的库内容列表2
- 计算机熵的定义是,信息熵
- java软件开发是什么_java常用的开发软件是什么
- copy 复制文件夹目录下所有文件,包括子目录 (新思路)
- Tempo超进化,提效降本好帮手,工时管理小当家 Timewise
- 树梅派应用27:通过USB蓝牙适配器连接BLE设备
- robots文件简介
- commons-cli使用介绍
- 适合学生党的蓝牙耳机选哪个?学生党最爱的几款蓝牙耳机
- VC中画基准线,随鼠标移动
- PC端如何使用ADB无线连接Android手机
- CCNA-应试教育-思科网院-CCNAv7: Switching, Routing, and Wireless Essentials 交换、路由和无线基础。
热门文章
- fft算法matlab程序,FFT算法(用matlab实现).doc
- Head First设计模式(中文版)PDF
- 计算机组成原理知识体系
- 使用foobar2000将cue文件分割wav、ape、flac无损音乐
- 逆向脱壳附加数据处理
- Centos7搭建coreseek
- C#旅程——ListView控件使用
- 高德地图No implementation found for long com.autonavi.amap.mapcore.MapCore
- 【历史上的今天】8 月 24 日:Windows 95问世;乔布斯辞任苹果 CEO 库克上台
- [vue] 混入+替换对应文字实现简繁切换