⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gussnum2.cpp

📁 猜数字很好玩的大家去
💻 CPP
字号:
#include<iostream.h>
#include<stdlib.h>
#include<time.h>
#include<conio.h>

void menu()
 {
  clrscr();
  cout <<endl<<endl<<endl;
  cout <<"       ==========================================================\n";
  cout <<"       $         1.)About This Game.                            $\n";
  cout <<"       $         2.)Play Game.                                  $\n";
  cout <<"       $         3.)Show Love.                                  $\n";
  cout <<"       $         4.)Quit Game.                                  $\n";
  cout <<"       ==========================================================\n";
  cout <<"\n\nPlease enter your choice:";
 }

void game_intro()
 {
  char choice;
  clrscr();
  cout <<endl<<endl<<endl<<endl<<endl;
  cout <<"       * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n";
  cout <<"       *                                                         *\n";
  cout <<"       *                       *|WELCOME!|*                      *\n";
  cout <<"       *                                                         *\n";
  cout <<"       *               MADE BY ERIC CHENG  VERSION 1.0           *\n";
  cout <<"       *                                                         *\n";
  cout <<"       *        COPYRIGHT (C)2004 ERICTY ALL RIGHT RESERVED      *\n";
  cout <<"       *                                                         *\n";
  cout <<"       *                  MADE IN 3rd MARCH 2004                 *\n";
  cout <<"       *                                                         *\n";
  cout <<"       * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n\n";
  cout <<"Enter'B' to back to main menu, 'Q' to quit.";
  cin >>choice;
  switch(choice)
   {
    case 'b':
    case 'B': break;
    case 'q':
    case 'Q': exit(0);
    default: break;
   }
}

void print_heart(void)
 {
  clrscr();
  char choice;
  cout <<"                           "<<"  **   ** **   **   "<<endl;
  cout <<"                         "<<"\x11  *  * *  *  * *  *     ( "<<endl;
  cout <<"                        "<<"\x11\x11\x2\x2\x2\x2\x2\x2\x2\x2\x2\x2\x2\x2\x2\x2\x2\x2\x2\x2\x2\x2\x2\x2\x2((   "<<endl;
  cout <<"                         "<<"\x11  .*     * *     *.     ( "<<endl;
  cout <<"                           "<<"   *   *   *   *    "<<endl;
  cout <<"                           "<<" .  * *     * *  .  "<<endl;
  cout <<"                           "<<"     *       *      "<<endl;
  cout <<"                           "<<" ^               ^  "<<endl;
  cout <<"               "<<" ########################################## "<<endl;
  cout <<"               "<<"#                                          #"<<endl;
  cout <<"               "<<"#   @@  \xb\xb\xb   @@@   @       @  @@@@@@@@    #"<<endl;
  cout <<"               "<<"#   @@ \xb     @   @  @@     @@ @@           #"<<endl;
  cout <<"               "<<"#   @@ \xb Y  @@   @@ @@     @@ @@           #"<<endl;
  cout <<"               "<<"#   @@ \xb    @@   @@ @@     @@ @@           #"<<endl;
  cout <<"               "<<"#   @@  \xb\xb\xb @@   @@ @@     @@ @@@@@@@@@    #"<<endl;
  cout <<"               "<<"#   @@      @@   @@ @@     @@ @@ \xc   \xc     #"<<endl;
  cout <<"               "<<"#   @@      @@   @@ @@     @@ @@  \xc \xc      #"<<endl;
  cout <<"               "<<"#   @@      @@   @@  @@   @@  @@   \xc       #"<<endl;
  cout <<"               "<<"#   @@      @@   @@   @@ @@   @@  \xc \xc      #"<<endl;
  cout <<"               "<<"#   @@       @   @     @@@    @@ \xc J \xc     #"<<endl;
  cout <<"               "<<"#    @@@@@@@  @@@       @      @@@@@@@@@   #"<<endl;
  cout <<"               "<<"#                  \xb \xc                     #"<<endl;
  cout <<"               "<<"#                                          #"<<endl;
  cout <<"               "<<" ##########################################" <<endl;
  cout <<"      Enter'B' to back to main menu, 'Q' to quit.";
  cin >>choice;
  switch(choice)
   {
    case 'b':
    case 'B': break;
    case 'q':
    case 'Q': exit(0);
    default: break;
   }
 }

void play_game();

void main()
 {
  char choice;
  while(1)
   {
    menu();
    cin >>choice;
    switch(choice)
     {
      case '1': game_intro();break;
      case '2': play_game();break;
      case '3': print_heart();break;
      case 'q':
      case 'Q':
      case '4': exit(0);break;
      default: break;
     }
   }
 }

