#include<windows.h>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<conio.h>
#include<dos.h>
void gotoxy(int x, int y)
{
COORD coord; //定义一个坐标结构变量
HANDLE hscr; //定义一个句柄
coord.X = x; //给坐标赋值
coord.Y = y;
hscr = GetStdHandle(STD_OUTPUT_HANDLE); //获得标准输出句柄(就是显示器)
SetConsoleCursorPosition(hscr, coord); //设置控制台光标的到指定坐标
}
void guess(int n)
{
int acount,bcount,i,j,k=0,flag,a[10],b[10];
do
{
flag=0;
srand((unsigned)time(NULL));//利用系统时钟设定种子
for(i=0;i<n;i++)
a[i]=rand()%10;
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
if(a[i]==a[j])
{
flag=1;
break;
}
}
}while(flag==1);
do///////////////////////比较函数/////////////////////////////////
{
k++;
acount=0;
bcount=0;
gotoxy(25,k+2);
printf("guess:");
for(i=0;i<n;i++)
scanf("%d",&b[i]);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(a[i]==b[i])
{
acount++;
break;
}
if(a[i]==b[j]&&i!=j)
{
bcount++;
break;
}
}
}
gotoxy(35,k+2);
printf("clue on:%dA%dB\n",acount,bcount);
if(acount==n)//不同猜测次数赢得游戏后的界面
{
if(k==1)
printf("you are the topmost rung of Fortune's ladder!!\n\n");
else if(k<=5)
printf("you are genius!!\n\n");
else if(k<=10)
printf("you are cleaver!!\n\n");
else
printf("you need try hard!!\n\n");
break;
}
}while(1);
}
void main()
{
int i,n;
while(1)
{//////////////////////////////////开始界面//////////////////////////////////////
system("cls");//清屏
gotoxy(30,6);
printf("1.start game?(y/n)");
gotoxy(30,8);
printf("2.Rule");
gotoxy(30,10);
printf("please choose:");
scanf("%d",&i);
switch(i)
{
case 1:
system("cls");
printf("please input n:\n");
scanf("%d",&n);
guess(n);
Sleep(2000);
break;
case 2://游戏规则
system("cls");
gotoxy(40,6);
printf("\n\n\n\t\tThe Rules OF The Game\n");
printf("step1:inpur of the number of difits\n");
printf("step2:input the number,separated by a apace between two number\n");
printf("step3:A represent location and data are correcr\n");
printf(" B represent location is correct but data is wrong!\n");
Sleep(10000);
break;
case 3:
// system("exit");
return;
default:
break;
}
}
} |