返回列表 發帖
  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.     string mora[] = {"剪刀","石頭","布"};
  11.     cout<<"請出拳(1)剪刀(2)石頭(3)布"<<endl;
  12.     cin>>player;
  13.     cout<<"電腦出拳中..."<<endl;     
  14.     com=(rand()%3)+1;      
  15.     cout <<"你出:"<< mora[player-1] << endl;
  16.     cout <<"電腦出:"<< mora[com-1] << endl;   
  17.     if(player == 1&&com==3) {
  18.       cout << "你贏了" << endl;
  19.     }
  20.     else if(player ==2&&com==1) {
  21.       cout <<"你贏了"<< endl;
  22.     }
  23.     else if(player == 3&&com==2) {
  24.       cout <<"你贏了"<< endl;
  25.     }
  26.     else if(player == com) {
  27.     cout <<"平手"<< endl;
  28.    }
  29.    else {
  30.     cout <<"你輸了"<< endl;
  31.    }
  32.      system("pause");   
  33.     return 0;
  34. }
複製代碼

TOP

返回列表