#include
#include
#include
using namespace std;
//猜拳类
class CaiQuan
{
public:
CaiQuan() //构造函数,数值初始化为0
{
win = 0;
lose = 0;
ping = 0;
}
void huanying();//欢迎页面
void zhixing();//猜拳执行
void tongji();//统计结果
private:
int win;
int lose;
int ping;
};
//欢迎页面
void CaiQuan::huanying()
{
cout<
cout<
cout<
Sleep(1000);
cout<
Sleep(1000);
cout<
Sleep(1000);
cout<
Sleep(100);
system("cls");
cout<
cout<
}
//猜拳核心代码
void CaiQuan::zhixing()
{
int array[3] = {1,2,3};
int me;
char h;
int i = 1;
int computer;
cout<
do
{
system("cls");
cout<
cout<
cout<
loop:
cin>>me;
if (1 != me && 2 != me && 3 != me)
{
cout<
goto loop;
}
srand(time(NULL));//产生随机种子
computer=array[rand()%3];//产生1,2,3中的随机数
cout<
switch(computer)
{
case 1:
if(me==1)
{
cout<
ping++;
}
else if(me==2)
{
cout<
lose++;
}
else if(me==3)
{
cout<
win++;
}
break;
case 2:
if(me==1)
{
cout<
win++;
}
else if(me==2)
{
cout<
ping++;
}
else if(me==3)
{
cout<
lose++;
}
break;
case 3:
if(me==1)
{
cout<
lose++;
}
else if(me==2)
{
cout<
win++;
}
else if(me==3)
{
cout<
ping++;
}
break;
default :cout<
goto loop;
break;
}
cout<
cin.get();
h = getchar();
}while('\n' == h);
}
//统计结果
void CaiQuan::tongji()
{
cout<
Sleep(1000);
cout<
cout<
cout<
cout<
}
//主函数
int main()
{
char p;
CaiQuan people;
people.huanying(); //欢迎界面,游戏载入
p = getchar(); //判断开始游戏,退出游戏
if ('\n' != p)
{
goto end;
}
system("cls");
people.zhixing();//进入游戏,执行猜拳
system("cls");
people.tongji();//游戏结束,执行猜拳统计
end:
cout<
return 0;
}