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

TOP

返回列表