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

📄 cap2.cpp

📁 系统随机给出一个0到99之间的两位数,玩者通过键盘输入一个数,系统判别输入数和随机数,然后给出大或小的提示,玩者在给定回合内继续输入直到得到该随机数为止.
💻 CPP
字号:
#include<iostream.h>
#include<stdlib.h>
#include<time.h>
#include<dos.h>
#include<string.h>
#include<iostream.h>
#include<graphics.h>
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
class Game
{ public:
  GameA();
 void GameB(int a,int b,int c);
  protected:
   int * cha;
   int rannumber;
   int number;
   int chances;
   };

class Player
{  public:
   player(char*pName);
   static int number();
   protected:
   int * tim;
   static int noofplayers;
   char name[20];
   int time;
   } ;

 int Player::noofplayers=0;

 Game::GameA()
{  moveto(180,250);
   outtext("well done!You have got it!!");
  }

void Game::GameB(int a,int b,int c)
 { rannumber=a;
   number=b;
   chances=c;
   moveto(180,250) ;
 if(b<0||(b>100&&b!=2002))
 outtext("It is impossible!Are you crazy?");
  else if(a-b>50)
 outtext("Oh,no!Too small!!!!");
  else if(a-b>30)
  outtext("Oh no!Much small!");
  else if(a-b>15)
  outtext("Oh no!Why not a little big?");
  else if(a-b>5)
  outtext("Oh no!Please get a little big!!");
  else if(a-b>0&&a-b<=5)
  outtext("My god! Nearly! But a little small!!");
  else if(b-a>50)
  outtext("Oh no!Too big!!");
  else if(b-a>30)
  outtext("Oh no!Get smaller!!");
  else if(b-a>15)
  outtext("Oh no!Why not get a bit small?");
  else if(b-a>5)
  outtext("Oh no!Can't you get small?.....");
  else if(b-a>0&&b-a<=5)
  outtext("My god! Nearly! Only a little big!!");

  moveto(220,300);

  if(7-c==1)
  {moveto(220,280);
  outtext("The last chance!!!"); }


  //if(c<3)cout<<"wenderful!"<<endl; //

  }


 Player::player(char*pName)
  {cout<<"Dear "<<pName<<",please enter a number to guess:"<<endl;
  strncpy(name,pName,sizeof(name));
  name[sizeof(name)-1]='\0';
  noofplayers++;
  }



class Score
   {public:
   int scores(int n,int t)
  {double s;
  if(n==0)
     s=30000+2000*(10-t);
   else if(n<=3&&n>0)
     s=25000-(2000*n)+2000*(10-t);
   else if(n<=5&&n>3)
     s=20000-(1500*n)+2000*(25-t);
   else if(n<=8&&n>5)
     s=15000-(1000*n)+2000*(30-t);

   return s;

     }
   protected:
   int n;
   int t;
   };

  void fn1()
  {  Game cap;
     Game yy;
    Score sco;
    int x,y,s;
    double score;
    clock_t start,end;

     randomize();
   x=random(100);
   unsigned size;
   size=imagesize(200,500,530,519);
   void*resize=malloc(size);
   getimage(200,500,530,519,resize);
   for(int n=0;n<8;n++)
   { start=clock();
     cin>>y;
     putimage(132,244,resize,COPY_PUT);
     if(y==x)
    {yy.GameA();
    end=clock();
    s=(end-start)/CLK_TCK;

   score=sco.scores(n,s);
   moveto(420,320);
   outtext("score");
   cout<<"You use "<<s<<" seconds to get the number."<<endl;
   cout<<"Your score is:"<<score<<endl;

      break;
      cout<<"wenderful"<<endl;}
      if(y!=x)
     cap.GameB(x,y,n);

     }
    putimage(150,278,resize,COPY_PUT);

    moveto(270,290);
    outtext("game over");

     }

  void fn2()
  {
  char chose;
    unsigned size;
   size=imagesize(200,500,530,519);
   void*resize=malloc(size);
   getimage(200,500,530,519,resize);
  fn1() ;
  cout<<"play again?(y/n)";
  cin>>chose;
  if(chose=='y')
  {putimage(132,244,resize,COPY_PUT);putimage(132,298,resize,COPY_PUT);fn2();}
  if(chose=='n')
   {cout<<"OK,see you!!"<<endl;
   moveto(230,370);
   outtext("ENJOY A NICE DAY!");}

   }
 void fn3()
 {Player pla;
 char name[20];
   cin>>name;
   pla.player(name);
   moveto(240,320);
   outtext(name);

   }

  void main()
 { closegraph();
int x1=100,y1=100;
int x2=500,y2=100;
int x3=105,y3=105;
int x4=495,y4=105;
int gdriver=DETECT,grade,errorcode;
initgraph(&gdriver,&grade,"c:\\tc\\bgi");
errorcode=graphresult();

if(errorcode!=grOk)
{printf("graphics error:%s\n",grapherrormsg(errorcode));
printf("press any key to hult:");
getch();
exit(1);
}
moveto(x1,y1);
lineto(x2,y2);
lineto(x2,y2+300);
lineto(x1,y2+300);
lineto(x1,y1);
moveto(x3,y3);
lineto(x4,y4);
lineto(x4,y4+290);
lineto(x3,y4+290);
lineto(x3,y3);

int x=150,y=150;
int i;
int radins=5;

moveto(220,170);
outtext("WELCOME TO PLAY THIS GAME");
moveto(221,170);
outtext("WELCOME TO PLAY THIS GAME");
moveto(220,169);
outtext("WELCOME TO PLAY THIS GAME");
moveto(220,180);
lineto(419,180);
moveto(220,184);
lineto(419,184);
arc(x,y,0,100,radins);
for(i=10;i<15;i++)
circle(x+i,y+i,radins);
for(i=10;i<20;i++)
circle(x+i,y+i,radins+10);
moveto(180,200);
outtext("A game to guess a random number.");
moveto(160,215);
outtext("Now there is a number between 0 to 99.");
moveto(180,320);
outtext("PLAYER:");
moveto(350,320);
outtext("SCORE:");
moveto(260,340);
outtext("TIME:");
moveto(130,242);
lineto(470,242);
lineto(470,265);
lineto(130,265);
lineto(130,242);
moveto(200,250);
outtext("HERE WE GO!!");
int t;
cout<<"please enter your name:"<<endl;
fn3();
cout<<"Enter a number"<<endl;
fn2();
getch();
exit(1);
getche();
closegraph();


  }

⌨️ 快捷键说明

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