返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<time.h>
  4. using namespace std;
  5. int main()
  6. {
  7.     srand(time(NULL));
  8.     int player=0;
  9.     int com=0;
  10.     int mypoint=0;
  11.     int compoint=0;
  12.     int game=1;
  13.    
  14.     for(int i=game;i<4;i++)
  15.     {
  16.     string mora[] = {"剪刀","石頭","布"};
  17.     cout<<"請出拳(1)剪刀(2)石頭(3)布"<<endl;
  18.     cin>>player;
  19.     cout<<"電腦出拳中..."<<endl;     
  20.     com=(rand()%3)+1;      
  21.     cout <<"你出:"<< mora[player-1] << endl;
  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.      {
  40.         cout <<"平手"<< endl;
  41.      }
  42.     else
  43.      {
  44.         cout <<"你輸了"<< endl;
  45.         compoint++;
  46.      }
  47.      if(mypoint == 2 ||compoint == 2)   
  48.     {
  49.        break;
  50.     }
  51.     }
  52.    
  53.     if(mypoint>compoint)
  54.     {
  55.     cout<<"你贏了"<<endl;
  56.     }
  57.     else
  58.     {
  59.     cout<<"你輸了"<<endl;
  60.     }
  61.    
  62.     system("pause");   
  63.     return 0;
  64. }
複製代碼

TOP

返回列表