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

📄 readme.txt

📁 猜数字很好玩的大家去
💻 TXT
字号:
游戏说明:
    本游戏是用C++编辑的,整个游戏从构想到完成用了一周左右的时间。

  在运行本程序时,会有一个主菜单:
                 ==========================================================
                 $         1.)About This Game.                            $
                 $         2.)Play Game.                                  $
                 $         3.)Show Love.                                  $
                 $         4.)Quit Game.                                  $
                 ==========================================================
  下面会有提示让你作出选择:输入1,然后回车(回车是执行明令的按键),屏幕输出本程序的相关信息。
                            输入2,然后回车,开始游戏。
                            输入3, 
                            输入3,然后回车,则会退出游戏。
游戏规则说明:
         
   游戏开始时,电脑会自动生成4个1~9之间不同的随机数,然后让你来猜出这4个数(按提示用键盘输入4个数共有
8次机会),你猜出的4个数应和电脑生成的4个数顺序相同,即如果电脑生成的4个数为1234,你猜出的数也应是1234
而不是3412、2314等。你输入的4个数由于顺序的不同,屏幕上输出你猜后的结果就会不同。如果你猜出某个位置上的
一个数,电脑就记作1A,若猜到的数位置不正确时,电脑记作1B,如:电脑生成的数为4568,你猜的数是5860,屏幕
就会输出1A2B,你还需要进一步的猜测。当你的成绩被记作4A0B时,你就胜利了。若你想提前知道答案,请输入0000。

注:游戏要求输入不同的4个数,若输入的数中有相同的,屏幕输出结果就不正确。


以下是游戏的源程序:


#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.)Quit Game.                                  $\n";
  cout <<"       ==========================================================\n";
  cout <<"\n\nPlease enter your choice:";
 }

void game_intro()  //关于游戏开发的说明
 {
  char choice;
  clrscr();
  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 MAY 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 play_game();

void main()
 {
  int choice;
  while(1)
   {
    menu();
    cin >>choice;
    switch(choice)
     {
      case 1: game_intro();break;
      case 2: play_game();break;
      case 3: exit(0);break;
      default: break;
     }
   }
 }

void play_game()    //此函数用countA[i]记录每次猜得的A的结果,countB[i]记录每次猜得的B的结果,用二维数组记录每次输入的
 {                  //4个数
  int game_win=0;
  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.\n\n";
  for(i=0;i<4;i++)
   {
    cout <<"number["<<i+1<<"]:";
    cin >>number[0][i];
    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++)
   {
    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]++;
       switch(k)
	{
	 case 0: if((j!=k)&&(pasd[j]==number[i][k]))
		  countB[i]++;break;
	 case 1: if((j!=k)&&(pasd[j]==number[i][k])&&(number[i][k]!=number[i][k-1]))
		  countB[i]++;break;
	 case 2: if((j!=k)&&(pasd[j]==number[i][k])&&(number[i][k]!=number[i][k-1])&&(number[i][k]!=number[i][k-2]))
		  countB[i]++;break;
	 case 4: if((j!=k)&&(pasd[j]==number[i][k])&&(number[i][k]!=number[i][k-1])&&(number[i][k]!=number[i][k-2])&&(number[i][k]!=number[i][k-3]))
		  countB[i]++;break;
	}
      }
    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++)
	 {
	  cout <<"number["<<h+1<<"]:";
	  cin >>number[i+1][h];
	 }
       }
      }
   }
  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 + -