欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C語言實(shí)現(xiàn)數(shù)字炸彈小游戲

 更新時(shí)間:2020年11月27日 16:35:47   作者:m0_52352462  
這篇文章主要為大家詳細(xì)介紹了C語言實(shí)現(xiàn)數(shù)字炸彈小游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了C語言實(shí)現(xiàn)數(shù)字炸彈小游戲的具體代碼,供大家參考,具體內(nèi)容如下

使用的是C語言

# 內(nèi)容
#include<stdio.h>
#include<stdlib.h>
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<Bn的中間量
 int in_DistantAn,in_DistantBn;//An與Bn離num的距離
 int in_TemporaryAnSaver,in_TemporaryBnSaver;//臨時(shí)用于比較的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 < 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");
 //判定是否為數(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_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");
  }//區(qū)間如果錯(cuò)誤就會報(bào)錯(cuò)
 }while(!(( in_An < in_GivenNum && in_Bn > in_GivenNum ) || ( in_An > in_GivenNum && in_Bn < in_GivenNum )));//判定區(qū)間是不是對的

 //排序
 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í)存儲,以便后面判斷所給數(shù)字是否滿足條件
  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");
  }//判定所猜的數(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的時(shí)候?yàn)榱遂柟趟鶎W(xué)知識而編得一個(gè)小游戲,內(nèi)容全英文。

小編再為大家分享一段代碼:

#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#include<Windows.h>
#include<time.h>
void menu()
{
 printf("###########################\n");
 printf("### 1. play 0. exit ###\n");
 printf("###########################\n");
}
void game()
{
 //1.生成一個(gè)隨機(jī)數(shù)
 int ret = 0;
 int guess = 0;
 //拿時(shí)間戳來設(shè)置隨機(jī)數(shù)的生成起點(diǎn)  //時(shí)間戳——(當(dāng)前計(jì)算機(jī)的時(shí)間-計(jì)算機(jī)的起始時(shí)間(1970.1.1.0時(shí)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 < 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("輸入錯(cuò)誤\n");
 break;
 }
 } while (input);
 return 0;
}

更多有趣的經(jīng)典小游戲?qū)崿F(xiàn)專題,分享給大家:

C++經(jīng)典小游戲匯總

python經(jīng)典小游戲匯總

python俄羅斯方塊游戲集合

JavaScript經(jīng)典游戲 玩不停

java經(jīng)典小游戲匯總

javascript經(jīng)典小游戲匯總

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • C++學(xué)習(xí)筆記之pimpl用法詳解

    C++學(xué)習(xí)筆記之pimpl用法詳解

    在編寫穩(wěn)定代碼是,管理好代碼間的依賴性是不可缺少的一個(gè)環(huán)節(jié)。特別是庫文件的編寫中,減少代碼間的依賴性可以提供一個(gè)“干凈”的接口。下面這篇文章主要給大家介紹了關(guān)于C++中pimpl用法的相關(guān)資料,需要的朋友可以參考下。
    2017-08-08
  • C語言實(shí)現(xiàn)一個(gè)多線程委托模型的示例詳解

    C語言實(shí)現(xiàn)一個(gè)多線程委托模型的示例詳解

    這篇文章主要介紹了C語言實(shí)現(xiàn)一個(gè)多線程委托模型,這就是一個(gè)使用C語言實(shí)現(xiàn)多線程委托模型的例子,其中包含boss線程和worker線程,可以處理工作線程的異常情況,需要的朋友可以參考下
    2023-06-06
  • C++實(shí)現(xiàn)LeetCode(79.詞語搜索)

    C++實(shí)現(xiàn)LeetCode(79.詞語搜索)

    這篇文章主要介紹了C++實(shí)現(xiàn)LeetCode(79.詞語搜索),本篇文章通過簡要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-07-07
  • c++ 頭文件<cwchar>中常見函數(shù)的實(shí)現(xiàn)代碼

    c++ 頭文件<cwchar>中常見函數(shù)的實(shí)現(xiàn)代碼

    本文記錄了c++ 頭文件<cwchar>中常見函數(shù)的實(shí)現(xiàn),本文結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧
    2023-12-12
  • 融會貫通C++智能指針教程

    融會貫通C++智能指針教程

    本文主要介紹了c++的基礎(chǔ)知識,通過不帶引用計(jì)數(shù)的只能指針和帶引用的智能指針,shared_ptr和weak_ptr,多線程訪問共享對象的線程安全問題以及自定義刪除器作了詳細(xì)的分析解答
    2021-08-08
  • C++ OpenCV實(shí)現(xiàn)圖像去水印功能

    C++ OpenCV實(shí)現(xiàn)圖像去水印功能

    本文將介紹如何使用OpenCV C++ 進(jìn)行簡單圖像水印去除。我們在網(wǎng)上download圖片時(shí),經(jīng)常因?yàn)榘鏅?quán)問題有水印。本案例通過編寫算法進(jìn)行簡單水印去除。需要的可以參考一下
    2022-01-01
  • C++ AVLTree高度平衡的二叉搜索樹深入分析

    C++ AVLTree高度平衡的二叉搜索樹深入分析

    這篇文章主要介紹了C++ AVLTree高度平衡的二叉搜索樹,二叉搜索樹雖可以縮短查找的效率,但如果數(shù)據(jù)有序或接近有序二叉搜索樹將退化為單支樹,查找元素相當(dāng)于在順序表中搜索元素,效率低下
    2023-03-03
  • C++語言編寫寫日志類

    C++語言編寫寫日志類

    這篇文章主要介紹了C++語言編寫寫日志類的相關(guān)資料,支持寫日志級別設(shè)置、支持多線程、支持可變形參表寫日志,需要的朋友可以參考下
    2015-12-12
  • c語言中assert斷言用法實(shí)例詳解

    c語言中assert斷言用法實(shí)例詳解

    斷言是C語言中一種用于檢查程序中假設(shè)語句正確性的方法,通過使用斷言,開發(fā)人員可以在程序中插入一些條件,以確保程序的執(zhí)行滿足特定的預(yù)期,這篇文章主要給大家介紹了關(guān)于c語言中assert斷言用法的相關(guān)資料,需要的朋友可以參考下
    2024-02-02
  • C++?分割字符串?dāng)?shù)據(jù)的實(shí)現(xiàn)方法

    C++?分割字符串?dāng)?shù)據(jù)的實(shí)現(xiàn)方法

    這篇文章主要介紹了C++?分割字符串?dāng)?shù)據(jù)的實(shí)現(xiàn)方法,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-09-09

最新評論