石头剪刀布

#include<iostream.h>
#include<cstdlib>
void main()
{
cout<<"welcome to the game!!";
cout<<endl;
int start;
cout<<"if you want to get some help please enter number 0,else enter your choice!"<<endl;
int choice;
start:cin>>choice;
if(choice>3)
{cout<<"error,please input again:";goto start;}
else
switch(choice){
case 0:cout<<"1代表石头 ,2代表剪刀,3代表布。游戏规则是石头砸坏剪刀,剪刀剪碎布,布覆盖石头,,如果选择一样,表示平局,please input your choice:"<<endl;
goto start;
case 1:cout<<"您出石头,";
break;
case 2:cout<<"您出剪刀,";
break;
case 3:cout<<"您出布,";
break;
}
int computerchoice=rand()%3+1;
if(computerchoice==choice)
cout<<"计算机和您 输出的一样,平局。";
else
switch(choice)
{
case 1:if(computerchoice==2)
  cout<<"计算机出剪刀,您赢了!";
else 
cout<<"计算机出布,您输了!";
break;
case 2:if(computerchoice==1)
  cout<<"计算机出石头,您输了!";
else
cout<<"计算机出布,您赢了!";
break;
case 3:if(computerchoice==2)
  cout<<"计算机出剪刀,您输了!";
else
cout<<"计算机出石头,您赢了!";
}
cout<<endl;
cout<<"please input your choice"<<endl;
goto start;

}


第二个程序:

#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
void main()
{
 char choose,h;
 cout<<"Welcome Game Zone!"<<endl;
 cout<<endl;
 cout<<"即将载入的是石头-剪刀-布游戏"<<endl;
 cout<<"Loding★☆★☆★☆"<<endl;
 cout<<"Are you ready?yes or no(Y/N)";
 cin>>choose;
 if(choose!='N'&& choose!='n')
 {
  int win(0),lose(0),draw(0),me,computer;
  do
  {
   cout<<"请输入你的选择:"<<endl;
   cin>>me;
   srand((unsigned)time(NULL));
   computer=rand()%3+1;
    switch(computer)
    {
     case 1:
      if(me==1)
      {
       cout<<"电脑出的是石头,你出的也是石头,此局为平局"<<endl;
       draw++;
      }
      else if(me==2)
      {
       cout<<"电脑出的是石头,你出的是剪刀,很不幸,此局你输了"<<endl;
       lose++;
      }
      else if(me==3)
      {
       cout<<"电脑出的是石头,你出的是布,恭喜你,此局你赢了"<<endl;
       win++;
      }
      break;
     case 2:
      if(me==1)
      {
       cout<<"电脑出的是剪刀,你出的是石头,恭喜你,此局你赢了"<<endl;
      win++;
      }
      else if(me==2)
      {
       cout<<"电脑出的是剪刀,你出的也是剪刀,此局为平局"<<endl;
       draw++;
      }
      else if(me==3)
      {
       cout<<"电脑出的是剪刀,你出的是布,很不幸,此局你输了"<<endl;
       lose++;
      }
      break;
     case 3:
      if(me==1)
      {
       cout<<"电脑出的是布,你出的是石头,很不幸,此局你输了"<<endl;
       lose++;
      }
      else if(me==2)
      {
       cout<<"电脑出的是布,你出的剪刀,恭喜你,此局你赢了"<<endl;
       win++;
      }
      else if(me==3)
      {
       cout<<"电脑出的是布,你出的也是布,此局为平局"<<endl;
       draw++;
      }
      break;
  default :
   break;
   // computer=rand()%3+1;
   }
    cout<<"你还要继续吗?Yes/No(Y/N)"<<endl;
    cin>>h;
  }while(h!='N'&& h!='n');
  cout<<"你一共进行了 "<<win+lose+draw<<"次游戏,其中:"<<endl;
  cout<<"你胜出"<<win<<"次"<<endl;
  cout<<"你输了"<<lose<<"次"<<endl;
  cout<<"你和电脑打平"<<draw<<"次";
 }


第三个程序:

#include <conio.h>
#include <cstdlib>
#include <ctime>
#include <iostream.h>


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;


第四个程序:

#include <iostream.h>
#include <time.h>
#include <stdlib.h>
#include <conio.h> 
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<<"*****************************"<<endl; 
cout<<"**欢迎进入石头剪刀布的世界!**"<<endl<<"准备好了吗?按任意键继续..."<<endl; 
cout<<"*****************************"<<endl; 
getch();
 while(1){
cout<<"电脑说“很高兴,精彩即将开始,祝君好运"<<endl;
cout<<"1.出石头"<<endl;
cout<<"2.出剪刀"<<endl;
cout<<"3.出布"<<endl;
cout<<"*************************"<<endl; 
cout<<"请选择"; 
cin>>cho;  //用户输入1-3任意数
good=main1(temp);
switch (good) 
 {  
 case 0: 
cout<<"对方出了剪子\n";
if (cho==1) cout<<"您赢了"<<endl,win++;
if (cho==2) cout<<"势均力敌"<<endl,tie++;
if (cho==3) cout<<"您输了"<<endl,lose++;
cout<<"战况:"<<"赢:"<<win<<"次;输:"<<lose<<"次;平:"<<tie<<"次。"<<endl;
break; 
case 1: 
 cout<<"对方出了石头\n";
if (cho==3) cout<<"您赢了"<<endl,win++;
if (cho==1) cout<<"势均力敌"<<endl,tie++;
if (cho==2) cout<<"您输了"<<endl,lose++;
cout<<"战况:"<<"赢:"<<win<<"次;输:"<<lose<<"次;平:"<<tie<<"次。"<<endl;
break; 
case 2: 
 cout<<"对方出了布\n";
if (cho==2) cout<<"您赢了"<<endl,win++;
if (cho==3) cout<<"势均力敌"<<endl,tie++;
if (cho==1) cout<<"您输了"<<endl,lose++;
cout<<"战况:"<<"赢:"<<win<<"次;输:"<<lose<<"次;平:"<<tie<<"次。"<<endl;
break; 
}} 
return 0;


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值