返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<time.h>
  4. using namespace std;
  5. int main()
  6. {
  7.   re:
  8.   system("cls");        
  9.   srand(time(NULL));
  10.   int com=0;
  11.   int player=0;
  12.   int mypoint=0;
  13.   int compoint=0;
  14.   int game=1;
  15.   cout<< "==========☆★☆猜拳遊戲☆★☆==========" <<endl;
  16.   cout<<endl;
  17.   for(int i=game;i<=3;i++)
  18.   {
  19.    string mora[]={"剪刀","石頭","布"};
  20.    cout<< "   玩家:"<<mypoint<<"       第"<<i<<"局     "<<"     電腦:"<<compoint<<endl;
  21.    cout<< "========================================" <<endl;
  22.    cout<< "請輸入你想要出的拳   (1)剪刀(2)石頭(3)布" <<endl;
  23.    cin>>player;
  24.    cout<< "電腦出拳中..." <<endl;
  25.    com=(rand()%3)+1;
  26.    cout<<"你出"<<mora[player-1]<<endl;
  27.    cout<< "電腦出" << mora[com-1] <<endl;
  28.    if(player==1&&com==3)
  29.    {
  30.    cout<<"你贏了"<<endl;
  31.    mypoint++;
  32.    }
  33.    else if(player==2&&com==1)
  34.    {
  35.    cout<<"你贏了"<<endl;
  36.    mypoint++;
  37.    }
  38.    else if(player==3&&com==2)
  39.    {
  40.    cout<<"你贏了"<<endl;
  41.    mypoint++;
  42.    }
  43.    else if(player==com)
  44.    cout<<"平手"<<endl;
  45.    else
  46.    {
  47.    cout<<"你輸了"<<endl;   
  48.    compoint++;
  49.    }   
  50.    if( mypoint == 2 || compoint == 2)
  51.    break;
  52.    cout<<endl;
  53.   }
  54.    cout<< "========================================" <<endl;
  55.    cout<<endl;
  56.    cout<<"玩家:"<<mypoint<<endl;
  57.    cout<<"電腦:"<<compoint<<endl;
  58.    cout<<endl;
  59.    if( mypoint> compoint )
  60.    cout<<"玩家贏了"<<endl;
  61.    if( compoint> mypoint )
  62.    cout<<"電腦贏了"<<endl;
  63.   system("pause");
  64.   goto re;
  65.   return 0;
  66. }
複製代碼

TOP

返回列表