※ 綜合應用:一個很簡單的剪刀石頭布遊戲
string hand[3] = {"剪刀","石頭","布"};
for (int i=1;i>0;i++)
{
int A = (i%3) + 1;
int B;
string s1 = "電腦出";
string s2 = ",請問您要出?(按1出剪刀,按2出石頭,按3出布,按其他離開遊戲)";
cout<<s1+hand[A-1]+s2<<endl;
cin>>B;
if (A==1)
{
if (B==1){cout<<"雙方平手!"<<endl;}
else if (B==2){cout<<"你贏了!"<<endl;}
else if (B==3){cout<<"你輸了!"<<endl;}
else {break;}
}
else if (A==2)
{
if (B==1){cout<<"你輸了!"<<endl;}
else if (B==2){cout<<"雙方平手!"<<endl;}
else if (B==3){cout<<"你贏了!"<<endl;}
else {break;}
}
else if (A==3)
{
if (B==1){cout<<"你贏了!"<<endl;}
else if (B==2){cout<<"你贏了!"<<endl;}
else if (B==3){cout<<"雙方平手!"<<endl;}
else {break;}
}
}
留言列表