?? readme.txt
字號:
游戲說明:
本游戲是用C++編輯的,整個游戲從構想到完成用了一周左右的時間。
在運行本程序時,會有一個主菜單:
==========================================================
$ 1.)About This Game. $
$ 2.)Play Game. $
$ 3.)Show Love. $
$ 4.)Quit Game. $
==========================================================
下面會有提示讓你作出選擇:輸入1,然后回車(回車是執行明令的按鍵),屏幕輸出本程序的相關信息。
輸入2,然后回車,開始游戲。
輸入3,
輸入3,然后回車,則會退出游戲。
游戲規則說明:
游戲開始時,電腦會自動生成4個1~9之間不同的隨機數,然后讓你來猜出這4個數(按提示用鍵盤輸入4個數共有
8次機會),你猜出的4個數應和電腦生成的4個數順序相同,即如果電腦生成的4個數為1234,你猜出的數也應是1234
而不是3412、2314等。你輸入的4個數由于順序的不同,屏幕上輸出你猜后的結果就會不同。如果你猜出某個位置上的
一個數,電腦就記作1A,若猜到的數位置不正確時,電腦記作1B,如:電腦生成的數為4568,你猜的數是5860,屏幕
就會輸出1A2B,你還需要進一步的猜測。當你的成績被記作4A0B時,你就勝利了。若你想提前知道答案,請輸入0000。
注:游戲要求輸入不同的4個數,若輸入的數中有相同的,屏幕輸出結果就不正確。
以下是游戲的源程序:
#include<iostream.h>
#include<stdlib.h>
#include<time.h>
#include<conio.h>
void menu() //顯示游戲主菜單
{
clrscr(); //清屏
cout <<endl<<endl<<endl;
cout <<" ==========================================================\n";
cout <<" $ 1.)About This Game. $\n";
cout <<" $ 2.)Play Game. $\n";
cout <<" $ 3.)Quit Game. $\n";
cout <<" ==========================================================\n";
cout <<"\n\nPlease enter your choice:";
}
void game_intro() //關于游戲開發的說明
{
char choice;
clrscr();
cout <<" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n";
cout <<" * *\n";
cout <<" * *|WELCOME!|* *\n";
cout <<" * *\n";
cout <<" * MADE BY ERIC CHENG VERSION 1.0 *\n";
cout <<" * *\n";
cout <<" * COPYRIGHT (C)2004 ERICTY ALL RIGHT RESERVED *\n";
cout <<" * *\n";
cout <<" * MADE IN 3rd MAY 2004 *\n";
cout <<" * *\n";
cout <<" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n\n";
cout <<"Enter'B' to back to main menu, 'Q' to quit.";
cin >>choice;
switch(choice)
{
case 'b':
case 'B': break;
case 'q':
case 'Q': exit(0);
default: break;
}
}
void play_game();
void main()
{
int choice;
while(1)
{
menu();
cin >>choice;
switch(choice)
{
case 1: game_intro();break;
case 2: play_game();break;
case 3: exit(0);break;
default: break;
}
}
}
void play_game() //此函數用countA[i]記錄每次猜得的A的結果,countB[i]記錄每次猜得的B的結果,用二維數組記錄每次輸入的
{ //4個數
int game_win=0;
int h,i,j,k,countA[8],countB[8];
int number[8][4],pasd[4];
unsigned seed=time(NULL);
void dis_resl(int,int,int,int num[]);
void choice(void);
cout <<endl;
srand(seed);
clrscr();
cout <<"\n\nPlease input four different numbers.\n\n";
for(i=0;i<4;i++)
{
cout <<"number["<<i+1<<"]:";
cin >>number[0][i];
pasd[i]=rand()/100%10;
switch(i)
{
case 1:while(pasd[i]==pasd[i-1])
pasd[i]=rand()/100%10;break;
case 2:while((pasd[i]==pasd[i-1])||(pasd[i]==pasd[i-2]))
pasd[i]=rand()/100%10;break;
case 3:while((pasd[i]==pasd[i-1])||(pasd[i]==pasd[i-2])||(pasd[i]==pasd[i-3]))
pasd[i]=rand()/100%10;break;
}
}
for(i=0;i<8;i++)
{
clrscr();
countA[i]=0;countB[i]=0;
for(j=0;j<4;j++)
for(k=0;k<4;k++)
{
if((j==k)&&(pasd[j]==number[i][k]))
countA[i]++;
switch(k)
{
case 0: if((j!=k)&&(pasd[j]==number[i][k]))
countB[i]++;break;
case 1: if((j!=k)&&(pasd[j]==number[i][k])&&(number[i][k]!=number[i][k-1]))
countB[i]++;break;
case 2: if((j!=k)&&(pasd[j]==number[i][k])&&(number[i][k]!=number[i][k-1])&&(number[i][k]!=number[i][k-2]))
countB[i]++;break;
case 4: if((j!=k)&&(pasd[j]==number[i][k])&&(number[i][k]!=number[i][k-1])&&(number[i][k]!=number[i][k-2])&&(number[i][k]!=number[i][k-3]))
countB[i]++;break;
}
}
if(countA[i]==4)
{
cout <<"\n\nCONGRATULATION!YOU WIN!\n"<<endl;
game_win=1;
choice();
break;
}
else
{
for(h=0;h<=i;h++)
dis_resl(h,countA[h],countB[h],number[h]);
cout <<"You have "<<8-i-1<<" times left!\n";
if(8-i-1)
{
cout <<"Please input four numbers again.\n";
for(h=0;h<4;h++)
{
cout <<"number["<<h+1<<"]:";
cin >>number[i+1][h];
}
}
}
}
if(!(8-i)&&!game_win)
{
cout <<"\n\nSORRY! YOU LOSE. THE NUMBERS ARE:\n\n";
for(h=0;h<4;h++)
cout <<" "<<pasd[h];
cout <<endl;
choice();
}
}
void dis_resl(int i,int a,int b,int num[])
{
int h;
cout <<i+1<<".)"<<a<<"A"<<b<<"B ";
for(h=0;h<4;h++)
cout <<num[h]<<" ";
cout <<endl;
}
void choice(void)
{
char choice;
cout <<"Enter 'B' to Back main menu, 'C' to Continue, 'Q' to Quit.";
cin >>choice;
switch(choice)
{
case 'b':
case 'B': break;
case 'c':
case 'C': play_game();break;
case 'q':
case 'Q': exit(0);break;
default: break;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -