返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int n=1,money=0,total=0;
  7.     re:
  8.     int a=0,b=0,c=0,d=0,r,option,buyin,bet,horse,winner;
  9.     system("cls");
  10.     cout<<"「好事成雙」賽馬場 第"<<n<<"局"<<endl;
  11.     cout<<"------------------------------------------------------------------------| 終點"<<endl;
  12.     cout<<"◆"<<endl;
  13.     cout<<"★"<<endl;
  14.     cout<<"▲"<<endl;
  15.     cout<<"●"<<endl;
  16.     cout<<"\n可用金額:"<<money<<"元\n"<<endl;
  17.     cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
  18.     cin>>option;
  19.     if(option==1)
  20.     {
  21.         cout<<"請買入:";
  22.         cin>>buyin;
  23.         if(buyin<0)
  24.         {
  25.             cout<<"您輸入的金額有誤,請重新買入!"<<endl;
  26.         }
  27.         money+=buyin;
  28.         goto re;            
  29.     }
  30.     else if(option==2)
  31.     {
  32.         cout<<"請下注:";
  33.         cin>>bet;
  34.         if(bet>money)
  35.         {
  36.             cout<<"您的金額不足,請重新下注!"<<endl;            
  37.             system("pause");
  38.             goto re;
  39.         }
  40.         else if(bet>=0 && bet<=money)
  41.         {
  42.             cout<<"(1)◆ (2)★ (3)▲ (4)● 請選擇:";
  43.             cin>>horse;
  44.             if(horse!=1 && horse!=2 && horse!=3 && horse!=4)
  45.             {
  46.                 cout<<"您輸入的編號有誤,請重新選擇!"<<endl;
  47.                 system("pause");
  48.                 goto re;               
  49.             }
  50.             else
  51.             {
  52.                 cout<<"比賽即將開始!\n\n";
  53.             }     
  54.         }
  55.         else
  56.         {
  57.             cout<<"您輸入的金額有誤,請重新下注!"<<endl;
  58.             system("pause");
  59.             goto re;   
  60.         }         
  61.     }
  62.     else if(option==3)
  63.     {
  64.         goto end;     
  65.     }
  66.     else
  67.     {
  68.         cout<<"您輸入錯誤,請重新選擇!"<<endl;
  69.         system("pause");
  70.         goto re;   
  71.     }
  72.     system("pause");
  73.     system("cls");
  74.     srand(time(NULL));
  75.     while(a!=70 && b!=70 && c!=70 && d!=70)
  76.     {
  77.         cout<<"比賽進行中"<<endl;
  78.         cout<<"------------------------------------------------------------------------| 終點"<<endl;
  79.         r=rand()%4+1;
  80.         if(r==1)
  81.         {
  82.             a++;        
  83.         }
  84.         if(r==2)
  85.         {
  86.             b++;        
  87.         }
  88.         if(r==3)
  89.         {
  90.             c++;        
  91.         }
  92.         if(r==4)
  93.         {
  94.             d++;        
  95.         }
  96.         for(int i=0;i<=a;i++)
  97.         {
  98.             cout<<" ";        
  99.         }
  100.         cout<<"◆"<<endl;
  101.         for(int i=0;i<=b;i++)
  102.         {
  103.             cout<<" ";        
  104.         }
  105.         cout<<"★"<<endl;
  106.         for(int i=0;i<=c;i++)
  107.         {
  108.             cout<<" ";        
  109.         }
  110.         cout<<"▲"<<endl;
  111.         for(int i=0;i<=d;i++)
  112.         {
  113.             cout<<" ";        
  114.         }
  115.         cout<<"●"<<endl;
  116.         system("cls");            
  117.     }
  118.     cout<<"比賽結束!由";
  119.     if(a==70)
  120.     {
  121.         cout<<"◆";
  122.         winner=1;         
  123.     }
  124.     if(b==70)
  125.     {
  126.         cout<<"★";
  127.         winner=2;        
  128.     }
  129.     if(c==70)
  130.     {
  131.         cout<<"▲";
  132.         winner=3;      
  133.     }
  134.     if(d==70)
  135.     {
  136.         cout<<"●";
  137.         winner=4;         
  138.     }
  139.     cout<<"先馳得點!"<<endl;
  140.     cout<<"------------------------------------------------------------------------| 終點"<<endl;
  141.     for(int i=0;i<=a;i++)
  142.     {
  143.         cout<<" ";        
  144.     }
  145.     cout<<"◆"<<endl;
  146.     for(int i=0;i<=b;i++)
  147.     {
  148.         cout<<" ";        
  149.     }
  150.     cout<<"★"<<endl;
  151.     for(int i=0;i<=c;i++)
  152.     {
  153.         cout<<" ";        
  154.     }
  155.     cout<<"▲"<<endl;
  156.     for(int i=0;i<=d;i++)
  157.     {
  158.         cout<<" ";        
  159.     }
  160.     cout<<"●"<<endl;
  161.     if(horse==winner)
  162.     {
  163.         money+=bet*3;
  164.         cout<<"贏了"<<bet*3<<"元!"<<endl;
  165.         total+=bet*3;                 
  166.     }
  167.     else
  168.     {
  169.         money-=bet;
  170.         cout<<"損失"<<bet<<"元!"<<endl;
  171.         total-=bet;
  172.     }
  173.     system("pause");
  174.     system("cls");
  175.     n++;
  176.     goto re;
  177.     end:
  178.     if(total>0)
  179.     {
  180.         cout<<"\n恭喜您,贏了"<<total<<"元!\n"<<endl;
  181.     }
  182.     else if(total<0)
  183.     {
  184.         cout<<"\n不好意思,讓您損失了"<<-total<<"元!\n"<<endl;
  185.     }
  186.     else
  187.     {
  188.         cout<<"\n不輸不贏,全身而退!\n"<<endl;
  189.     }
  190.     cout<<"謝謝光臨,下次再來!"<<endl;
  191.     system("pause");
  192.     return 0;   
  193. }
複製代碼

TOP

返回列表