返回列表 發帖
  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;
  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.     }
  27.      
  28.     system("pause");
  29.     system("cls"); //清空畫面
  30.     srand(time(NULL)); //撒亂樹種子
  31.    
  32.     while(a!=70 && b!=70 && c!=70&& d!=70) //判斷四隻馬只要有一隻到終點就跳離while
  33.     {
  34.           cout<<"賽馬進行中"<<endl;
  35.           cout<<"------------------------------------------------------------------------| 終點"<<endl;         
  36.             r = rand()%4+1;  //產生1~4亂數  隨機挑馬1~4其中一隻
  37.             if(r==1)
  38.                 a++;  
  39.             if(r==2)
  40.                 b++;  
  41.             if(r==3)
  42.                 c++;  
  43.             if(r==4)
  44.                 d++;  
  45.                
  46.                  
  47.              for(int i=0;i<=a;i++)  //第一匹馬前進
  48.              {
  49.                   cout<<" ";
  50.              }
  51.              cout<<"◆"<<endl;
  52.              for(int i=0;i<=b;i++)  //第二匹馬前進
  53.              {
  54.                   cout<<" ";
  55.              }
  56.              cout<<"★"<<endl;
  57.              for(int i=0;i<=c;i++)  //第三匹馬前進
  58.              {
  59.                   cout<<" ";
  60.              }
  61.              cout<<"▲"<<endl;
  62.              for(int i=0;i<=d;i++)  //第四匹馬前進
  63.              {     
  64.                    cout<<" ";
  65.              }
  66.              cout<<"●"<<endl;
  67.              system("cls"); //清空畫面
  68.     }
  69.      
  70.      
  71.      cout<<"賽馬結束!";
  72.      if(a==70)
  73.      {
  74.         cout<<"由◆先馳得點!"<<endl;
  75.      }else if(b==70)
  76.      {
  77.         cout<<"由★先馳得點!"<<endl;
  78.      }else if(c==70)
  79.      {
  80.         cout<<"由▲先馳得點!"<<endl;
  81.      }else
  82.      {
  83.         cout<<"由●先馳得點!"<<endl;
  84.      }
  85.       
  86.       
  87.       
  88.    
  89.      cout<<"------------------------------------------------------------------------| 終點"<<endl;      
  90.      for(int i=0;i<=a;i++)  //第一匹馬最後的位子
  91.      {      
  92.              cout<<" ";
  93.      }
  94.      cout<<"◆"<<endl;
  95.      for(int i=0;i<=b;i++)  //第二匹馬最後的位子
  96.      {        
  97.               cout<<" ";
  98.      }
  99.      cout<<"★"<<endl;
  100.      for(int i=0;i<=c;i++)  //第三匹馬最後的位子
  101.      {
  102.               cout<<" ";
  103.      }
  104.      cout<<"▲"<<endl;
  105.      for(int i=0;i<=d;i++)  //第四匹馬最後的位子
  106.      {     
  107.               cout<<" ";
  108.      }
  109.      cout<<"●"<<endl;
  110.     n++; //加一場
  111.     system("pause");
  112.     system("cls");
  113.     goto re;
  114.     system("pause");
  115.     return 0;   
  116. }
複製代碼

TOP

返回列表