|
|
#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 就只有這個圖片,,上面游戲規則應該很詳細了啊 |
| 能不能詳細一點 |
| 那個進制的 |