返回列表 發帖
  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]<<endl;
  23.         cout << "電腦出:"<<card[com]<<endl;
  24.         if(player==1&&com==3)
  25.         {
  26.             cout<<win[0]<<endl;
  27.             mypoint++;
  28.         }
  29.         if(player==1&&com==2)
  30.         {
  31.             cout<<win[1]<<endl;
  32.             compoint++;
  33.         }
  34.         if(player==2&&com==1)
  35.         {
  36.             cout<<win[0]<<endl;
  37.             mypoint++;
  38.         }
  39.         if(player==2&&com==3)
  40.         {
  41.             cout<<win[1]<<endl;
  42.             compoint++;
  43.         }
  44.         if(player==3&&com==2)
  45.         {
  46.             cout<<win[0]<<endl;
  47.             mypoint++;
  48.         }
  49.         if(player==2&&com==3)
  50.         {
  51.             cout<<win[1]<<endl;
  52.             compoint++;
  53.         }
  54.         else
  55.         {
  56.             cout<<win[2]<<endl;
  57.         }
  58.         if(compoint==2||mypoint==2)
  59.             break;   
  60.     }
  61.     cout<<"\t玩家: "<<mypoint<<"電腦: "<<compoint<<endl;
  62.     if(mypoint>compoint)
  63.     {
  64.         cout<<win[0]<<endl;
  65.     }
  66.     else
  67.     {
  68.         cout<<win[1]<<endl;
  69.     }
  70.     system("PAUSE");
  71.     return 0;
  72. }
複製代碼

TOP

返回列表