日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

C语言编程轰炸,C语言实现数字炸弹小游戏

發布時間:2023/12/10 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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语言实现数字炸弹小游戏的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。