«

剪刀石布(五局制)

点亮灯 发布于 阅读:75 C++


剪刀石头布(5局制).rar

#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main ()
{

int shu1;
int shu2;
int a,b;
a=0;
b=0;
/*************/
cout<<"\t\t\t*********************************\n";
cout<<"\t\t\t**********剪刀**石头**布*********\n";
cout<<"\t\t\t*********************************\n";
cout<<"\t\t\t我们来玩个游戏吧!(^._.^)?\n";
cout<<"\t\t\t1=剪刀       2=石头        3布\n";

for(int i=1;i<=5;i++){
cout<<"请输入数字:(1/2/3)";
cin>>shu1;

if(shu1==1){
    cout<<"你出的是:";
    cout<<"剪刀";
}
if(shu1==2){
    cout<<"你出的是:";
    cout<<"石头";
}
if(shu1==3){
    cout<<"你出的是:";
    cout<<"布";
}
/***********************/
srand(time(0));
shu2 = rand() % (3 - 1 + 1) + 1;
if(shu2==1){
    cout<<"\n电脑出的是:";
    cout<<"剪刀\n";
}
if(shu2==2){
    cout<<"\n电脑出的是:";
    cout<<"石头\n";
}
if(shu2==3){
    cout<<"\n电脑出的是:";
    cout<<"布\n";
}
//判定平局
if((shu1==1)&&(shu2==1)||(shu1==2)&&(shu2==2)||(shu1==3)&&(shu2==3)){
cout<<"\t\t\t*********************************\n";
cout<<"\t\t\t*************再来一次************\n";
cout<<"\t\t\t*********************************\n";
i--;
}
//判定赢
if((shu1==1)&&(shu2==3)||(shu1==2)&&(shu2==1)||(shu1==3)&&(shu2==2)){
cout<<"\t\t\t*********************************\n";
cout<<"\t\t\t***************赢****************\n";
cout<<"\t\t\t*********************************\n";
a++;
}

//判定输
if((shu1==1)&&(shu2==2)||(shu1==2)&&(shu2==3)||(shu1==3)&&(shu2==1)){
cout<<"\t\t\t*********************************\n";
cout<<"\t\t\t***************输****************\n";
cout<<"\t\t\t*********************************\n";
b++;
}
if(a==3)
   {
    cout<<"赢了";
    break;
   }
else if(b==3)
   {
        cout<<"输了";
    break;
   }
}
}
//展开==做完了