#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; } } } |
能不能提供详细一点的数据,这样看不大明白 |
这个是c语言书上的例题吧 |
大佬啊,大佬啊,你在哪里~ |
C语言猜数字程序代码问题 随机产生4个数(0-9).用户输入4个数进行核对.位置正确数字正确为A.数字正确位置不正确为B. 4A时提示继续还是退出.类似文曲星里的游戏. 实现猜数字的游戏。游戏规则如下: (1)首先程序随机生成一个0-9999的数。 (2)玩家每次输入一个4位数,程序告诉玩家两个信息: 用户输入的数,在个、十、百、千4个数字中,有几个数字是谜底里面有的,且出现在 正确的位置上为A; 用户输入的数,在个、十、百、千4个数字中,有几个数字是谜底里面有的,但未出现 在正确的位置上为B。 |
theplaystar 发表于 2018-10-17 20:38 就只有这个图片,,上面游戏规则应该很详细了啊 |
能不能详细一点 |
那个进制的 |