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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

C语言编程轰炸,利用C语言编写一个数字炸弹小游戏

發(fā)布時間:2023/12/10 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C语言编程轰炸,利用C语言编写一个数字炸弹小游戏 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

利用C語言編寫一個數(shù)字炸彈小游戲

發(fā)布時間:2020-11-30 15:57:34

來源:億速云

閱讀:173

作者:Leah

這篇文章將為大家詳細(xì)講解有關(guān)利用C語言編寫一個數(shù)字炸彈小游戲,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。

具體內(nèi)容如下#?內(nèi)容

#include

#include

int?main(){

//變量

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

int?in_Deltar?=?1,in_EnteredNumber,in_Sig;//游戲中輸入數(shù)字及其判定所需要的數(shù)字

int?in_GivenNum?=?0,in_An?=?0,in_Bn?=?0;//出的數(shù)字,和數(shù)字區(qū)間

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'){

//輸入“數(shù)字炸彈”

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?

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");

//判定是否為數(shù)字

//輸入“數(shù)字炸彈”所在的區(qū)間

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_An?>?in_GivenNum?&&?in_Bn?

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");

}//區(qū)間如果錯誤就會報錯

}while(!((?in_An??in_GivenNum?)?||?(?in_An?>?in_GivenNum?&&?in_Bn?

//排序

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;

//開始猜數(shù)字

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();

}//判斷是否為數(shù)字

//差的運(yùn)算

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");

}

//臨時存儲,以便后面判斷所給數(shù)字是否滿足條件

in_TemporaryAnSaver?=?in_An;

in_TemporaryBnSaver?=?in_Bn;

if((?in_Deltar??0?)?||?(?in_Deltar?

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");

}//判定所猜的數(shù)字是否在區(qū)間內(nèi)

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);//區(qū)間修正

}

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

getchar();

getchar();

}

}

總結(jié)

學(xué)習(xí)C的時候為了鞏固所學(xué)知識而編得一個小游戲,內(nèi)容全英文。

小編再為大家分享一段代碼:#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.生成一個隨機(jī)數(shù)

int?ret?=?0;

int?guess?=?0;

//拿時間戳來設(shè)置隨機(jī)數(shù)的生成起點??//時間戳——(當(dāng)前計算機(jī)的時間-計算機(jī)的起始時間(1970.1.1.0時0分0秒))=(xxxx)秒

//time_t

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

ret=rand()%100+1;?//生成隨機(jī)數(shù)?0---0x7fff(32767)

//printf("%d\n",ret);

//2.猜數(shù)字

while?(1)

{

printf("請猜數(shù)字:?");

scanf("%d",?&guess);

if?(guess?>?ret)

{

printf("big\n");

}

else?if?(guess?

{

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;

}

關(guān)于利用C語言編寫一個數(shù)字炸彈小游戲就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

總結(jié)

以上是生活随笔為你收集整理的C语言编程轰炸,利用C语言编写一个数字炸弹小游戏的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。