c++剪刀石头布

2024-12-26 00:16:42
推荐回答(5个)
回答1:

#include
#include
#include
#include
int main1(int n1)
{
srand((unsigned)time(0));
n1=rand()%3;
return n1;
}

int main()
{
int cho,good,temp,win=0,lose=0,tie=0;
char a;
cout<<"一一一一一一一一一一一一一一一一一一一一一一一一一一一一"<cout<<"欢迎进入石头剪刀布的世界!"<cout<<"一一一一一一一一一一一一一一一一一一一一一一一一一一一一"<getch();
while(1){
cout<<"//////////新一局//////////"<cout<<"1.出石头"<cout<<"2.出剪刀"<cout<<"3.出布"<cout<<"*************************"<cout<<"请选择";
cin>>cho; //用户输入1-3任意数
good=main1(temp);
switch (good)
{
case 0:
cout<<"对方出了剪子\n";
if (cho==1) cout<<"您赢了"<if (cho==2) cout<<"势均力敌"<if (cho==3) cout<<"您输了"<cout<<"战况:"<<"赢:"<break;
case 1:
cout<<"对方出了石头\n";
if (cho==3) cout<<"您赢了"<if (cho==1) cout<<"势均力敌"<if (cho==2) cout<<"您输了"<cout<<"战况:"<<"赢:"<break;
case 2:
cout<<"对方出了布\n";
if (cho==2) cout<<"您赢了"<if (cho==3) cout<<"势均力敌"<if (cho==1) cout<<"您输了"<cout<<"战况:"<<"赢:"<break;
}}
return 0;
}

回答2:

#include
#include
#include
#include

using namespace std;

int guess(void)
{
return rand() % 3;
}//end guess

int main(void)
{

//规则表。下标表示:0-石头,1-剪子,2-布;内容表示:0-平局;1-玩家胜;2-计算机胜
int rules[3][3] = {
{0, 1, 2},
{2, 0, 1},
{1, 2, 0}
};//end rules

char names[3][5] = {"石头", "剪子", "布"};
char results[3][20] = {"势均力敌!", "您赢了!", "您输了!"};

srand(time(0)); //初始化随机数

int cmd = 0, computer = 0, game = 0, games[3]={0, 0, 0};
cout << "----------------------\n欢迎进入石头剪子布小游戏世界!按任意键开始...\n----------------------" << endl;
for(;;) {
cout << "///////////新一局/////////\n0-出石头;\n1-出剪子;\n2-出布;\n其他任意键结束:\n*********************\n请选择" << endl;
cmd = getch() - '0';
computer = guess();
if(cmd<0 || cmd >2) break;
cout <<"您出的是:" << names[cmd] << endl;
cout <<"我出的是:" << names[game]<< endl;
game = rules[cmd][computer];
games[game]++;
cout << results[game]<< endl << endl;
cout << "战况:赢" << games[1] <<"次;输:" << games[2] << "平:"<< games[0] << "次" << endl;
}//next for
return 0;
}

运行结果与题目提供的样本截屏完全一致!!!采纳我的吧!楼上的没有计分这个功能!

回答3:

#include
#include
#include

using namespace std;

int getIt()
{
srand((unsigned)time(NULL));
int n= rand()%3;
return n;
}
int main()
{
int a, n, win, lose, draw;
win=lose=draw=0;
cout << " /////////////新一局/////////////" < cout << "请输入1-3任意数"< cout << "1 剪子" < cout << "2 石头" < cout << "3 布" < cout << "********************************" < while(cin>>a)
{
n=getIt();
switch(n)
{
case 0:cout<<"对方出了剪子\n"; break;
case 1: cout<<"对方出了石头\n"; break;
case 2: cout<<"对方出了布\n"; break;
}
n++;
if(a == n) {
cout << "draw game " << endl;
draw++;
}
else if( a + 1 == n || (a==3 && n==1)) {
cout << "computer win" < lose++;
}
else {
cout <<"you win" < win++;
}
cout <<"战况: 赢" << win <<"次; 输: "<< lose <<"次"<< " 平:" << draw << "次"< }
return 0;
}
//楼上的也太不厚道了吧

回答4:

孩子你是华东交大的吧?

回答5:

给你发工程文件了,谢谢~~