返回列表 發帖
本帖最後由 陳妍蓁 於 2024-8-10 11:58 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     int n=0,m=0,sum=0,m1,m2,r,x;
  8.     int option1,option2;
  9.     string h[]={"◆","★","▲","●"};
  10.     int a[]={0,0,0,0};
  11.     srand(time(NULL));
  12.     re:
  13.         system("cls");
  14.         cout<<"好事成雙賽馬場 第"<<x<<"局"<<endl;
  15.         cout<<"----------------------------------------------------------------------------|終點"<<endl;
  16.         for(int i=0;i<=3;i++)
  17.             cout<<h[i]<<endl;
  18.     re2:
  19.         cout<<endl<<"可用餘額"<<m<<"元"<<endl<<endl;
  20.         cout<<"(1)買入 (2)下注 (3)離開 請選擇:"<<endl;
  21.         cin>>option1;
  22.         if(option1==1){
  23.             cout<<"(1)買入:";
  24.             cin>>m1;
  25.             cout<<"元"<<endl;
  26.             if(m1<=0){
  27.                 cout<<"輸入錯誤"<<endl;
  28.                 _sleep(1500);
  29.                 goto re;
  30.             }
  31.             m=m1++;
  32.             sum+=m1;
  33.             goto re;
  34.         }
  35.         else if (option1==2){
  36.             cout<<"下注:";
  37.             cin>>m2;
  38.             if(m2<=0 || m2>m){
  39.                 cout<<"輸入錯誤"<<endl;
  40.                 _sleep(1500);
  41.                 goto re;
  42.             }
  43.             cout<<"請選擇:(1)◆ (2)★ (3)▲ (4)●";
  44.             cin>>option2;
  45.             cout<<"比賽即將開始..."<<endl;

  46.         }
  47.         else if(option1==3){
  48.             goto end;
  49.         }
  50.         else
  51.             goto re;
  52.         system("pause");

  53.         while(true){
  54.             system("cls");
  55.             cout<<"比賽進行中"<<endl;
  56.             cout<<"-------------------------------------------------------------------------| 終點"<<endl;
  57.             r=rand()%4;
  58.             a[r]++;
  59.             _sleep(5);
  60.             for(int i=0;i<=a[0];i++)
  61.                 cout<<" ";
  62.                 cout<<"◆"<<endl;
  63.             for(int i=0;i<=a[1];i++)
  64.                 cout<<" ";
  65.                 cout<<"★"<<endl;
  66.             for(int i=0;i<=a[2];i++)
  67.                 cout<<" ";
  68.                 cout<<"▲"<<endl;
  69.             for(int i=0;i<=a[3];i++)
  70.                 cout<<" ";
  71.                 cout<<"●"<<endl;

  72.             if(a[r]==73){
  73.                 break;
  74.                 _sleep(50);
  75.                 system("cls");
  76.             }
  77.         }
  78.             system("cls");
  79.             cout<<"比賽結束 由:"<<h[r]<<"勝出"<<endl;
  80.             cout<<"----------------------------------------------------------------------------| 終點"<<endl;
  81.             for(int i=0;i<=a[0];i++)
  82.                 cout<<" ";
  83.                 cout<<"◆"<<endl;
  84.             for(int i=0;i<=a[1];i++)
  85.                 cout<<" ";
  86.                 cout<<"★"<<endl;
  87.             for(int i=0;i<=a[2];i++)
  88.                 cout<<" ";
  89.                 cout<<"▲"<<endl;
  90.             for(int i=0;i<=a[3];i++)
  91.                 cout<<" ";
  92.                 cout<<"●"<<endl;

  93.             if(option2==r+1){
  94.                 cout<<"賺到"<<m2*3<<"元"<<endl;
  95.                 m+=m2*3;
  96.             }
  97.             else{
  98.                 cout<<"賠"<<m2<<"元"<<endl;
  99.                 m-=m2;
  100.             }

  101.             system("pause");
  102.             r++;
  103.             goto re;
  104.     end:
  105.         if(sum==m)
  106.             cout<<"沒輸沒贏!全身而退!"<<endl<<endl;
  107.         else if(sum<m)
  108.             cout<<"恭喜你!這次總共贏了"<<m-sum<<"元!"<<endl<<endl;
  109.         else if(sum>m)
  110.             cout<<"不好意思!讓你損失了"<<sum-m<<"元!"<<endl<<endl;

  111.         cout<<"謝謝光臨,下次再來"<<endl;
  112.         _sleep(50);
  113.         return 0;
  114. }
複製代碼

TOP

返回列表