返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int n=1,f=0;
  7.     re:
  8.     int a=0,b=0,c=0,d=0,r,j,k,bet,horse;
  9.     system("cls");
  10.     cout<<"「好事成雙」賽馬場 第"<<n<<"局"<<endl;
  11.     cout<<"------------------------------------------------------------------------| 終點"<<endl;
  12.     cout<<"◆"<<endl;
  13.     cout<<"★"<<endl;
  14.     cout<<"▲"<<endl;
  15.     cout<<"●"<<endl;
  16.     cout<<endl;
  17.     cout<<"可用餘額: "<<f<<"元"<<endl;
  18.     cout<<"(1)買入(2)下注(3)離開 請選擇: "<<endl;
  19.     cin>>j;
  20.     if(j==1)
  21.     {
  22.         cout<<"買入: ";
  23.         cin>>k;
  24.         f+=k;   
  25.         goto re;
  26.     }else if(j==2)
  27.     {
  28.         cout<<"請下注";
  29.         cin>>bet;
  30.         if(bet>k)
  31.         {
  32.             cout<<"您餘額不足,請重新下注!"<<endl;
  33.             system("pause");
  34.             goto re;
  35.         }else if(bet>=0 && bet<= f)
  36.         {
  37.                 f-=bet;
  38.                 cout<<"(1)◆ (2)★ (3)▲(4)● 請選擇:";
  39.                 cin>>horse;
  40.                 cout<<"比賽即將開始"<<endl;
  41.         }else
  42.         {
  43.             cout<<"您輸入錯誤!!請重新下注!"<<endl;
  44.             system("pause");
  45.             goto re;   
  46.         }
  47.         
  48.     }else
  49.     {
  50.         goto end;
  51.     }
  52.      
  53.     system("pause");
  54.     system("cls"); //清空畫面
  55.     srand(time(NULL)); //撒亂樹種子
  56.    
  57.     while(a!=70 && b!=70 && c!=70&& d!=70) //判斷四隻馬只要有一隻到終點就跳離while
  58.     {
  59.           cout<<"賽馬進行中"<<endl;
  60.           cout<<"------------------------------------------------------------------------| 終點"<<endl;         
  61.             r = rand()%4+1;  //產生1~4亂數  隨機挑馬1~4其中一隻
  62.             if(r==1)
  63.                 a++;  
  64.             if(r==2)
  65.                 b++;  
  66.             if(r==3)
  67.                 c++;  
  68.             if(r==4)
  69.                 d++;  
  70.                
  71.                  
  72.              for(int i=0;i<=a;i++)  //第一匹馬前進
  73.              {
  74.                   cout<<" ";
  75.              }
  76.              cout<<"◆"<<endl;
  77.              for(int i=0;i<=b;i++)  //第二匹馬前進
  78.              {
  79.                   cout<<" ";
  80.              }
  81.              cout<<"★"<<endl;
  82.              for(int i=0;i<=c;i++)  //第三匹馬前進
  83.              {
  84.                   cout<<" ";
  85.              }
  86.              cout<<"▲"<<endl;
  87.              for(int i=0;i<=d;i++)  //第四匹馬前進
  88.              {     
  89.                    cout<<" ";
  90.              }
  91.              cout<<"●"<<endl;
  92.              system("cls"); //清空畫面
  93.     }
  94.      
  95.      
  96.      cout<<"賽馬結束!";
  97.      if(a==70)
  98.      {
  99.         cout<<"由◆先馳得點!"<<endl;
  100.      }else if(b==70)
  101.      {
  102.         cout<<"由★先馳得點!"<<endl;
  103.      }else if(c==70)
  104.      {
  105.         cout<<"由▲先馳得點!"<<endl;
  106.      }else
  107.      {
  108.         cout<<"由●先馳得點!"<<endl;
  109.      }
  110.       
  111.       
  112.       
  113.    
  114.      cout<<"------------------------------------------------------------------------| 終點"<<endl;      
  115.      for(int i=0;i<=a;i++)  //第一匹馬最後的位子
  116.      {      
  117.              cout<<" ";
  118.      }
  119.      cout<<"◆"<<endl;
  120.      for(int i=0;i<=b;i++)  //第二匹馬最後的位子
  121.      {        
  122.               cout<<" ";
  123.      }
  124.      cout<<"★"<<endl;
  125.      for(int i=0;i<=c;i++)  //第三匹馬最後的位子
  126.      {
  127.               cout<<" ";
  128.      }
  129.      cout<<"▲"<<endl;
  130.      for(int i=0;i<=d;i++)  //第四匹馬最後的位子
  131.      {     
  132.               cout<<" ";
  133.      }
  134.      cout<<"●"<<endl;
  135.     n++; //加一場
  136.     system("pause");
  137.     system("cls");
  138.     goto re;
  139.     end:
  140.     system("pause");
  141.     return 0;   
  142. }
複製代碼

TOP

返回列表