石头剪刀布V1.3版本
2024-11-23 19:43:30
发布于:浙江
时间不够,没做全。。。下回升级吧
#include<iostream>
#include<time.h>
#include<stdlib.h>
#include<conio.h>
#include<windows.h>
short computer_s_select,user_s_select;
int press_down;
using namespace std;
void computer()
{
cout<<"电脑出了 ";
srand(time(0));
computer_s_select=rand()%3+1;
if(computer_s_select==1)
{
cout<<"石头\n";
}
else if(computer_s_select==2)
{
cout<<"剪刀\n";
}
else
{
cout<<"布\n";
}
}
void user()
{
cout<<"你要出什么?\n";
cout<<"1.石头\n";
cout<<"2.剪刀\n";
cout<<"3.布\n";
cout<<"你出了 ";
while(1)
{
press_down=getch();
if(press_down==49)
{
user_s_select=1;
cout<<"石头\n";
break;
}
if(press_down==50)
{
user_s_select=2;
cout<<"剪刀\n";
break;
}
if(press_down==51)
{
user_s_select=3;
cout<<"布\n";
break;
}
}
}
void start()
{
cout<<"*********************\n";
cout<<"欢迎使用“石头剪刀布”游戏V1.3\n";
cout<<"*********************\n";
cout<<"按任意键开始游戏...\n";
getch();
}
int main()
{
start();
system("cls");
a:
user();
computer();
if((computer_s_select==1&&user_s_select==2)||(computer_s_select==2&&user_s_select==3)||(computer_s_select==3&&user_s_select==1))
{
cout<<"电脑赢了\n";
cout<<"按任意键继续游戏...\n";
getch();
system("cls");
goto a;
}
else if(computer_s_select==user_s_select)
{
cout<<"你和电脑平局\n";
cout<<"按任意键继续游戏...\n";
getch();
system("cls");
goto a;
}
else
{
cout<<"你赢了\n";
cout<<"按任意键继续游戏...\n";
getch();
system("cls");
goto a;
}
}
转发或修改请标明出处。
最后...一定要关注+点赞啊!!!
这里空空如也
有帮助,赞一个