返回列表 發帖
本帖最後由 洪翊展 於 2018-6-4 19:57 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int n=1, winner, balance=0, option, buyin, bet, player;
  7.     srand(time(NULL));
  8.     re:
  9.     system("cls");      
  10.     int s[]={0,0,0,0};
  11.     cout<<"「好事成雙」賽馬場 第 "<<n<<" 局"<<endl;
  12.     cout<<"-   -   -   -   -   -   -   -   -   -   -   終點"<<endl;
  13.     cout<<"1"<<endl;
  14.     cout<<"2"<<endl;
  15.     cout<<"3"<<endl;
  16.     cout<<"4"<<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.         cout<<"比賽即將開始..."<<endl<<endl;         
  52.     }
  53.     else if(option==3)
  54.     {
  55.         goto end;         
  56.     }
  57.     else
  58.     {
  59.         cout<<"輸入錯誤!";
  60.         _sleep(1500);
  61.         goto re;
  62.     }
  63.     system("pause");
  64.     while(true)
  65.     {
  66.         system("cls");
  67.         int r=rand()%4;   
  68.         s[r]++;   
  69.         cout<<"比賽進行中"<<endl;
  70.         cout<<"-   -   -   -   -   -   -   -   -   -   -   終點"<<endl;
  71.         for(int i=0; i<=s[0]; i++)
  72.             cout<<" ";
  73.         cout<<"1"<<endl;
  74.         for(int i=0; i<=s[1]; i++)
  75.             cout<<" ";
  76.         cout<<"2"<<endl;
  77.         for(int i=0; i<=s[2]; i++)
  78.             cout<<" ";
  79.         cout<<"3"<<endl;
  80.         for(int i=0; i<=s[3]; i++)
  81.             cout<<" ";
  82.         cout<<"4"<<endl;
  83.         if(s[r]==45)
  84.         {
  85.             winner=r+1;
  86.             break;
  87.         }
  88.         _sleep(60);                     
  89.     }
  90.     system("cls");
  91.     cout<<"比賽結束! 由 "<<winner<<" 號選手先馳得點!"<<endl;
  92.     cout<<"-   -   -   -   -   -   -   -   -   -   -   終點"<<endl;
  93.     for(int i=0; i<=s[0]; i++)
  94.         cout<<" ";
  95.     cout<<"1"<<endl;
  96.     for(int i=0; i<=s[1]; i++)
  97.         cout<<" ";
  98.     cout<<"2"<<endl;
  99.     for(int i=0; i<=s[2]; i++)
  100.         cout<<" ";
  101.     cout<<"3"<<endl;
  102.     for(int i=0; i<=s[3]; i++)
  103.         cout<<" ";
  104.     cout<<"4"<<endl;
  105.     n++;
  106.     if(winner==player)
  107.     {
  108.         cout<<"你贏了"<<bet*3<<"元!"<<endl;
  109.         balance+=bet*3;
  110.     }
  111.     else
  112.     {
  113.         cout<<"你輸了"<<bet<<"元!"<<endl;
  114.         balance-=bet;
  115.     }
  116.     system("pause");
  117.     goto re;
  118.    
  119.     end:
  120.     if(balance>0)
  121.     {
  122.     cout<<"恭喜你! 這次總共贏了"<<balance<<"元"<<endl;
  123.     cout<<endl<<"慢走!"<<endl;
  124.     }
  125.     else if(balance<0)
  126.     {
  127.     cout<<"不好意思! 讓你損失了"<<balance<<"元"<<endl;
  128.     cout<<endl<<"慢走!"<<endl;
  129.     }
  130.     else
  131.     {
  132.     cout<<"沒輸沒贏! 全身而退!"<<endl;
  133.     cout<<endl<<"慢走!"<<endl;
  134.     }
  135.     _sleep(1500);
  136.     return 0;
  137. }
複製代碼

TOP

返回列表