返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     // 開局第一場
  8.     int n =1,x=0,money=0;
  9.     re:   
  10.     system("cls");
  11.     int a=0,b=0,c=0,d=0,r, option, buyin =0,bet,horse,winer ; // 每匹馬前進的進度   
  12.     string words ="賽馬進行中";
  13.     // 代表馬的名子
  14.     string name[4] = {"◆","★","▲","●"};
  15.    
  16.     // 宣告一個暫存的變數
  17.     int position =0;
  18.     cout<<"「智慧」賽馬場 第"<<n<<"局"<<endl;
  19.     cout<<"------------------------------------------------------------------------| 終點"<<endl;
  20.     cout<<"◆"<<endl;
  21.     cout<<"★"<<endl;
  22.     cout<<"▲"<<endl;
  23.     cout<<"●"<<endl;
  24.     cout<<endl;
  25.     cout<<"可用餘額:"<<x<<"元"<<endl;
  26.     cout<<endl;
  27.     cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
  28.     cin>>option;
  29.    
  30.     // 如果買入 把錢加入餘額
  31.     if(option==1)
  32.     {
  33.         cout<<"買入:";
  34.         cin>>buyin;
  35.        x += buyin;
  36.         goto re;
  37.     }else if(option==2)
  38.     {
  39.         cout<<"請下注:";
  40.         cin>>bet;
  41.         if(bet > x)
  42.         {
  43.            cout<<"您餘額不足,請重新下注!"<<endl;            
  44.            system("pause");
  45.            goto re;
  46.         }else if(bet >0 && bet<=x)
  47.         {
  48.            cout<<"(1)◆ (2)★ (3)▲(4)●請選擇:";
  49.            cin>>horse;
  50.            x -= 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"); // 按下enter 才開始
  66.     system("cls"); // 清空畫面
  67.     srand(time(NULL)); // 撒種子亂數
  68.   
  69.     while(a<70 && b<70 && c<70 && d<70)
  70.     {  
  71.       
  72.       // 隨機挑一匹馬
  73.       r = rand()%4+1;
  74.       // 每匹馬 跑的進度
  75.       switch(r)
  76.       {
  77.           case 1:
  78.                a++;
  79.                break;
  80.           case 2:
  81.                b++;
  82.                break;
  83.           case 3:
  84.                c++;
  85.                break;
  86.           case 4:
  87.                d++;
  88.                break;
  89.       }
  90.       if(a==70 || b==70 || c==70 || d==70)
  91.       {  
  92.          if(a==70)
  93.          {
  94.              position = 0;
  95.              winer = 1;   
  96.          }
  97.               
  98.          if(b==70)
  99.          {
  100.               position =1;
  101.               winer = 2;   
  102.          }
  103.          
  104.          if(c==70)
  105.          {
  106.               position =2;
  107.               winer = 3;   
  108.          }
  109.               
  110.          if(d==70)
  111.          {
  112.               position =3;
  113.               winer = 4;      
  114.          }           
  115.          
  116.          words = "比賽結束!由"+name[position]+"先馳得點!";
  117.       }
  118.       cout<<words<<endl;
  119.       cout<<"------------------------------------------------------------------------| 終點"<<endl;   
  120.       
  121.       // 要把每匹馬的進度給輸出
  122.       // 第一匹馬
  123.       for(int i=0;i<=a;i++)
  124.       {
  125.           cout<<" ";
  126.       }
  127.       cout<<name[0]<<endl;
  128.       
  129.       // 第二匹馬
  130.       for(int i=0;i<=b;i++)
  131.       {
  132.           cout<<" ";
  133.       }
  134.       cout<<name[1]<<endl;
  135.       
  136.        // 第三匹馬
  137.       for(int i=0;i<=c;i++)
  138.       {
  139.           cout<<" ";
  140.       }
  141.       cout<<name[2]<<endl;
  142.       
  143.       // 第四匹馬
  144.       for(int i=0;i<=d;i++)
  145.       {
  146.           cout<<" ";
  147.       }
  148.       cout<<name[3]<<endl;
  149.       
  150.    
  151.       
  152.       if(a<=69 && b<=69 && c<=69 && d<=69)
  153.       {               
  154.             
  155.         system("cls");
  156.       }
  157.       
  158.     }
  159.     if(horse == winer)
  160.     {
  161.        x = x +bet*3;
  162.        money = money -bet;
  163.        cout<<"您贏了"<<bet*3<<"元"<<endl;      
  164.     }else
  165.     {
  166.         money = money -bet;
  167.         cout<<"損失"<<bet<<"元"<<endl;
  168.     }
  169.     n++;                  
  170.     system("pause");
  171.     goto re;
  172.     end:
  173.     if(money ==0)
  174.     {
  175.         cout<<"沒輸沒贏! 全身而退!"<<endl;
  176.     }else if(money > 0)
  177.     {
  178.         cout<<"恭喜你! 這次總共贏了"<<money<<"元"<<endl;  
  179.     }else
  180.     {
  181.        cout<<"不好意思! 讓你損失了"<<-money<<"元"<<endl;  
  182.     }
  183.     system("pause");
  184.     return 0;   
  185. }
複製代碼

TOP

返回列表