返回列表 發帖
  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.     // 當有任一匹跑到終點70 的時候就跳離迴圈
  14.     string words ="賽馬進行中";
  15.     // 代表馬的名子
  16.     string name[4] = {"◆","★","▲","●"};
  17.    
  18.     // 宣告一個暫存的變數
  19.     int position =0;
  20.     cout<<"「好事成雙」賽馬場 第"<<n<<"局"<<endl;
  21.     cout<<"------------------------------------------------------------------------| 終點"<<endl;
  22.     cout<<"◆"<<endl;
  23.     cout<<"★"<<endl;
  24.     cout<<"▲"<<endl;
  25.     cout<<"●"<<endl;
  26.     cout<<endl;
  27.     cout<<"可用餘額:"<<blance<<"元"<<endl;
  28.     cout<<endl;
  29.     cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
  30.     cin>>option;
  31.    
  32.     // 如果買入 把錢加入餘額
  33.     if(option==1)
  34.     {
  35.         cout<<"買入:";
  36.         cin>>buyin;
  37.         blance += buyin;
  38.         goto re;
  39.     }else if(option==2)
  40.     {
  41.         cout<<"請下注:";
  42.         cin>>bet;
  43.         if(bet > blance)
  44.         {
  45.            cout<<"您餘額不足,請重新下注!"<<endl;            
  46.            system("pause");
  47.            goto re;
  48.         }else if(bet >0 && bet<=blance)
  49.         {
  50.            cout<<"(1)◆ (2)★ (3)▲(4)●請選擇:";
  51.            cin>>horse;
  52.            blance -= bet;
  53.            cout<<"即將開始賽馬!"<<endl;
  54.         }else
  55.         {
  56.            cout<<"您輸入錯誤,請重新下注!"<<endl;            
  57.            system("pause");
  58.            goto re;
  59.         }
  60.         
  61.     }else
  62.     {
  63.        // 離開      
  64.         goto end;
  65.     }
  66.    
  67.     system("pause"); // 按下enter 才開始
  68.     system("cls"); // 清空畫面
  69.     srand(time(NULL)); // 撒種子亂數
  70.   
  71.     while(a<=70 && b<=70 && c<=70 && d<=70)
  72.     {  
  73.       cout<<words<<endl;
  74.       cout<<"------------------------------------------------------------------------| 終點"<<endl;   
  75.       // 隨機挑一匹馬
  76.       r = rand()%4+1;
  77.       // 每匹馬 跑的進度
  78.       switch(r)
  79.       {
  80.           case 1:
  81.                a++;
  82.                break;
  83.           case 2:
  84.                b++;
  85.                break;
  86.           case 3:
  87.                c++;
  88.                break;
  89.           case 4:
  90.                d++;
  91.                break;
  92.       }
  93.       
  94.       // 要把每匹馬的進度給輸出
  95.       // 第一匹馬
  96.       for(int i=0;i<=a;i++)
  97.       {
  98.           cout<<" ";
  99.       }
  100.       cout<<name[0]<<endl;
  101.       
  102.       // 第二匹馬
  103.       for(int i=0;i<=b;i++)
  104.       {
  105.           cout<<" ";
  106.       }
  107.       cout<<name[1]<<endl;
  108.       
  109.        // 第三匹馬
  110.       for(int i=0;i<=c;i++)
  111.       {
  112.           cout<<" ";
  113.       }
  114.       cout<<name[2]<<endl;
  115.       
  116.       // 第四匹馬
  117.       for(int i=0;i<=d;i++)
  118.       {
  119.           cout<<" ";
  120.       }
  121.       cout<<name[3]<<endl;
  122.       
  123.    
  124.       if(a==70 || b==70 || c==70 || d==70)
  125.       {  
  126.          if(a==70)
  127.          {         
  128.               position = 0;
  129.               winer = 1;
  130.          }
  131.          if(b==70)
  132.          {         
  133.               position =1;
  134.               winer = 2;
  135.          }
  136.          if(c==70)
  137.          {         
  138.               position =2;
  139.               winer = 3;
  140.          }
  141.          if(d==70)
  142.          {         
  143.               position =3;
  144.               winer =4;
  145.          }         
  146.          
  147.          words = "比賽結束!由"+name[position]+"先馳得點!";
  148.       }
  149.       if(a==71 || b==71 || c==71 || d==71)
  150.       {               
  151.       }else{      
  152.         system("cls");
  153.       }
  154.       
  155.     }
  156.    

  157.     if(horse == winer)
  158.     {

  159.         blance = blance + bet*3;
  160.         cout<<"您贏了"<<bet*3<<"元"<<endl;
  161.     }else
  162.     {
  163.         cout<<"損失"<<bet<<"元"<<endl;
  164.     }
  165.    

  166.     n++;
  167.     system("pause");
  168.     goto re;     
  169.     end:
  170.     system("pause");  
  171.     return 0;   
  172. }
複製代碼

TOP

返回列表