返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.    
  8.     int n =1,blance=0;
  9.     re:   
  10.     system("cls");
  11.     int a=0,b=0,c=0,d=0,r, option, buyin =0,bet,horse,winer ;
  12.    
  13.    
  14.     string words ="賽馬進行中";
  15.   
  16.     string name[4] = {"◆","★","▲","●"};
  17.    

  18.     int position =0;
  19.     cout<<"「好事成雙」賽馬場 第"<<n<<"局"<<endl;
  20.     cout<<"------------------------------------------------------------------------| 終點"<<endl;
  21.     cout<<"◆"<<endl;
  22.     cout<<"★"<<endl;
  23.     cout<<"▲"<<endl;
  24.     cout<<"●"<<endl;
  25.     cout<<endl;
  26.     cout<<"可用餘額:"<<blance<<"元"<<endl;
  27.     cout<<endl;
  28.     cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
  29.     cin>>option;
  30.    

  31.     if(option==1)
  32.     {
  33.         cout<<"買入:";
  34.         cin>>buyin;
  35.         blance += buyin;
  36.         goto re;
  37.     }else if(option==2)
  38.     {
  39.         cout<<"請下注:";
  40.         cin>>bet;
  41.         if(bet > blance)
  42.         {
  43.            cout<<"您餘額不足,請重新下注!"<<endl;            
  44.            system("pause");
  45.            goto re;
  46.         }else if(bet >0 && bet<=blance)
  47.         {
  48.            cout<<"(1)◆ (2)★ (3)▲(4)●請選擇:";
  49.            cin>>horse;
  50.            blance -= bet;
  51.            cout<<"即將開始賽馬!"<<endl;
  52.         }else
  53.         {
  54.            cout<<"您輸入錯誤,請重新下注!"<<endl;            
  55.            system("pause");
  56.            goto re;
  57.         }
  58.         
  59.     }else
  60.     {
  61.            
  62.         goto end;
  63.     }
  64.    
  65.     system("pause");
  66.     system("cls");
  67.     srand(time(NULL));
  68.   
  69.     while(a<=70 && b<=70 && c<=70 && d<=70)
  70.     {  
  71.       cout<<words<<endl;
  72.       cout<<"------------------------------------------------------------------------| 終點"<<endl;   
  73.      
  74.       r = rand()%4+1;
  75.    
  76.       switch(r)
  77.       {
  78.           case 1:
  79.                a++;
  80.                break;
  81.           case 2:
  82.                b++;
  83.                break;
  84.           case 3:
  85.                c++;
  86.                break;
  87.           case 4:
  88.                d++;
  89.                break;
  90.       }
  91.       
  92.      
  93.       for(int i=0;i<=a;i++)
  94.       {
  95.           cout<<" ";
  96.       }
  97.       cout<<name[0]<<endl;
  98.       
  99.      
  100.       for(int i=0;i<=b;i++)
  101.       {
  102.           cout<<" ";
  103.       }
  104.       cout<<name[1]<<endl;
  105.       
  106.       
  107.       for(int i=0;i<=c;i++)
  108.       {
  109.           cout<<" ";
  110.       }
  111.       cout<<name[2]<<endl;
  112.       
  113.      
  114.       for(int i=0;i<=d;i++)
  115.       {
  116.           cout<<" ";
  117.       }
  118.       cout<<name[3]<<endl;
  119.       
  120.    
  121.       if(a==70 || b==70 || c==70 || d==70)
  122.       {  
  123.          if(a==70)
  124.          {         
  125.               position = 0;
  126.               winer = 1;
  127.          }
  128.          if(b==70)
  129.          {         
  130.               position =1;
  131.               winer = 2;
  132.          }
  133.          if(c==70)
  134.          {         
  135.               position =2;
  136.               winer = 3;
  137.          }
  138.          if(d==70)
  139.          {         
  140.               position =3;
  141.               winer =4;
  142.          }         
  143.          
  144.          words = "比賽結束!由"+name[position]+"先馳得點!";
  145.       }
  146.      
  147.       if(a==71 || b==71 || c==71 || d==71)
  148.       {               
  149.       }else{      
  150.         system("cls");
  151.       }
  152.       
  153.     }
  154.    

  155.     if(horse == winer)
  156.     {

  157.         blance = blance + bet*3;
  158.         cout<<"您贏了"<<bet*3<<"元"<<endl;
  159.     }else
  160.     {
  161.         cout<<"損失"<<bet<<"元"<<endl;
  162.     }
  163.      
  164.     n++;
  165.     system("pause");
  166.     goto re;     
  167.     end:
  168.     system("pause");  
  169.     return 0;   
  170. }
複製代碼

TOP

返回列表