返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     int n =1,blance=0,money=0;
  8.     re:   
  9.     system("cls");
  10.     int a=0,b=0,c=0,d=0,r, option, buyin =0,bet,horse,winer ; // 每匹馬前進的進度   
  11.    
  12.     string words ="賽馬進行中";

  13.     string name[4] = {"◆","★","▲","●"};
  14.    
  15.     int position =0;
  16.     cout<<"「好事成雙」賽馬場 第"<<n<<"局"<<endl;
  17.     cout<<"------------------------------------------------------------------------| 終點"<<endl;
  18.     cout<<"◆"<<endl;
  19.     cout<<"★"<<endl;
  20.     cout<<"▲"<<endl;
  21.     cout<<"●"<<endl;
  22.     cout<<endl;
  23.     cout<<"可用餘額:"<<blance<<"元"<<endl;
  24.     cout<<endl;
  25.     cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
  26.     cin>>option;
  27.    
  28.     if(option==1)
  29.     {
  30.         cout<<"買入:";
  31.         cin>>buyin;
  32.         blance += buyin;
  33.         goto re;
  34.     }else if(option==2)
  35.     {
  36.         cout<<"請下注:";
  37.         cin>>bet;
  38.         if(bet > blance)
  39.         {
  40.            cout<<"您餘額不足,請重新下注!"<<endl;            
  41.            system("pause");
  42.            goto re;
  43.         }else if(bet >0 && bet<=blance)
  44.         {
  45.            cout<<"(1)◆ (2)★ (3)▲(4)●請選擇:";
  46.            cin>>horse;
  47.            blance -= bet;
  48.            cout<<"即將開始賽馬!"<<endl;
  49.         }else
  50.         {
  51.            cout<<"您輸入錯誤,請重新下注!"<<endl;            
  52.            system("pause");
  53.            goto re;
  54.         }
  55.         
  56.     }else
  57.     {   
  58.         goto end;
  59.     }
  60.    
  61.     system("pause");
  62.     system("cls");
  63.     srand(time(NULL));
  64.   
  65.     while(a<70 && b<70 && c<70 && d<70)
  66.     {  
  67.    
  68.       r = rand()%4+1;

  69.       switch(r)
  70.       {
  71.           case 1:
  72.                a++;
  73.                break;
  74.           case 2:
  75.                b++;
  76.                break;
  77.           case 3:
  78.                c++;
  79.                break;
  80.           case 4:
  81.                d++;
  82.                break;
  83.       }
  84.       
  85.    
  86.       if(a==70 || b==70 || c==70 || d==70)
  87.       {  
  88.          if(a==70)
  89.          {         
  90.               position = 0;
  91.               winer = 1;
  92.          }
  93.          if(b==70)
  94.          {         
  95.               position =1;
  96.               winer = 2;
  97.          }
  98.          if(c==70)
  99.          {         
  100.               position =2;
  101.               winer = 3;
  102.          }
  103.          if(d==70)
  104.          {         
  105.               position =3;
  106.               winer =4;
  107.          }         
  108.          
  109.          words = "比賽結束!由"+name[position]+"先馳得點!";
  110.       }
  111.       
  112.       cout<<words<<endl;
  113.       cout<<"------------------------------------------------------------------------| 終點"<<endl;   
  114.       
  115.       for(int i=0;i<=a;i++)
  116.       {
  117.           cout<<" ";
  118.       }
  119.       cout<<name[0]<<endl;
  120.       
  121.       for(int i=0;i<=b;i++)
  122.       {
  123.           cout<<" ";
  124.       }
  125.       cout<<name[1]<<endl;
  126.       
  127.       for(int i=0;i<=c;i++)
  128.       {
  129.           cout<<" ";
  130.       }
  131.       cout<<name[2]<<endl;
  132.       
  133.       for(int i=0;i<=d;i++)
  134.       {
  135.           cout<<" ";
  136.       }
  137.       cout<<name[3]<<endl;
  138.       
  139.       if(a<=69 && b<=69 && c<=69 && d<=69)
  140.       {           
  141.         system("cls");
  142.       }
  143.       
  144.     }
  145.    
  146.     if(horse == winer)
  147.     {
  148.         blance = blance + bet*3;

  149.         money = money + bet*3;
  150.         cout<<"您贏了"<<bet*3<<"元"<<endl;
  151.     }else
  152.     {

  153.         money = money -bet;
  154.         cout<<"損失"<<bet<<"元"<<endl;
  155.     }
  156.   
  157.     n++;
  158.     system("pause");
  159.     goto re;     
  160.     end:
  161.    
  162.     if(money ==0 )
  163.     {
  164.        cout<<"沒輸沒贏! 全身而退!"<<endl;
  165.     }else if( money > 0)
  166.     {
  167.        cout<<"恭喜你! 這次總共贏了"<<money<<"元"<<endl;
  168.     }else
  169.     {
  170.        cout<<"不好意思! 讓你損失了"<<-money<<"元"<<endl;
  171.     }
  172.     cout<<endl;
  173.     cout<<"謝謝光臨! 下次再來!"<<endl;
  174.     system("pause");  
  175.     return 0;   
  176. }
複製代碼

TOP

返回列表