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

TOP

返回列表