返回列表 發帖
  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<<"玩家:"<<mypoint<<"            第"<<i<<"局"<<"           電腦:"<<compoint<<endl;
  18.     cout<<"======================================================="<<endl;
  19.     cout<<"請出拳(1)剪刀(2)石頭(3)布"<<endl;
  20.     cin>>player;
  21.     cout<<"電腦出拳中..."<<endl;     
  22.     com=(rand()%3)+1;      
  23.     cout <<"你出:"<< mora[player-1] << endl;
  24.     cout <<"電腦出:"<< mora[com-1] << endl;           
  25.      if(player == 1&&com==3)
  26.      {
  27.         cout << "你贏了" << endl;
  28.         mypoint++;
  29.      }
  30.     else if(player ==2&&com==1)
  31.      {
  32.         cout <<"你贏了"<< endl;
  33.         mypoint++;
  34.      }
  35.     else if(player == 3&&com==2)
  36.      {
  37.         cout <<"你贏了"<< endl;
  38.         mypoint++;
  39.      }
  40.     else if(player == com)
  41.      {
  42.         cout <<"平手"<< endl;
  43.      }
  44.     else
  45.      {
  46.         cout <<"你輸了"<< endl;
  47.         compoint++;
  48.      }
  49.      if(mypoint == 2 ||compoint == 2)   
  50.      {
  51.        break;
  52.      }
  53.        cout<<"======================================================="<<endl;
  54.        cout<<endl;
  55.     }
  56.     cout<<"玩家:"<<mypoint<<"           電腦:"<<compoint<<endl;
  57.    
  58.     if(mypoint>compoint)
  59.     {
  60.     cout<<"你贏了"<<endl;
  61.     }
  62.     else
  63.     {
  64.     cout<<"你輸了"<<endl;
  65.     }
  66.    
  67.     system("pause");   
  68.     return 0;
  69. }
複製代碼

TOP

返回列表