返回列表 發帖
本帖最後由 鄭楀諺 於 2018-5-26 14:11 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<time.h>
  4. using namespace std;
  5. int main()
  6. {
  7.     int random=0,round=1;
  8.     int money=0,ans=0,bet=0,newmoney=0,exit=0,got=0,loose=0;
  9.     srand(time(NULL));
  10.     while(true)
  11.     {
  12.             bool in=true;
  13.             int numh=0,numh1=0,numh2=0,numh3=0,numh4=0;
  14.             int h1=0,h2=0,h3=0,h4=0;
  15.             while(in)
  16.             {
  17.                     cout<<"第"<<round<<"局"<<endl;
  18.                     cout<<"「好事成雙」賽馬場"<<endl;
  19.                     cout<<"|-------------------------------------------------------------------------|終點"<<endl;                                                                        
  20.                     cout<<"◆"<<endl;
  21.                     cout<<"★"<<endl;
  22.                     cout<<"▲"<<endl;
  23.                     cout<<"●"<<endl;           
  24.                     cout<<"可用餘額"<<money<<"元"<<endl;
  25.                     cout<<"(1)買入    (2)下注    (3)離開 請選擇:";
  26.                     cin>>ans;
  27.                     if(ans==1)
  28.                     {
  29.                       cout<<"買入:";
  30.                       cin>>newmoney;
  31.                       if(newmoney<=0)
  32.                       {
  33.                               cout<<"輸入錯誤!"<<endl;
  34.                               _sleep(500);
  35.                                 }
  36.                                 else
  37.                                 {
  38.                                         money=money+newmoney;
  39.                                 }  
  40.                     }
  41.                     if(ans==2)
  42.                     {
  43.                             cout<<"下注:";
  44.                     cin>>bet;
  45.                     if(bet<=0)
  46.                     {
  47.                                cout<<"輸入錯誤!";
  48.                                _sleep(500);
  49.                     }
  50.                     if(bet>money)
  51.                     {
  52.                                cout<<"餘額不足!";
  53.                                _sleep(500);
  54.                     }
  55.                     else
  56.                     {
  57.                         in=false;
  58.                         cout<<"(1)  ◆"<<endl;
  59.                                         cout<<"(2)  ★"<<endl;
  60.                                         cout<<"(3)  ▲"<<endl;
  61.                                         cout<<"(4)  ●"<<endl;
  62.                                         cout<<"請輸入下注馬匹代碼:"<<endl;
  63.                                         cin>>numh;
  64.                                         if(numh==1)
  65.                                         {
  66.                                                 numh1++;
  67.                                         }
  68.                                         if(numh==2)
  69.                                         {
  70.                                                 numh2++;
  71.                                         }
  72.                                         if(numh==3)
  73.                                         {
  74.                                                 numh3++;
  75.                                         }
  76.                                         if(numh==4)
  77.                                         {
  78.                                                 numh4++;
  79.                                         }
  80.                                         if(numh>4)
  81.                                         {
  82.                                                 cout<<"餘額不足!";
  83.                                        _sleep(500);
  84.                                         }
  85.                     }
  86.                     }
  87.                     if(ans==3)
  88.                     {
  89.                               if(loose>got)
  90.                               {
  91.                                            cout<<"不好意思! 讓你損失了"<<loose<<"元!"<<endl;
  92.                               }
  93.                               if(loose<got)
  94.                               {
  95.                                            cout<<"恭喜你! 這次總共贏了"<<got<<"元!"<<endl;
  96.                               }
  97.                               if(loose==got)
  98.                               {
  99.                                   cout<<"沒輸沒贏! 全身而退!"<<endl;
  100.                               }
  101.                     cout<<"謝謝光臨,下次再會"<<endl;
  102.                     in=false;
  103.                                 exit=1;
  104.                                 _sleep(5000);
  105.                     }
  106.                     if(ans>3)
  107.                     {
  108.                             cout<<"輸入錯誤!";
  109.                             _sleep(500);
  110.                         }
  111.                     system("cls");
  112.             }
  113.             if(exit!=0)
  114.             {
  115.                     break;
  116.                 }
  117.             while(h1!=75&&h2!=75&&h3!=75&&h4!=75)
  118.             {
  119.                 random=rand()%4;
  120.                 if(random==0)
  121.                 {
  122.                     h1++;
  123.                 }
  124.                 if(random==1)
  125.                 {
  126.                     h2++;
  127.                 }
  128.                 if(random==2)
  129.                 {
  130.                     h3++;
  131.                 }
  132.                 if(random==3)
  133.                 {
  134.                     h4++;
  135.                 }
  136.                 cout<<"比賽進行中"<<endl;
  137.                 cout<<"|-------------------------------------------------------------------------|終點"<<endl;
  138.                 for(int i=0;i<=h1;i++)
  139.                 {
  140.                 cout<<" ";
  141.                 }
  142.                         cout<<"◆"<<endl;
  143.                         for(int i=0;i<=h2;i++)
  144.                 {
  145.                 cout<<" ";
  146.                 }
  147.                         cout<<"★"<<endl;
  148.                         for(int i=0;i<=h3;i++)
  149.                 {
  150.                 cout<<" ";
  151.                 }
  152.                         cout<<"▲"<<endl;
  153.                         for(int i=0;i<=h4;i++)
  154.                 {
  155.                 cout<<" ";
  156.                 }
  157.                         cout<<"●"<<endl;
  158.                         system("cls");
  159.             }
  160.             round++;
  161.             system("cls");
  162.             cout<<"比賽結束! 由";
  163.             if(h1==75)
  164.             {
  165.             cout<<"◆搶先得馳"<<endl;
  166.             numh1++;
  167.             }
  168.             if(h2==75)
  169.             {
  170.             cout<<"★搶先得馳"<<endl;
  171.             numh2++;
  172.             }
  173.             if(h3==75)
  174.             {
  175.             cout<<"▲搶先得馳"<<endl;
  176.             numh3++;
  177.             }
  178.             if(h4==75)
  179.             {
  180.             cout<<"●搶先得馳"<<endl;
  181.             numh4++;
  182.             }
  183.                 if(numh1==2)
  184.                 {
  185.                         cout<<"恭喜您!您賺了"<<bet<<"元!"<<endl;
  186.                         money=money+bet;
  187.                         got=bet+got;
  188.                 }
  189.                 else if(numh2==2)
  190.                 {
  191.                         cout<<"恭喜您!您賺了"<<bet<<"元!"<<endl;
  192.                         money=money+bet;
  193.                         got=bet+got;
  194.                 }
  195.                 else if(numh3==2)
  196.                 {
  197.                         cout<<"恭喜您!您賺了"<<bet<<"元!"<<endl;
  198.                         money=money+bet;
  199.                         got=bet+got;
  200.                 }
  201.                 else if(numh4==2)
  202.                 {
  203.                         cout<<"恭喜您!您賺了"<<bet<<"元!"<<endl;
  204.                         money=money+bet;
  205.                         got=bet+got;
  206.                 }
  207.                 else
  208.                 {
  209.                         cout<<"唉!今天運氣不好啊!一不小心就虧了"<<bet<<"元!"<<endl;
  210.                         money=money-bet;
  211.                         loose=bet+loose;
  212.                 }  
  213.     }        
  214.     return 0;
  215. }
複製代碼

TOP

返回列表