返回列表 發帖
  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 my=0;
  11.     int comp=0;
  12.     int game=1;
  13.     string mora[]={"剪刀","石頭","布"};
  14.     for(int i=game;i<=3;i++)
  15.     {
  16.     cout<<"輸入你要的拳(1:剪刀,2:石頭,3:布)"<<endl;
  17.     cin>>player;
  18.     cout<<"電腦出拳中"<<endl;
  19.     com=(rand()%3)+1;
  20.     cout << "你出:" << mora[player-1] << endl;
  21.     cout << "電腦出:" << mora[com-1] << endl;
  22.     if(player==com)
  23.     {
  24.         cout<<"平手"<<endl;
  25.     }
  26.     else if(player==1&&com==3)
  27.     {
  28.         cout<<"贏"<<endl;
  29.         my++;
  30.     }
  31.     else if(player==2&&com==1)
  32.     {
  33.         cout<<"贏"<<endl;
  34.         my++;
  35.     }
  36.     else if(player==3&&com==2)
  37.     {
  38.         cout<<"贏"<<endl;
  39.         my++;
  40.     }
  41.     else
  42.     {
  43.         cout<<"輸"<<endl;
  44.         comp++;
  45.     }
  46.     if(my==2||comp==2)
  47.     {break;
  48.     }
  49. }
  50.      if(my>comp)
  51.      {
  52.      cout<<"你贏"<<endl;           
  53.      }
  54.      else
  55.      {cout<<"我贏了"<<endl;
  56.      }
  57.     system("pause");
  58.     return 0;     
  59. }
複製代碼

TOP

返回列表