返回列表 發帖
#include<iostream>
#include<cstdlib>
#include<time.h>
using namespace std;
int main()
{
    srand(time(NULL));
    int player=0;
    int com=0;
    int mypoint=0;
    int compoint=0;
    int game=1;
   
    for(int i=game;i<4;i++)
    {
    string mora[] = {"剪刀","石頭","布"};
    cout<<"玩家:"<<mypoint<<"            第"<<i<<"局"<<"           電腦:"<<compoint<<endl;
    cout<<"======================================================="<<endl;
    cout<<"請出拳(1)剪刀(2)石頭(3)布"<<endl;
    cin>>player;
    cout<<"電腦出拳中..."<<endl;     
    com=(rand()%3)+1;      
    cout <<"你出:"<< mora[player-1] << endl;
    cout <<"電腦出:"<< mora[com-1] << endl;           
     if(player == 1&&com==3)
     {
        cout << "你贏了" << endl;
        mypoint++;
     }
    else if(player ==2&&com==1)
     {
        cout <<"你贏了"<< endl;
        mypoint++;
     }
    else if(player == 3&&com==2)
     {
        cout <<"你贏了"<< endl;
        mypoint++;
     }
    else if(player == com)
     {
        cout <<"平手"<< endl;
     }
    else
     {
        cout <<"你輸了"<< endl;
        compoint++;
     }
     if(mypoint == 2 ||compoint == 2)   
     {
       break;
     }
       cout<<"======================================================="<<endl;
       cout<<endl;
      
    }
    cout<<"玩家:"<<mypoint<<"           電腦:"<<compoint<<endl;
   
    if(mypoint>compoint)
    {
    cout<<"你贏了"<<endl;
    }
    else if(player == com)
     {
        cout <<"平手"<< endl;
     }
    else
    {
    cout<<"你輸了"<<endl;
    }
   
    system("pause");   
    return 0;
}

TOP

  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.     }
  57.     cout<<"玩家:"<<mypoint<<"           電腦:"<<compoint<<endl;
  58.    
  59.     if(mypoint>compoint)
  60.     {
  61.     cout<<"你贏了"<<endl;
  62.     }
  63.     else if(player == com)
  64.      {
  65.         cout <<"平手"<< endl;
  66.      }
  67.     else
  68.     {
  69.     cout<<"你輸了"<<endl;
  70.     }
  71.    
  72.     system("pause");   
  73.     return 0;
  74. }
複製代碼

TOP

返回列表