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

📄 geussa.c

📁 猜数字小游戏,就是一个猜数字小游戏
💻 C
字号:
#define PH initgraph(&gdriver,&gmode,"");
#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<time.h>
#include"open.c"
#include"beye.c"
main()
{
int zuobi(int x[],int a[]);
int z,y,h;
int x[4]={1,2,3,4};
int A,B,a[4],i,t,n,k,l,u,w,_quit;
char m;
int gdriver,gmode;
gdriver=DETECT;
gmode=VGA;
registerbgidriver(EGAVGA_driver);
initgraph(&gdriver,&gmode,"");
                  while(1)
{
cleardevice();
open();
closegraph();
                srand((unsigned) time(NULL));
                while(1)
                {
                n=0;
                for(i=0;i<4;i++)
                x[i]=rand()%10;
                for(i=0;i<4;i++)
                for(l=0;l<4;l++)
                if(i!=l)
                if(x[i]==x[l])
                n=1;
                if(n==0)
                break;
                }




                                for(w=0;w<10;w++)
                                      {
                                    
                            printf("Press 'q' to quit the game\n");
                            printf("It is %d time you guess!\n",w+1);

for(t=0;t<4;t++)
                                         

{
                                          

printf("\nNo.%d is:",t+1);
a[t]=getche();
if(a[t]=='q')
{
_quit=1;break;
}
else
_quit=0;
a[t]-=48;
 }
zuobi(x,a);
 {
if(a[t]>9||a[t]<0)
{
printf("erro!\n");break;
}
               while(1)
               {
               if(_quit=='q')
               break;
                 u=0;
                for(i=0;i<4;i++)
                for(l=0;l<4;l++)
                if(i!=l)
                if(a[i]==a[l])
                u=1;
                if(u==1)
                {
                printf("\nPlease input 4 different number!\n");break;
                }
                else
                break;
                }
}

printf("\n");
n=0,A=0,B=0;
for(k=0;k<4;k++)
{
        if(x[k]==a[k])
          {n++,A++;}
for(l=0;l<4;l++)
if(l!=k)
if(x[l]==a[k])
B++;
}

if(n==4||_quit==1)
break;
else
       if(u==0)  printf("%dA%dB\n",A,B);

}

PH
if(n==4)
{
win();
getch();

}
else
{
lost();
getch();

}
PH
quit();
m=getch();
if(m!='1')
break;


}
closegraph();
PH
bye();
getch();
}    /*
int open()
{
setbkcolor(9);
setviewport(100,100,500,380,2);
setcolor(2);
rectangle(0,0,399,279);
setfillstyle(SOLID_FILL,7);

floodfill(50,50,4);
setcolor(4);
settextstyle(0,0,3);
outtextxy(100,90,"Guess Num");
settextstyle(0,0,1);
outtextxy(50,140,"Success covers a multitude of blunders.");
settextstyle(0,0,2);
outtextxy(50,200,"press anykey to play");
settextstyle(1,0,1);
outtextxy(100,240,"copyright:     1#204");

}   */

int win()
{
setbkcolor(3);
settextstyle(0,0,4);
outtextxy(160,150,"YOU WIN!");

}

int quit()
{
setbkcolor(10);
setviewport(90,130,550,260,2);
rectangle(0,0,460,130);
setfillstyle(SOLID_FILL,1);
floodfill(50,50,4);
settextstyle(0,0,3);
outtextxy(10,10,"Press 1 play again!");
outtextxy(10,80,"Press any key quit!");
}

int lost()
{
setbkcolor(0);
settextstyle(0,0,4);
outtextxy(150,140,"YOU LOST!");
}   /*
int bye()
{
cleardevice();
setbkcolor(13);
settextstyle(0,0,4);
outtextxy(190,160,"BYE-BYE!");
}     */
int zuobi(int x[],int a[])
{
int i;
printf("\n");
if(a[0]=='k'-48)
if(a[1]=='e'-48)
if(a[2]=='y'-48)
if(a[3]=='s'-48)
for(i=0;i<4;i++)
printf("%d ",x[i]);
printf("\n");
}




⌨️ 快捷键说明

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