返回列表 發帖

賽馬程式 (二)

本帖最後由 王瑞喻 於 2019-12-28 14:30 編輯

讓馬匹隨機往終點移動


本帖隱藏的內容需要回復才可以瀏覽
附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int h[4]={0,0,0,0};
  7.     srand(time(NULL));
  8.     cout<<"賽馬場"<<endl;
  9.     cout<<"-------------------------------------------------------------------------|終點"<<endl;
  10.     cout<<"◆"<<endl;
  11.     cout<<"★"<<endl;
  12.     cout<<"▲"<<endl;
  13.     cout<<"●"<<endl;
  14.     system("pause");
  15.     while(true)
  16.     {
  17.         cout<<"比賽進行中"<<endl;
  18.         cout<<"-------------------------------------------------------------------------|終點"<<endl;
  19.         int r=rand()%4;
  20.         h[r]++;
  21.         for(int i=1;i<=h[0];i++)
  22.         {
  23.             cout<<" ";
  24.         }
  25.         cout<<"◆"<<endl;
  26.         for(int i=1;i<=h[1];i++)
  27.         {
  28.             cout<<" ";
  29.         }
  30.         cout<<"★"<<endl;
  31.         for(int i=1;i<=h[2];i++)
  32.         {
  33.             cout<<" ";
  34.         }
  35.         cout<<"▲"<<endl;
  36.         for(int i=1;i<=h[3];i++)
  37.         {
  38.             cout<<" ";
  39.         }
  40.         cout<<"●"<<endl;
  41.         if(h[r]==72)
  42.         {
  43.             break;
  44.         }
  45.         system("cls");
  46.     }
  47.     system("pause");
  48.     return 0;
  49. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int h[4]={0,0,0,0};
  7.     srand(time(NULL));
  8.     cout<<"賽馬場"<<endl;
  9.     cout<<"-------------------------------------------------------------------------|終點"<<endl;
  10.     cout<<"◆"<<endl;
  11.     cout<<"★"<<endl;
  12.     cout<<"▲"<<endl;
  13.     cout<<"●"<<endl;
  14.     system("pause");
  15.     while(true)
  16.     {
  17.         cout<<"比賽進行中"<<endl;
  18.         cout<<"-------------------------------------------------------------------------|終點"<<endl;
  19.         int r=rand()%4;
  20.         h[r]++;
  21.         for(int i=1;i<=h[0];i++)
  22.         {
  23.             cout<<" ";
  24.         }
  25.         cout<<"◆"<<endl;
  26.         for(int i=1;i<=h[1];i++)
  27.         {
  28.             cout<<" ";
  29.         }
  30.         cout<<"★"<<endl;
  31.         for(int i=1;i<=h[2];i++)
  32.         {
  33.             cout<<" ";
  34.         }
  35.         cout<<"▲"<<endl;
  36.         for(int i=1;i<=h[3];i++)
  37.         {
  38.             cout<<" ";
  39.         }
  40.         cout<<"●"<<endl;
  41.         if(h[r]==72)
  42.         {
  43.             break;
  44.         }
  45.         system("cls");
  46.     }
  47.     system("pause");
  48.     return 0;
  49. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     cout<<"[好事成雙]賽馬場\n----------------------------------------------------------|終點"<<endl;
  7.     cout<<"▲"<<endl;
  8.     cout<<"◆"<<endl;
  9.     cout<<"★"<<endl;
  10.     cout<<"●"<<endl;
  11.     system("pause");
  12.     system("cls");
  13.     srand(time(NULL));
  14.     int h[4]={0,0,0,0};
  15.     while(true)
  16.     {
  17.             cout<<"比賽進行中\n------------------------------------------------------------|終點"<<endl;
  18.             int r=rand()%4;
  19.             h[r]++;
  20.             for(int i=0;i<=h[0];i++)
  21.                     cout<<" ";
  22.             cout<<"▲"<<endl;
  23.             for(int i=0;i<=h[1];i++)
  24.                     cout<<" ";
  25.             cout<<"◆"<<endl;
  26.             for(int i=0;i<=h[2];i++)
  27.                     cout<<" ";
  28.             cout<<"★"<<endl;
  29.             for(int i=0;i<=h[3];i++)
  30.                     cout<<" ";
  31.             cout<<"●"<<endl;
  32.             if(h[r]==60)
  33.                        break;
  34.             _sleep(30);
  35.             system("cls");
  36.     }
  37.     system("pause");
  38.     return 0;
  39. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int r ;
  7.     srand(time(NULL));
  8.     int h[4] = {0,0,0,0};
  9.     cout<<"賽馬場"<<endl<<"----------------------------------------終點"<<endl;
  10.     cout<<"◆"<<endl<<"★"<<endl<<"▲"<<endl<<"●"<<endl;
  11.     system("pause");
  12.     system("cls");
  13.     while(true)   
  14.     {
  15.     cout<<"比賽中"<<endl<<"----------------------------------------終點"<<endl;   
  16.         r = rand()%4;
  17.         h[r]++;
  18.         for(int i=1;i<=h[0];i++)
  19.         {
  20.             cout<<" ";            
  21.         }
  22.         cout<<"◆"<<endl;
  23.         for(int i=1;i<=h[1];i++)
  24.         {
  25.             cout<<" ";            
  26.         }
  27.         cout<<"★"<<endl;for(int i=1;i<=h[2];i++)
  28.         {
  29.             cout<<" ";            
  30.         }
  31.         cout<<"▲"<<endl;for(int i=1;i<=h[3];i++)
  32.         {
  33.             cout<<" ";            
  34.         }
  35.         cout<<"●"<<endl;
  36.         if(h[r]>=40)
  37.             break;
  38.         _sleep(10);
  39.         system("cls");
  40.     }
  41.     system("pause");
  42.     return 0;
  43. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int r=rand()%4;
  7.     srand(time(NULL));
  8.     cout<<"「好事成雙」賽馬場"<<endl;
  9.     cout<<"--------------------------------------------------------------------|終點"<<endl;
  10.     cout<<"◆"<<endl;
  11.     cout<<"★"<<endl;
  12.     cout<<"▲"<<endl;
  13.     cout<<"●"<<endl;
  14.     system("pause");
  15.     system("cls")
  16.     system("pause");
  17.     return 0;
  18. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     int h[4]={0,0,0,0};
  8.     srand (time(NULL));
  9.     cout<<"「好事成雙」賽馬場"<<endl;
  10.     cout<<"-----------------------------------------------------------------------|終點"<<endl;
  11.     cout<<"◆"<<endl;
  12.     cout<<"★"<<endl;
  13.     cout<<"▲"<<endl;
  14.     cout<<"●"<<endl;  
  15.        system("pause");
  16.        system("cls");
  17.     while(true)
  18.     {
  19.         int r=rand()%4;
  20.         h[r]++;
  21.         cout<<"比賽進行中"<<endl;
  22.         cout<<"-----------------------------------------------------------------------|終點"<<endl;
  23.         for(int k=1; k<=h[0]; k++)
  24.             cout<<" ";
  25.         cout<<"◆"<<endl;
  26.         for(int k=1; k<=h[1]; k++)
  27.             cout<<" ";
  28.         cout<<"★"<<endl;
  29.         for(int k=1; k<=h[2]; k++)
  30.             cout<<" ";
  31.         cout<<"▲"<<endl;
  32.         for(int k=1; k<=h[3]; k++)
  33.             cout<<" ";
  34.         cout<<"●"<<endl;
  35.         if(h[r]==71)
  36.             break;
  37.         _sleep(10);
  38.         system("cls");
  39.     }
  40.     system("pause");
  41.     return 0;
  42. }
複製代碼

TOP

回復 7# 林孟蓁

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int h[4]={0,0,0,0};
  7.     srand(time(NULL));
  8.     cout<<"賽馬場"<<endl;
  9.     cout<<"-------------------------------------------------------------------------|終點"<<endl;
  10.     cout<<"◆"<<endl;
  11.     cout<<"★"<<endl;
  12.     cout<<"▲"<<endl;
  13.     cout<<"●"<<endl;
  14.     system("pause");
  15.     while(true)
  16.     {
  17.         cout<<"比賽進行中"<<endl;
  18.         cout<<"-------------------------------------------------------------------------|終點"<<endl;
  19.         int r=rand()%4;
  20.         h[r]++;
  21.         for(int i=1;i<=h[0];i++)
  22.         {
  23.             cout<<" ";
  24.         }
  25.         cout<<"◆"<<endl;
  26.         for(int i=1;i<=h[1];i++)
  27.         {
  28.             cout<<" ";
  29.         }
  30.         cout<<"★"<<endl;
  31.         for(int i=1;i<=h[2];i++)
  32.         {
  33.             cout<<" ";
  34.         }
  35.         cout<<"▲"<<endl;
  36.         for(int i=1;i<=h[3];i++)
  37.         {
  38.             cout<<" ";
  39.         }
  40.         cout<<"●"<<endl;
  41.         if(h[r]==72)
  42.         {
  43.             break;
  44.         }
  45.         system("cls");
  46.     }
  47.     system("pause");
  48.     return 0;
  49. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     int h[4]={0,0,0,0};
  8.     srand (time(NULL));
  9.     cout<<"「好事成雙」賽馬場"<<endl;
  10.     cout<<"-----------------------------------------------------------------------|終點"<<endl;
  11.     cout<<"◆"<<endl;
  12.     cout<<"★"<<endl;
  13.     cout<<"▲"<<endl;
  14.     cout<<"●"<<endl;  
  15.        system("pause");
  16.        system("cls");
  17.     while(true)
  18.     {
  19.         int r=rand()%4;
  20.         h[r]++;
  21.         cout<<"比賽進行中"<<endl;
  22.         cout<<"-----------------------------------------------------------------------|終點"<<endl;
  23.         for(int k=1; k<=h[0]; k++)
  24.             cout<<" ";
  25.         cout<<"◆"<<endl;
  26.         for(int k=1; k<=h[1]; k++)
  27.             cout<<" ";
  28.         cout<<"★"<<endl;
  29.         for(int k=1; k<=h[2]; k++)
  30.             cout<<" ";
  31.         cout<<"▲"<<endl;
  32.         for(int k=1; k<=h[3]; k++)
  33.             cout<<" ";
  34.         cout<<"●"<<endl;
  35.         if(h[r]==71)
  36.             break;
  37.         _sleep(10);
  38.         system("cls");
  39.     }
  40.     system("pause");
  41.     return 0;
  42. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int h[4]={0,0,0,0};
  7.     srand(time(NULL));
  8.     cout<<"賽馬場"<<endl;
  9.     cout<<"------------------------------------------------------------------------|終點"<<endl;
  10.     cout<<"◆"<<endl<<"★"<<endl<<"▲"<<endl<<"●"<<endl;                       //72
  11.     system("pause");
  12.     system("cls");
  13.     while(true)
  14.     {
  15.         cout<<"比賽進行中"<<endl;           
  16.         cout<<"------------------------------------------------------------------------|終點"<<endl;
  17.    
  18.     int r=rand()%4;
  19.     h[r]++;
  20.     for(int i=1;i<=h[0];i++)
  21.         {
  22.             cout<<" ";
  23.         }
  24.         cout<<"◆"<<endl;
  25.     for(int i=1;i<=h[1];i++)
  26.         {
  27.             cout<<" ";
  28.         }
  29.         cout<<"★"<<endl;
  30.     for(int i=1;i<=h[2];i++)
  31.         {
  32.             cout<<" ";
  33.         }
  34.         cout<<"▲"<<endl;
  35.     for(int i=1;i<=h[3];i++)
  36.         {
  37.             cout<<" ";
  38.         }
  39.         cout<<"●"<<endl;
  40.         if(h[r]==72)
  41.             break;
  42.         system("cls");   
  43.     }
  44.     system("pause");
  45.     return 0;
  46. }
  47.    
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int h[4]={0,0,0,0};
  7.     srand(time(NULL));
  8.     cout<<"賽馬場"<<endl;
  9.     cout<<"-------------------------------------------------------------------------|終點"<<endl;
  10.     cout<<"◆"<<endl;
  11.     cout<<"★"<<endl;
  12.     cout<<"▲"<<endl;
  13.     cout<<"●"<<endl;
  14.     system("pause");
  15.     while(true)
  16.     {
  17.         cout<<"比賽進行中"<<endl;
  18.         cout<<"-------------------------------------------------------------------------|終點"<<endl;
  19.         int r=rand()%4;
  20.         h[r]++;
  21.         for(int i=1;i<=h[0];i++)
  22.         {
  23.             cout<<" ";
  24.         }
  25.         cout<<"◆"<<endl;
  26.         for(int i=1;i<=h[1];i++)
  27.         {
  28.             cout<<" ";
  29.         }
  30.         cout<<"★"<<endl;
  31.         for(int i=1;i<=h[2];i++)
  32.         {
  33.             cout<<" ";
  34.         }
  35.         cout<<"▲"<<endl;
  36.         for(int i=1;i<=h[3];i++)
  37.         {
  38.             cout<<" ";
  39.         }
  40.         cout<<"●"<<endl;
  41.         if(h[r]==72)
  42.         {
  43.             break;
  44.         }
  45.         system("cls");
  46.     }
  47.     system("pause");
  48.     return 0;
  49. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {  
  7.     int h[4]={0,0,0,0};
  8.     srand(time(NULL));
  9.     cout<<"[好事雙城]賽馬場"<<endl;
  10.     cout<<"-------------------------------------------------------------------------| 終點"<<endl;
  11.     cout<<"◆"<<endl;
  12.     cout<<"★"<<endl;
  13.     cout<<"▲"<<endl;
  14.     cout<<"●"<<endl;
  15.     system("pause");
  16.     while(true)
  17.     {
  18.         cout<<"比賽進行中......"<<endl;
  19.         int r=rand()%4;
  20.         h[r]++;
  21.         cout<<"-------------------------------------------------------------------------| 終點"<<endl;
  22.         for(int i=1;i<=h[0];i++)
  23.             cout<<" ";
  24.         cout<<"◆"<<endl;
  25.         for(int i=1;i<=h[1];i++)
  26.             cout<<" ";
  27.         cout<<"★"<<endl;
  28.         for(int i=1;i<=h[2];i++)
  29.             cout<<" ";
  30.         cout<<"▲"<<endl;
  31.         for(int i=1;i<=h[3];i++)
  32.             cout<<" ";
  33.         cout<<"●"<<endl;           
  34.         if(h[r]==72)
  35.         {
  36.             break;     
  37.         }
  38.             _sleep(20);
  39.             system("cls");
  40.     }
  41.     system("pause");
  42.     return 0;
  43. }
複製代碼
Jian-wei Wang

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     srand(time(NULL));
  7.     int d[]={0,0,0,0},speed=30;
  8.     cout<<"「好事成雙」賽馬場"<<endl;
  9.     cout<<"-----------------------------------------------------------------| 終點"<<endl;
  10.     cout<<"●"<<endl;
  11.     cout<<"▲"<<endl;
  12.     cout<<"★"<<endl;
  13.     cout<<"◆"<<endl;
  14.     system("pause");
  15.     while(true)
  16.     {
  17.         system("cls");
  18.         cout<<"比賽進行中"<<endl;
  19.         cout<<"-----------------------------------------------------------------| 終點"<<endl;
  20.         int g=rand()%4;
  21.         d[g]++;
  22.         for(int a=0;a<=d[0];a++)
  23.             cout<<" ";
  24.         cout<<"●"<<endl;
  25.         for(int b=0;b<=d[1];b++)
  26.             cout<<" ";
  27.         cout<<"▲"<<endl;
  28.         for(int c=0;c<=d[2];c++)
  29.             cout<<" ";
  30.         cout<<"★"<<endl;
  31.         for(int e=0;e<=d[3];e++)
  32.             cout<<" ";
  33.         cout<<"◆"<<endl;
  34.         if(d[0]>=64||d[1]>=64||d[2]>=64||d[3]>=64)
  35.             break;
  36.         _sleep(speed);
  37.     }
  38.     system("pause");
  39.     return 0;
  40. }
複製代碼

TOP

返回列表