返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     srand(time(NULL));
  7.     int x=1,balance=0,option,buyin,bet,player,wallet=0;
  8.     re:
  9.     system("cls");
  10.     string n[]={"1","2","3","4"};
  11.     int s[]={0,0,0,0};
  12.     int r;
  13.     cout<<"「好事成雙」賽馬場 第"<<x<<"局"<<endl;
  14.     cout<<"-------------------------------------------------------------------------| 終點"<<endl;
  15.     for(int i=0; i<4; i++)
  16.         cout<<n[i]<<endl;
  17.     cout<<endl<<"可用餘額: "<<balance<<"元"<<endl<<endl;   
  18.     cout<<"(1)買入 (2)下注 (3)離開 請選擇: ";
  19.     cin>>option;
  20.     if(option==1)
  21.     {
  22.         cout<<"買入: ";
  23.         cin>>buyin;
  24.         if(buyin<=0)
  25.         {
  26.              cout<<"輸入錯誤!";
  27.              _sleep(1500);
  28.              goto re;     
  29.         }
  30.         balance+=buyin;
  31.         goto re;         
  32.     }
  33.     else if(option==2)
  34.     {
  35.         cout<<"下注: ";
  36.         cin>>bet;
  37.         if(bet<=0)
  38.         {
  39.              cout<<"輸入錯誤!";
  40.              _sleep(1500);
  41.              goto re;     
  42.         }
  43.         if(bet>balance)
  44.         {
  45.              cout<<"可用餘額不足,請先買入!";
  46.              _sleep(1500);
  47.              goto re;     
  48.         }
  49.         cout<<endl<<"1號  2號  3號  4號  請選擇: ";
  50.         cin>>player;
  51.         if(player>=5 || player<=0)
  52.         {
  53.             cout<<"輸入錯誤!";
  54.             _sleep(1500);
  55.             goto re;
  56.         }
  57.         cout<<"比賽即將開始..."<<endl<<endl;         
  58.     }
  59.     else if(option==3)
  60.     {
  61.         goto end;         
  62.     }
  63.     else
  64.     {
  65.         cout<<"輸入錯誤!";
  66.         _sleep(1500);
  67.         goto re;
  68.     }
  69.     system("pause");
  70.     while(true)
  71.     {
  72.         cout<<"比賽進行中"<<endl;
  73.         cout<<"-------------------------------------------------------------------------| 終點"<<endl;
  74.         r=rand()%4;   
  75.         s[r]++;
  76.         for(int i=0; i<4; i++)
  77.         {
  78.             for(int j=0; j<s[i]; j++)
  79.                 cout<<" ";
  80.             cout<<n[i]<<endl;     
  81.         }
  82.         _sleep(10);
  83.         system("cls");
  84.         if(s[r]==76)
  85.             break;
  86.     }
  87.     cout<<"比賽結果! 由 "<<n[r]<<" 先馳得點!"<<endl;
  88.     cout<<"-------------------------------------------------------------------------| 終點"<<endl;
  89.     for(int i=0; i<4; i++)
  90.     {
  91.         for(int j=0; j<s[i]; j++)
  92.             cout<<" ";
  93.         cout<<n[i]<<endl;
  94.     }
  95.     if(player-1==r)
  96.     {
  97.         cout<<"獲得"<<bet*3<<"元"<<endl;
  98.         balance=bet*3+balance;
  99.         wallet+=bet+3;            
  100.     }else
  101.     {
  102.         cout<<"損失"<<bet<<"元"<<endl;
  103.         balance=balance-bet;
  104.         wallet-=bet;     
  105.     }
  106.     system("pause");
  107.     x++;
  108.     goto re;
  109.     end:
  110.     if(wallet==0)
  111.         cout<<"沒輸沒贏! 全身而退"<<endl<<endl;
  112.     else if(wallet>0)
  113.         cout<<"恭喜你! 這次總共贏了"<<wallet<<"元"<<endl<<endl;
  114.     else
  115.         cout<<"不好意思! 讓你損失了"<<-wallet<<"元"<<endl<<endl;
  116.     system("pause");
  117.     return 0;
  118. }
複製代碼

TOP

返回列表