返回列表 發帖
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <time.h>
  4. using namespace std;
  5. int main()
  6. {
  7.     string card[3]={"剪刀","石頭","布"};
  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<<"第"<<i<<"局"<<"\t玩家: "<<mypoint<<"電腦: "<<compoint<<endl;
  17.         cout<<"輸入你要的拳(1.剪刀2.石頭3.布)"<<endl;
  18.         cin>>player;
  19.         cout<<"電腦出拳中..."<<endl;
  20.         srand(time(NULL));
  21.         com=(rand()%3)+1;
  22.         cout << "你出:"<<card[player-1]<<endl;
  23.         cout << "電腦出:"<<card[com-1
  24.         ]<<endl;
  25.         if(player==1&&com==3)
  26.         {
  27.             cout<<win[0]<<endl;
  28.             mypoint++;
  29.         }
  30.         if(player==1&&com==2)
  31.         {
  32.             cout<<win[1]<<endl;
  33.             compoint++;
  34.         }
  35.         if(player==2&&com==1)
  36.         {
  37.             cout<<win[0]<<endl;
  38.             mypoint++;
  39.         }
  40.         if(player==2&&com==3)
  41.         {
  42.             cout<<win[1]<<endl;
  43.             compoint++;
  44.         }
  45.         if(player==3&&com==2)
  46.         {
  47.             cout<<win[0]<<endl;
  48.             mypoint++;
  49.         }
  50.         if(player==2&&com==3)
  51.         {
  52.             cout<<win[1]<<endl;
  53.             compoint++;
  54.         }
  55.         else
  56.         {
  57.             cout<<win[2]<<endl;
  58.         }
  59.         if(compoint==2||mypoint==2)
  60.             break;   
  61.     }
  62.     cout<<"\t玩家: "<<mypoint<<"電腦: "<<compoint<<endl;
  63.     if(mypoint>compoint)
  64.     {
  65.         cout<<win[0]<<endl;
  66.     }
  67.     else if(compoint==mypoint)
  68.     {
  69.          cout<<win[2]<<endl;
  70.     }
  71.     else
  72.     {
  73.         cout<<win[1]<<endl;
  74.     }
  75.     system("PAUSE");
  76.     return 0;
  77. }
複製代碼

TOP

返回列表