C++有趣程序(10)

自创石头剪刀布游戏:(有一点点水。。。)

#include <bits/stdc++.h> 
using namespace std;
int main()
{
cout<<"1代表石头:2代表剪刀:3代表布:4代表结束游戏:"<<endl;
cout<<"请出拳"<<endl;
int n;
while(cin>>n)
{
if(n<1||n>4) cout<<"输入错误 请重新输入:"<<endl;
else if(n==4) break;
else
{
int d;
srand((unsigned)time(0));
d=rand()%3+1;
switch(n)
{
case 1: cout<<"你出的是石头"<<endl;break;
case 2: cout<<"你出的是剪刀"<<endl;break;
case 3: cout<<"你出的是布"<<endl;break;
}
switch(d)
{
case 1: cout<<"我出的是石头"<<endl;break;
case 2: cout<<"我出的是剪刀"<<endl;break;
case 3: cout<<"我出的是布"<<endl;break;
}
if(d==n) cout<<"平手"<<endl;
else if(d-n==1) cout<<"你赢了"<<endl;
else if(d==1&&n==3) cout<<"你赢了"<<endl;
else cout<<"你输了"<<endl;
}
}
}
0 0 vote
Article Rating
Subscribe
提醒
0 评论
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x