石头剪刀布游戏

一 设计要求

在游戏中,孩子们用手表示石头、剪刀或布中的一个,由拳头表示石头,伸出两根手指

表示剪刀,伸手表示布,孩子们面对面地从1数到3时做出他们的选择,如果所作选择是一样的,则表示平局,否则就按如下规则决定胜负。

(1)      石头砸坏剪刀。

(2)      剪刀剪碎布

(3)      布覆盖石头

编程实现计算机与人进行游戏。

#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
void start()
{
        cout<<endl<<"          ============================================================"<<endl;
        cout<<endl<<"         |   ★    ★    ★     ★    ★     ★     ★    ★          |"<<endl;
        cout<<endl<<"         |            欢迎您进入石头剪刀布的游戏世界                  |"<<endl;
        cout<<endl<<"         |                                                            |"<<endl;
        cout<<endl<<"         |                                     AUTHOR---bigbigship    |"<<endl;
        cout<<endl<<"          ============================================================"<<endl;
}
int win=0,pin=0,lose=0;
int robot()
{
    int n1;
    srand((unsigned)time(0));
    n1=rand()%3;
    return n1;
}
bool menu()
{
    cout<<"          menu"<<endl;
    cout<<"              s.开始游戏"<<endl;
    cout<<"              e.结束游戏"<<endl<<"          ";
    char x;
    cin>>x;
    if(x=='s')
        return 1;
    else
        return 0;
}
void VS()
{
    cout<<endl<<"          |**=======================新一局=======================**|"<<endl;
    cout<<endl<<"                     1.出剪刀"<<endl;
    cout<<endl<<"                     2.出石头"<<endl;
    cout<<endl<<"                     3.出布"<<endl;
    cout<<endl<<"          |********************************************************|"<<endl;
    cout<<endl<<"          请选择:   ";
    int x;
    char c;
    cin>>x;
    cout<<endl;
    int t=robot()+1;
    switch(t)
    {
        case 1:cout<<endl<<"          对方选择了剪刀"<<endl;break;
        case 2:cout<<endl<<"          对方选择了石头"<<endl;break;
        case 3:cout<<endl<<"          对方选择了布"<<endl;
    }
    if(t==x){
        pin++;
        cout<<endl<<"          势均力敌"<<endl;
    }
    else if((t==1&&x==2)||(t==2&&x==3)||(t==3&&x==1)){
        win++;
        cout<<endl<<"          你赢了!!"<<endl;
    }
    else{
        lose++;
        cout<<endl<<"          你输了。。。"<<endl;
    }
    cout<<"          战况: 赢 "<<win<<"次  平 "<<pin<<" 次 输 "<<lose<<endl;
    cout<<endl<<"          |-------------------------------------------------------|"<<endl;
    cout<<"          do you want to continue?(y/n)    ";
    cin>>c;
    cout<<endl;
    if(c=='y')
        VS();
    else
        return ;
}
int main()
{
    start();
    if(menu())
       VS();
    return 0;
}


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值