返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<time.h>
  4. using namespace std;
  5. int main()
  6. {
  7.   re:
  8.   system("cls");        
  9.   srand(time(NULL));
  10.   int com=0;
  11.   int player=0;
  12.   int mypoint=0;
  13.   int compoint=0;
  14.   int game=1;
  15.   for(int i=game;i<=3;i++)
  16.   {
  17.    string mora[]={"剪刀","石頭","布"};
  18.    cout<< "請輸入你想要出的拳   (1)剪刀(2)石頭(3)布" <<endl;
  19.    cin>>player;
  20.    cout<< "電腦出拳中..." <<endl;
  21.    com=(rand()%3)+1;
  22.    cout<< "電腦出" << mora[com-1] <<endl;
  23.    if(player==1&&com==3)
  24.    {
  25.    cout<<"你贏了"<<endl;
  26.    mypoint++;
  27.    }
  28.    else if(player==2&&com==1)
  29.    {
  30.    cout<<"你贏了"<<endl;
  31.    mypoint++;
  32.    }
  33.    else if(player==3&&com==2)
  34.    {
  35.    cout<<"你贏了"<<endl;
  36.    mypoint++;
  37.    }
  38.    else if(player==com)
  39.    cout<<"平手"<<endl;
  40.    else
  41.    {
  42.    cout<<"你輸了"<<endl;   
  43.    compoint++;
  44.    }   
  45.    if( mypoint == 2 || compoint == 2)
  46.    break;
  47.   }
  48.    if( mypoint> compoint )
  49.    cout<<"玩家贏了"<<endl;
  50.    if( compoint> mypoint )
  51.    cout<<"電腦贏了"<<endl;
  52.   system("pause");
  53.   goto re;
  54.   return 0;
  55. }
複製代碼

TOP

返回列表