返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     cout<<"猜拳遊戲"<<endl;
  7.     srand(time(NULL));
  8.     int player,computer;
  9.     int win=0,lose=0,tie=0;
  10.     string name[3]={"剪刀","石頭","布"};
  11.     cout<<"請出拳! (1)剪刀(2)石頭(3)布(0)結束 :";
  12.     if(player==0)
  13.     goto end;
  14.     cin>>player;
  15.     computer=rand()%3+1;
  16.     cout<<"你出"<<name[player-1]<<endl;
  17.     cout<<"電腦出"<<name[computer-1]<<endl;
  18.     if(player==computer)
  19.     {
  20.       cout<<"平手!!!"<<endl;
  21.       tie+=1;                  
  22.     }
  23.     if((player==1&&computer==3)||(player==2&&computer==1)||(player==3&&computer==2))
  24.     {
  25.       cout<<"你贏了!!!"<<endl;
  26.       win+=1;                  
  27.     }
  28.     else
  29.     {
  30.       cout<<"你輸了!!!"<<endl;
  31.       lose+=1;   
  32.     }
  33.     end:
  34.         {
  35.           cout<<"戰果統計"<<endl;
  36.           cout<<"贏了"<<win<<"次"<<"輸了"<<lose<<"次"<<"平手了"<<tie<<"次"<<endl<<
  37.                     
  38.                   
  39.         }
  40.     system("pause");
  41.     return 0;
  42. }
複製代碼

TOP

返回列表