返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     int n =1,blance=0;
  8.     re:   
  9.     system("cls");
  10.     int a=0,b=0,c=0,d=0,r, option, buyin =0,bet,horse,winer ;   

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

  155.     n++;
  156.     system("pause");
  157.     goto re;     
  158.     end:
  159.     system("pause");  
  160.     return 0;   
  161. }
複製代碼

TOP

返回列表