程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C >> C語言基礎知識 >> 猜數游戲

猜數游戲

編輯:C語言基礎知識
  /*猜數游戲*/
         /*程序產生一個隨機數,游戲者輸入數據進行猜測。治理員可輸入密碼,
         其中普通治理員只能獲得答案,超級治理員獲得答案並能修改普通治理員密碼*/
          #include<stdio.h>
          #include<stdlib.h>
          #include<time.h>
          
          #define NO 0
          #define YES 1
          #define QU99v -1
          #define EASY 1
          #define COMMON 2
          #define HARD 3
          #define PASSWord2 -111111 /*超級治理員密碼,不可修改*/
        
           char *PasswordName= "LiangJianbin";/*超級治理員確認密碼,不可修改*/
           int Password1 =111111 ;  /*普通治理員密碼,可修改*/
           int number;       /*計算機產生的隨機數*/
           int guess_value=0; /*游戲者輸入的猜測數*/
           int nbr_of_guesses=0;/*累加游戲者猜測的次數*/
           int done=0;  /*標記游戲者是否猜對,若猜對則  done=1*/
       
       
          void the_back_door(int password,int answer);  /*開個後門好作弊,判定普通或超級治理員*/
          void super_Adm_menu(int answer); /*超級治理員選擇菜單*/
          void game_introdUCtion(void);/*游戲介紹,選擇游戲級別或退出*/
          void quit_or_not(void);    /*確認是否退出*/
          void change_password(int answer);/*修改普通治理員密碼*/
          void input_data(void);/*輸入數據或退出,治理員可輸入密碼*/
          void congratulate(void) ;  /*祝賀猜對並問是否繼續*/
          int judge(void);/*判定數據是否正確*/
          void enter_password_name(char *true_password);/*確認超級治理員*/  
          
          int main(void)
          {
              game_introduction();/*游戲介紹,選擇游戲級別或退出*/
              system("pause");
              return 0;
               
           }    
                  
              
       void game_introduction(void)/*游戲介紹,選擇游戲級別或退出*/
       {
              int selection;
              int flag=0;/*循周游戲介紹標志,選擇游戲級別或退出後flag=1,循環結束*/  
              do
              {
                  nbr_of_guesses=0;
                  puts("This is a guess number game.You can input a number to guess.");
                  
                  do
                  {
                        puts(" 1--Get a easy degree.");
                        puts(" 2--Get a common degree.");
                        puts(" 3--Get a hard  degree.");
                        puts(" -1--Quit the game.");
                        puts(" Enter a selection.");
                  
                        scanf("%d",&selection);
                 }while(selection!=-1&&selection<1selection>3);
              
                 if(selection==EASY)
                 {
                       printf(" Getting a Random number ");
                      /*產生隨機數*/
                      srand( (unsigned) time(NULL));
                      number=rand();
                      flag=1;
                 }
                 else if  (selection==COMMON)
                 {
             
                      printf(" Getting a Random number ");
                      /*產生隨機數*/
                      srand( (unsigned) time(NULL));
   &nb
  
 
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved