返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     int t=1,z=0,money=0;
  8.     re:
  9.     system("cls");  
  10.     int a=0,b=0,c=0,d=0,r,tmp=0,o,buy=0,bet,horse,winer;
  11.     string words ="賽馬進行中";
  12.     string name[4] = {"◆","★","▲","●"};
  13.     cout<<"「好事成雙」賽馬場"<<"第"<<t<<"局"<<endl;
  14.     cout<<"------------------------------------------------------------------------| 終點"<<endl;
  15.     cout<<"◆"<<endl;
  16.     cout<<"★"<<endl;
  17.     cout<<"▲"<<endl;
  18.     cout<<"●"<<endl<<endl;
  19.     cout<<"可用餘額:"<<z<<"元"<<endl<<endl;
  20.     cout<<"(1)買入 (2)下注 (3)離開 請選擇:";  
  21.     cin>>o;
  22.     if(o==1)
  23.     {
  24.         cout<<"買入:";
  25.         cin>>buy;
  26.         z += buy;
  27.         goto re;
  28.     }else if(o==2)
  29.     {
  30.         cout<<"請下注:";
  31.         cin>>bet;
  32.         if(bet > z)
  33.         {
  34.            cout<<"您餘額不足,請重新下注!"<<endl;
  35.         }else if(bet >0 && bet<=z)
  36.         {
  37.            cout<<"(1)◆ (2)★ (3)▲(4)●請選擇:";
  38.            cin>>horse;
  39.            z -= bet;
  40.            cout<<"即將開始賽馬!"<<endl;
  41.         }else
  42.         {
  43.            cout<<"您輸入錯誤,請重新下注!"<<endl;
  44.             system("pause");
  45.             goto re;
  46.         }
  47.     }else
  48.     {
  49.         goto end;
  50.     }
  51.     system("pause");
  52.     system("cls");
  53.     srand(time(NULL));
  54.     while(a<70 && b<70 && c<70 && d<70)
  55.     {
  56.         r = rand()%4+1;
  57.         switch(r)
  58.         {
  59.             case 1:
  60.                  a++;
  61.                  break;
  62.             case 2:
  63.                  b++;
  64.                  break;
  65.             case 3:
  66.                  c++;
  67.                  break;
  68.             case 4:
  69.                  d++;      
  70.         }
  71.         if(a==70 || b==70 || c==70 || d==70)
  72.         {
  73.             if(a==70)
  74.             {
  75.                 tmp = 0;
  76.                 winer = 1;         
  77.             }
  78.             if(b==70)
  79.             {
  80.                 tmp = 1;
  81.                 winer = 2;         
  82.             }
  83.             if(c==70)
  84.             {
  85.                 tmp = 2;
  86.                 winer = 3;         
  87.             }
  88.             if(d==70)
  89.             {
  90.                 tmp =3;
  91.                 winer = 4;         
  92.             }
  93.             words = "比賽結束!由"+name[tmp]+"先馳得點!";;        
  94.         }
  95.         cout<<words<<endl;   
  96.         cout<<"------------------------------------------------------------------------| 終點"<<endl;  
  97.         for(int i=0;i<=a;i++)
  98.         {
  99.             cout<<" ";        
  100.         }
  101.         cout<<name[0]<<endl;  
  102.         for(int i=0;i<=b;i++)
  103.         {
  104.             cout<<" ";        
  105.         }
  106.         cout<<name[1]<<endl;  
  107.         for(int i=0;i<=c;i++)
  108.         {
  109.             cout<<" ";        
  110.         }
  111.         cout<<name[2]<<endl;  
  112.         for(int i=0;i<=d;i++)
  113.         {
  114.             cout<<" ";        
  115.         }
  116.         cout<<name[3]<<endl;

  117.         if(a<=69 && b<=69 && c<=69 && d<=69)
  118.         {
  119.             system("cls");     
  120.         }
  121.     }
  122.         if(horse == winer)
  123.         {
  124.             z = z + bet*3;
  125.             cout<<"您贏了"<<bet*3<<"元"<<endl;
  126.             money = money + bet*3;
  127.         }else
  128.         {
  129.             cout<<"損失"<<bet<<"元"<<endl;
  130.             money = money - bet;
  131.         }   
  132.     system("pause");
  133.     t++;   
  134.     goto re;
  135.     end:
  136.     if(money ==0 )
  137.     {
  138.        cout<<"沒輸沒贏! 全身而退!"<<endl;
  139.     }else if( money > 0)
  140.     {
  141.        cout<<"恭喜你! 這次總共贏了"<<money<<"元"<<endl;
  142.     }else
  143.     {
  144.        cout<<"不好意思! 讓你損失了"<<-money<<"元"<<endl;
  145.     }
  146.     system("pause");  
  147.     return 0;   
  148. }
複製代碼

TOP

返回列表