返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<time.h>
  4. using namespace std;
  5. int main()
  6. {         
  7.     int player=0;
  8.     int com=0;
  9.     cout<<"請出拳(1剪刀.2石頭3布)"<<endl;
  10.     cin>>player;
  11.     cout<<"電腦出拳中。。。"<<endl;
  12.     srand(time(NULL));
  13.     com=rand()%3+1;
  14.     if(com==1)
  15.     {
  16.       cout<<"電腦出剪刀"<<endl;
  17.     }
  18.     else if(com==2)
  19.     {
  20.       cout<<"電腦出石頭"<<endl;
  21.     }
  22.     else if(com==3)
  23.     {
  24.       cout<<"電腦出布"<<endl;
  25.     }
  26.     if(player==1&&com==1)
  27.     {
  28.       cout<<"平手"<<endl;   
  29.     }
  30.     else if(player==1&&com==2)
  31.     {
  32.       cout<<"你輸了"<<endl;   
  33.     }
  34.     else if(player==1&&com==3)
  35.     {
  36.       cout<<"你贏了"<<endl;   
  37.     }
  38.     else if(player==2&&com==1)
  39.     {
  40.       cout<<"你贏了"<<endl;   
  41.     }
  42.     else if(player==2&&com==2)
  43.     {
  44.       cout<<"平手"<<endl;   
  45.     }
  46.     else if(player==2&&com==3)
  47.     {
  48.       cout<<"你輸了"<<endl;   
  49.     }
  50.     else if(player==3&&com==1)
  51.     {
  52.       cout<<"你輸了"<<endl;   
  53.     }
  54.     else if(player==3&&com==2)
  55.     {
  56.       cout<<"你贏了"<<endl;   
  57.     }
  58.     else if(player==3&&com==3)
  59.     {
  60.       cout<<"平手"<<endl;   
  61.     }
  62.     system("pause");
  63.     return 0;
  64. }
複製代碼

TOP

返回列表