hk8100_00 偶而上來逛逛的過客
註冊時間: 2009-06-27 文章: 10
255.69 果凍幣
|
發表於: 2009-11-5, PM 5:55 星期四 文章主題: 開口中遊戲 |
|
|
代碼: |
// Compiler : Visual C++ 2010 Express Edition Beta 2
#include <iostream>
#include <ctime>
#include <string> // use getline
using namespace std;
string u[2];
void set_one()
{
cout << "設置用戶名稱 : " << endl;
cout << "用戶 a : "; getline(cin,u[0]);
cout << "用戶 b : "; getline(cin,u[1]);
system("cls");
}
void game(int z,int x,int c)
{
char t;
int iu[2];
int zx[2];
int i=0;
do
{
int a=rand()%c;
zx[0]=z;
zx[1]=x;
do
{
cout << zx[0] << " to " << zx[1] << endl;
cout << "<" << u[0] << "> " << "Number : "; cin >> iu[0];
if(iu[0]<=zx[0])
cout << " < < Error !! > > " << endl;
else if(iu[0]>=zx[1])
cout << " < < Error !! > > " << endl;
else if(iu[0]>a)
zx[1]=iu[0];
else if(iu[0]<a)
zx[0]=iu[0];
if(iu[0]==a)
{
cout << " > > Game over !!" << endl;
cout << " > > 總用了" << i << "回合" << endl;
break;
}
cout << endl;
cout << zx[0] << " to " << zx[1] << endl;
cout << "<" << u[1] << "> " << "Number : "; cin >> iu[1];
if(iu[1]<=zx[0])
cout << " < < Error !! > > " << endl;
else if(iu[1]>=zx[1])
cout << " < < Error !! > > " << endl;
else if(iu[1]>a)
zx[1]=iu[1];
else if(iu[1]<a)
zx[0]=iu[1];
i++;
cout << "第" << i << "回合完結" << endl;
cout << endl;
if(iu[1]==a)
{
cout << " > > Game over !!" << endl;
cout << " > > 總用了" << i << "回合" << endl;
break;
}
} while(iu[0]!=a || iu[1]!=a);
cout << endl;
cout << "Try again (Y) : "; cin >> t;
system("cls");
} while(t=='y'||t=='Y');
}
int main()
{
srand((unsigned)time(NULL));
cout << "開口中 雙打版" << endl << endl;
system("pause");
system("cls");
set_one();
game(1,100,100);
return 0;
}
|
本來打算設計同電腦VS的版本,因為我能力有限所以設計了雙打版 |
|