返回列表 發帖
本帖最後由 鄭楀諺 於 2018-4-21 14:56 編輯
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <time.h>
  4. using namespace std;
  5. int main()
  6. {
  7.     //剪刀石頭布
  8.     string win[3]={"你贏","電腦贏","平手"};
  9.     int player=0;
  10.     int com=0;
  11.     int game=1;
  12.     int mypoint=0;
  13.     int compoint=0;
  14.     for(int i=game;i<=3;i++)
  15.     {
  16.         cout<<"輸入你要的拳(1.剪刀2.石頭3.布)"<<endl;
  17.         cin>>player;
  18.         cout<<"電腦出拳中..."<<endl;
  19.         srand(time(NULL));
  20.         com=(rand()%3)+1;
  21.         if(player==1&&com==3)
  22.         {
  23.             cout<<win[0]<<endl;
  24.             mypoint++;
  25.         }
  26.         if(player==1&&com==2)
  27.         {
  28.             cout<<win[1]<<endl;
  29.             compoint++;
  30.         }
  31.         if(player==2&&com==1)
  32.         {
  33.             cout<<win[0]<<endl;
  34.             mypoint++;
  35.         }
  36.         if(player==2&&com==3)
  37.         {
  38.             cout<<win[1]<<endl;
  39.             compoint++;
  40.         }
  41.         if(player==3&&com==2)
  42.         {
  43.             cout<<win[0]<<endl;
  44.             mypoint++;
  45.         }
  46.         if(player==2&&com==3)
  47.         {
  48.             cout<<win[1]<<endl;
  49.             compoint++;
  50.         }
  51.         else
  52.         {
  53.             cout<<win[2]<<endl;
  54.         }
  55.         if(compoint==2||mypoint==2)
  56.             break;
  57.     }
  58.     if(mypoint>compoint)
  59.     {
  60.         cout<<win[0]<<endl;
  61.     }
  62.     else
  63.     {
  64.         cout<<win[1]<<endl;
  65.     }
  66.     system("PAUSE");
  67.     return 0;
  68. }
複製代碼
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <time.h>
  4. using namespace std;
  5. int main()
  6. {
  7.     //剪刀石頭布
  8.     string win[3]={"你贏","電腦贏","平手"};
  9.     int player=0;
  10.     int com=0;
  11.     int game=1;
  12.     int mypoint=0;
  13.     int compoint=0;
  14.     cout<<"輸入你要的拳(1.剪刀2.石頭3.布)"<<endl;
  15.     cin>>player;
  16.     cout<<"電腦出拳中..."<<endl;
  17.     srand(time(NULL));
  18.     com=(rand()%3)+1;
  19.     for(int i=game;i<=3;i++)
  20.     {
  21.         if(player==1&&com==3)
  22.         {
  23.             cout<<win[0]<<endl;
  24.             mypoint++;
  25.         }
  26.         if(player==1&&com==2)
  27.         {
  28.             cout<<win[1]<<endl;
  29.             compoint++;
  30.         }
  31.         if(player==2&&com==1)
  32.         {
  33.             cout<<win[0]<<endl;
  34.             mypoint++;
  35.         }
  36.         if(player==2&&com==3)
  37.         {
  38.             cout<<win[1]<<endl;
  39.             compoint++;
  40.         }
  41.         if(player==3&&com==2)
  42.         {
  43.             cout<<win[0]<<endl;
  44.             mypoint++;
  45.         }
  46.         if(player==2&&com==3)
  47.         {
  48.             cout<<win[1]<<endl;
  49.             compoint++;
  50.         }
  51.         else
  52.         {
  53.             cout<<win[2]<<endl;
  54.         }
  55.         if(compoint==2||mypoint==2)
  56.             break;
  57.     }
  58.     if(mypoint>compoint)
  59.     {
  60.         cout<<win[0]<<endl;
  61.     }
  62.     else
  63.     {
  64.         cout<<win[1]<<endl;
  65.     }
  66.     system("PAUSE");
  67.     return 0;
  68. }
複製代碼

TOP

返回列表