#include <iostream.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
#include <iomanip.h>
int mun_eqv=0;//用于记录平局数
int mun_cpt=0;//记录电脑胜利局数
int mun_men=0;//记录用户胜利局数
int cpt;//电脑出的随机数。
int computer()
{
srand( (unsigned)time( NULL ) );
return rand()%3;
}
void star()
{
mun_eqv=0;
mun_cpt=0;
int mun_men=0;
cout<<endl;
cout<<endl;
cout<<"现在开始!"<<endl;
cout<<"请出招吧!"<<endl;
}
void answer()
{
cout<<endl<<endl<<endl<<endl<<endl<<endl;
cout<<"总下了"<<mun_men+mun_cpt+mun_eqv<<"局"<<endl;
cout<<"其中,"<<mun_eqv<<"平局"<<endl;
// cout<<"人比电脑:"+mun_men+"比"+mun_cpt+";"+mun_eqv+"平"<<endl;
cout<<"人比电脑:"<<mun_men<<"比"<<mun_cpt<<endl;
if(mun_cpt==mun_men)
{
cout<<"平局,彼此彼此!"<<endl;
}
else if(mun_cpt<mun_men)
{
cout<<"祝贺你取得胜利,什么时候请客呀!"<<endl;
}
else
{
cout<<"胜负及兵家常事,回去修炼几年再来吧!"<<endl;
}
}
void work(char you, int him)
{
cout<<endl<<endl<<endl<<endl<<endl;
if(you=='r'&&him==0)
{
cout<<setw(10)<<"石头对石头"<<endl;
cout<<"平局!我们彼此彼此吧?"<<endl;
mun_eqv++;
}
else if(you=='s'&&him==1)
{
cout<<"剪刀对剪刀"<<endl;
cout<<"平局!我们彼此彼此吧?"<<endl;
mun_eqv++;
}
else if(you=='c'&&him==2)
{
cout<<"布对布"<<endl;
cout<<"平局!我们彼此彼此吧?"<<endl;
mun_eqv++;
}
else if(you=='r'&&him==1)
{
cout<<"天呀,你的石头,我的剪刀!"<<endl;
cout<<"你胜了,谢谢刀下留情!"<<endl;
mun_men++;
}
else if(you=='s'&&him==2)
{
cout<<"天呀,你的剪刀剪我的布!"<<endl;
cout<<"你胜了,谢谢刀下留情!"<<endl;
mun_men++;
}
else if(you=='c'&&him==0)
{
cout<<"天呀,你的布包我的石头!"<<endl;
cout<<"你胜了,谢谢刀下留情!"<<endl;
mun_men++;
}
else if(you=='r'&&him==2)
{
cout<<"怎么样,石头同志,尝过我布的利害了吧?"<<endl;
cout<<"你输了,还敢再来吗?"<<endl;
mun_cpt++;
}
else if(you=='c'&&him==1)
{
cout<<"怎么样,布布同志,尝过我剪刀的利害了吧?"<<endl;
cout<<"你输了,还敢再来吗?"<<endl;
mun_cpt++;
}
else if(you=='s'&&him==0)
{
cout<<"怎么样,剪刀同志,我的石头你也敢来?"<<endl;
cout<<"你输了,还敢再来吗?"<<endl;
mun_cpt++;
}
}
void help()
{
cout<<"石头剪刀布游戏"<<endl;
cout<<endl;
cout<<endl;
cout<<"用户按“r”(Rock)表示石头,“s”(Scissors)表示剪刀,“c”(Cloth)表示布,“b”(begin)表示开始,“i”(Instruction)表示查看帮助,“g”(game)表示查看结果,“q”(Quit)表示退出。"<<endl;
cout<<"当游戏开始后,按R、S、C进行人机游戏。"<<endl;
cout<<"游戏规则:布包石头,石头碰剪刀,剪刀剪布为胜利,"<<endl;
cout<<"如果出的是同样的,比如同是石头,则平局。"<<endl;
}
void main()
{
bool y=true;
help();
star();
while(y)
{
char b;
b = getch();
switch(b)
{
case 'r':
case 's':
case 'c':
system("cls");
cpt=computer();
work(b, cpt);
break;
case 'b':
system("cls");
star();
break;
case 'i':
system("cls");
help();
break;
case 'g':
system("cls");
answer();
break;
case 'q':
exit(1);
}
}
}
#include <stdlib.h>
#include <time.h>
#include <conio.h>
#include <iomanip.h>
int mun_eqv=0;//用于记录平局数
int mun_cpt=0;//记录电脑胜利局数
int mun_men=0;//记录用户胜利局数
int cpt;//电脑出的随机数。
int computer()
{
srand( (unsigned)time( NULL ) );
return rand()%3;
}
void star()
{
mun_eqv=0;
mun_cpt=0;
int mun_men=0;
cout<<endl;
cout<<endl;
cout<<"现在开始!"<<endl;
cout<<"请出招吧!"<<endl;
}
void answer()
{
cout<<endl<<endl<<endl<<endl<<endl<<endl;
cout<<"总下了"<<mun_men+mun_cpt+mun_eqv<<"局"<<endl;
cout<<"其中,"<<mun_eqv<<"平局"<<endl;
// cout<<"人比电脑:"+mun_men+"比"+mun_cpt+";"+mun_eqv+"平"<<endl;
cout<<"人比电脑:"<<mun_men<<"比"<<mun_cpt<<endl;
if(mun_cpt==mun_men)
{
cout<<"平局,彼此彼此!"<<endl;
}
else if(mun_cpt<mun_men)
{
cout<<"祝贺你取得胜利,什么时候请客呀!"<<endl;
}
else
{
cout<<"胜负及兵家常事,回去修炼几年再来吧!"<<endl;
}
}
void work(char you, int him)
{
cout<<endl<<endl<<endl<<endl<<endl;
if(you=='r'&&him==0)
{
cout<<setw(10)<<"石头对石头"<<endl;
cout<<"平局!我们彼此彼此吧?"<<endl;
mun_eqv++;
}
else if(you=='s'&&him==1)
{
cout<<"剪刀对剪刀"<<endl;
cout<<"平局!我们彼此彼此吧?"<<endl;
mun_eqv++;
}
else if(you=='c'&&him==2)
{
cout<<"布对布"<<endl;
cout<<"平局!我们彼此彼此吧?"<<endl;
mun_eqv++;
}
else if(you=='r'&&him==1)
{
cout<<"天呀,你的石头,我的剪刀!"<<endl;
cout<<"你胜了,谢谢刀下留情!"<<endl;
mun_men++;
}
else if(you=='s'&&him==2)
{
cout<<"天呀,你的剪刀剪我的布!"<<endl;
cout<<"你胜了,谢谢刀下留情!"<<endl;
mun_men++;
}
else if(you=='c'&&him==0)
{
cout<<"天呀,你的布包我的石头!"<<endl;
cout<<"你胜了,谢谢刀下留情!"<<endl;
mun_men++;
}
else if(you=='r'&&him==2)
{
cout<<"怎么样,石头同志,尝过我布的利害了吧?"<<endl;
cout<<"你输了,还敢再来吗?"<<endl;
mun_cpt++;
}
else if(you=='c'&&him==1)
{
cout<<"怎么样,布布同志,尝过我剪刀的利害了吧?"<<endl;
cout<<"你输了,还敢再来吗?"<<endl;
mun_cpt++;
}
else if(you=='s'&&him==0)
{
cout<<"怎么样,剪刀同志,我的石头你也敢来?"<<endl;
cout<<"你输了,还敢再来吗?"<<endl;
mun_cpt++;
}
}
void help()
{
cout<<"石头剪刀布游戏"<<endl;
cout<<endl;
cout<<endl;
cout<<"用户按“r”(Rock)表示石头,“s”(Scissors)表示剪刀,“c”(Cloth)表示布,“b”(begin)表示开始,“i”(Instruction)表示查看帮助,“g”(game)表示查看结果,“q”(Quit)表示退出。"<<endl;
cout<<"当游戏开始后,按R、S、C进行人机游戏。"<<endl;
cout<<"游戏规则:布包石头,石头碰剪刀,剪刀剪布为胜利,"<<endl;
cout<<"如果出的是同样的,比如同是石头,则平局。"<<endl;
}
void main()
{
bool y=true;
help();
star();
while(y)
{
char b;
b = getch();
switch(b)
{
case 'r':
case 's':
case 'c':
system("cls");
cpt=computer();
work(b, cpt);
break;
case 'b':
system("cls");
star();
break;
case 'i':
system("cls");
help();
break;
case 'g':
system("cls");
answer();
break;
case 'q':
exit(1);
}
}
}