void play_game()
 {
  int game_win=0,flag;
  int h,i,j,k,countA[8],countB[8];
  int number[8][4],pasd[4];
  unsigned seed=time(NULL);
  void dis_resl(int,int,int,int num[]);
  void choice(void);
  cout <<endl;
  srand(seed);
  clrscr();
  cout <<"\n\nPlease input four different numbers.(0-9)\n\n";
  for(i=0;i<4;i++)
   {
    flag=1;
    while(flag)
     {
      cout <<"NUMBER["<<i+1<<"]:";
      cin >>number[0][i];
      switch(i)
       {
	case 0: flag=0;break;
	case 1: if((number[0][i]!=number[0][i-1])||(!number[0][i]))
		 flag=0;break;
	case 2: if(((number[0][i]!=number[0][i-1])
		 &&(number[0][i]!=number[0][i-2]))||(!number[0][i]))
		 flag=0;break;
	case 3: if(((number[0][i]!=number[0][i-1])
		 &&(number[0][i]!=number[0][i-2])
		 &&(number[0][i]!=number[0][i-3]))||(!number[0][i]))
		 flag=0;break;
       }
      if(flag)
       {
	cout <<"INPUT ERROR!"<<endl;
	cout <<"Please input number again."<<endl;
       }
     }
     pasd[i]=rand()/100%10;
     switch(i)
      {
       case 1:while(pasd[i]==pasd[i-1])
		pasd[i]=rand()/100%10;break;
       case 2:while((pasd[i]==pasd[i-1])||(pasd[i]==pasd[i-2]))
		pasd[i]=rand()/100%10;break;
       case 3:while((pasd[i]==pasd[i-1])||(pasd[i]==pasd[i-2])||(pasd[i]==pasd[i-3]))
		pasd[i]=rand()/100%10;break;
      }
   }
  for(i=0;i<8;i++)
   {
    if((!number[i][0])
     &&(!number[i][1])
     &&(!number[i][2])
     &&(!number[i][3]))
     {i=8;break;}
    clrscr();
    countA[i]=0;countB[i]=0;
    for(j=0;j<4;j++)
     {
      for(k=0;k<4;k++)
       {
	if((j==k)&&(pasd[j]==number[i][k]))
	 countA[i]++;
	else if(pasd[j]==number[i][k])
	 countB[i]++;
       }
     }
    if(countA[i]==4)
     {
      cout <<"\n\nCONGRATULATION!YOU WIN!\n"<<endl;
      game_win=1;
      choice();
      break;
     }
    else
     {
      for(h=0;h<=i;h++)
	dis_resl(h,countA[h],countB[h],number[h]);
      cout <<"You have "<<8-i-1<<" times left!\n";
      if(8-i-1)
       {
	cout <<"Please input four numbers again.\n";
	for(h=0;h<4;h++)
	 {
	  flag=1;
	  while(flag)
	   {
	    cout <<"NUMBER["<<h+1<<"]:";
	    cin >>number[i+1][h];
	    switch(h)
	     {
	      case 0: flag=0;break;
	      case 1: if((number[i+1][h]!=number[i+1][h-1])
		      ||(!number[i+1][h]))
		       flag=0;break;
	      case 2: if(((number[i+1][h]!=number[i+1][h-1])
		       &&(number[i+1][h]!=number[0][h-2]))
		       ||(!number[i+1][h]))
		       flag=0;break;
	      case 3: if(((number[i+1][h]!=number[i+1][h-1])
			&&(number[i+1][h]!=number[i+1][h-2])
			&&(number[i+1][h]!=number[i+1][h-3]))
			||(!number[i+1][h]))
		       flag=0;break;
	     }
	    if(flag)
	     {
	     cout <<"INPUT ERROR!"<<endl;
	     cout <<"Please input number again."<<endl;
	     }
	   }
	 }
       }
      }
   }
  if(!(8-i)&&!game_win)
   {
    cout <<"\n\nSORRY! YOU LOSE. THE NUMBERS ARE:\n\n";
    for(h=0;h<4;h++)
     cout <<"     "<<pasd[h];
    cout <<endl;
    choice();
   }
 }

void dis_resl(int i,int a,int b,int num[])
 {
  int h;
  cout <<i+1<<".)"<<a<<"A"<<b<<"B         ";
  for(h=0;h<4;h++)
   cout <<num[h]<<" ";
  cout <<endl;
 }

void choice(void)
 {
  char choice;
  cout <<"Enter 'B' to Back main menu, 'C' to Continue, 'Q' to Quit.";
  cin >>choice;
  switch(choice)
   {
    case 'b':
    case 'B': break;
    case 'c':
    case 'C': play_game();break;
    case 'q':
    case 'Q': exit(0);break;
    default: break;
   }
 }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -