返回列表 發帖

賽馬程式 (二)

本帖最後由 tonyh 於 2016-10-15 11:54 編輯

使畫面動起來



  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     srand(time(NULL));
  7.     re:
  8.     system("cls");
  9.     string n[]={"◆","★","▲","●"};
  10.     int s[]={0,0,0,0};
  11.     int r;
  12.     cout<<"「好事成雙」賽馬場"<<endl;
  13.     cout<<"-------------------------------------------------------------------------| 終點"<<endl;
  14.     for(int i=0; i<4; i++)
  15.         cout<<n[i]<<endl;
  16.     system("pause");
  17.     while(true)
  18.     {
  19.         cout<<"比賽進行中"<<endl;
  20.         cout<<"-------------------------------------------------------------------------| 終點"<<endl;
  21.         r=rand()%4;   //0~3
  22.         s[r]++;
  23.         for(int i=0; i<4; i++)
  24.         {
  25.             for(int j=0; j<s[i]; j++)
  26.                 cout<<" ";
  27.             cout<<n[i]<<endl;     
  28.         }
  29.         _sleep(10);
  30.         system("cls");
  31.         if(s[r]==76)
  32.             break;
  33.     }
  34.     cout<<"比賽結果"<<endl;
  35.     cout<<"-------------------------------------------------------------------------| 終點"<<endl;
  36.     for(int i=0; i<4; i++)
  37.     {
  38.         for(int j=0; j<s[i]; j++)
  39.             cout<<" ";
  40.         cout<<n[i]<<endl;     
  41.     }
  42.     system("pause");
  43.     goto re;
  44.     return 0;
  45. }
複製代碼
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     srand(time(NULL));
  7.     re:
  8.     system("cls");
  9.     int a=0,b=0,c=0,d=0;
  10.     cout<<"「好事成雙」賽馬場"<<endl;
  11.     cout<<"-------------------------------------------------------------------------| 終點"<<endl;
  12.     cout<<"◆"<<endl;
  13.     cout<<"★"<<endl;
  14.     cout<<"▲"<<endl;
  15.     cout<<"●"<<endl;
  16.     system("pause");
  17.     system("cls");
  18.     while(a!=76 && b!=76 && c!=76 && d!=76)
  19.     {
  20.         int r=rand()%4;   //0~3
  21.         if(r==0)
  22.             a++;
  23.         else if(r==1)
  24.             b++;
  25.         else if(r==2)
  26.             c++;
  27.         else
  28.             d++;
  29.         cout<<"比賽進行中"<<endl;
  30.         cout<<"-------------------------------------------------------------------------| 終點"<<endl;
  31.         for(int i=0; i<a; i++)
  32.             cout<<" ";
  33.         cout<<"◆"<<endl;   
  34.         for(int i=0; i<b; i++)
  35.             cout<<" ";
  36.         cout<<"★"<<endl;
  37.         for(int i=0; i<c; i++)
  38.             cout<<" ";
  39.         cout<<"▲"<<endl;
  40.         for(int i=0; i<d; i++)
  41.             cout<<" ";
  42.         cout<<"●"<<endl;     
  43.         _sleep(10);
  44.         system("cls");
  45.     }
  46.     cout<<"比賽結束"<<endl;
  47.     cout<<"-------------------------------------------------------------------------| 終點"<<endl;
  48.     for(int i=0; i<a; i++)
  49.         cout<<" ";
  50.     cout<<"◆"<<endl;   
  51.     for(int i=0; i<b; i++)
  52.         cout<<" ";
  53.     cout<<"★"<<endl;
  54.     for(int i=0; i<c; i++)
  55.         cout<<" ";
  56.     cout<<"▲"<<endl;
  57.     for(int i=0; i<d; i++)
  58.         cout<<" ";
  59.     cout<<"●"<<endl;
  60.     system("pause");
  61.     goto re;
  62.     return 0;
  63. }
複製代碼

返回列表