返回列表 發帖

跑馬燈 (一) - _sleep() 函式

本帖最後由 鄭繼威 於 2022-12-28 20:52 編輯

設計一動畫, 由
□□□□□□□□□□
開始慢慢改變為
■□□□□□□□□□
接著
■■□□□□□□□□
...
□□□□□■■■□□
呈現黑色方格不斷向右流動的感覺,並運用 _sleep() 函式控制其流動速度。
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.    int speed=50;
  7.    re:
  8.    for(int i=1; i<=13; i++)
  9.    {
  10.        if(i==1)
  11.            cout<<"□□□□□□□□□□"<<endl;
  12.        if(i==2)
  13.            cout<<"■□□□□□□□□□"<<endl;
  14.        if(i==3)
  15.            cout<<"■■□□□□□□□□"<<endl;
  16.        if(i==4)
  17.            cout<<"■■■□□□□□□□"<<endl;
  18.        if(i==5)
  19.            cout<<"□■■■□□□□□□"<<endl;
  20.        if(i==6)
  21.            cout<<"□□■■■□□□□□"<<endl;
  22.        if(i==7)
  23.            cout<<"□□□■■■□□□□"<<endl;
  24.        if(i==8)
  25.            cout<<"□□□□■■■□□□"<<endl;
  26.        if(i==9)
  27.            cout<<"□□□□□■■■□□"<<endl;
  28.        if(i==10)
  29.            cout<<"□□□□□□■■■□"<<endl;
  30.        if(i==11)
  31.            cout<<"□□□□□□□■■■"<<endl;
  32.        if(i==12)
  33.            cout<<"□□□□□□□□■■"<<endl;
  34.        if(i==13)
  35.            cout<<"□□□□□□□□□■"<<endl;
  36.        _sleep(speed);
  37.        system("cls");
  38.    }
  39.    goto re;
  40.    system("pause");   
  41.    return 0;
  42. }
複製代碼

  1. #include<iostream>
  2. #include<cstdlib>
  3. //#include<windows.h>
  4. using namespace std;
  5. int main()
  6. {
  7.    int speed=50;
  8.    re:
  9.    for(int i=1; i<=13; i++)
  10.    {
  11.        if(i==1)
  12.            cout<<"□□□□□□□□□□"<<endl;
  13.        if(i==2)
  14.            cout<<"■□□□□□□□□□"<<endl;
  15.        if(i==3)
  16.            cout<<"■■□□□□□□□□"<<endl;
  17.        if(i==4)
  18.            cout<<"■■■□□□□□□□"<<endl;
  19.        if(i==5)
  20.            cout<<"□■■■□□□□□□"<<endl;
  21.        if(i==6)
  22.            cout<<"□□■■■□□□□□"<<endl;
  23.        if(i==7)
  24.            cout<<"□□□■■■□□□□"<<endl;
  25.        if(i==8)
  26.            cout<<"□□□□■■■□□□"<<endl;
  27.        if(i==9)
  28.            cout<<"□□□□□■■■□□"<<endl;
  29.        if(i==10)
  30.            cout<<"□□□□□□■■■□"<<endl;
  31.        if(i==11)
  32.            cout<<"□□□□□□□■■■"<<endl;
  33.        if(i==12)
  34.            cout<<"□□□□□□□□■■"<<endl;
  35.        if(i==13)
  36.            cout<<"□□□□□□□□□■"<<endl;
  37.        _sleep(speed);
  38.        system("cls");
  39.    }
  40.    goto re;
  41.    system("pause");   
  42.    return 0;
  43. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. //#include<windows.h>
  4. using namespace std;
  5. int main()
  6. {
  7.    int speed=50;
  8.    re:
  9.    for(int i=1; i<=13; i++)
  10.    {
  11.        if(i==1)
  12.            cout<<"□□□□□□□□□□"<<endl;
  13.        if(i==2)
  14.            cout<<"■□□□□□□□□□"<<endl;
  15.        if(i==3)
  16.            cout<<"■■□□□□□□□□"<<endl;
  17.        if(i==4)
  18.            cout<<"■■■□□□□□□□"<<endl;
  19.        if(i==5)
  20.            cout<<"□■■■□□□□□□"<<endl;
  21.        if(i==6)
  22.            cout<<"□□■■■□□□□□"<<endl;
  23.        if(i==7)
  24.            cout<<"□□□■■■□□□□"<<endl;
  25.        if(i==8)
  26.            cout<<"□□□□■■■□□□"<<endl;
  27.        if(i==9)
  28.            cout<<"□□□□□■■■□□"<<endl;
  29.        if(i==10)
  30.            cout<<"□□□□□□■■■□"<<endl;
  31.        if(i==11)
  32.            cout<<"□□□□□□□■■■"<<endl;
  33.        if(i==12)
  34.            cout<<"□□□□□□□□■■"<<endl;
  35.        if(i==13)
  36.            cout<<"□□□□□□□□□■"<<endl;
  37.        _sleep(speed);
  38.        system("cls");
  39.    }
  40.    goto re;
  41.    system("pause");   
  42.    return 0;
  43. }
複製代碼

TOP

#include<iostream>
#include<cstdlib>
//#include<windows.h>
using namespace std;
int main()
{
   int speed=50;
   re:
   for(int i=1; i<=13; i++)
   {
       if(i==1)
           cout<<"□□□□□□□□□□"<<endl;
       if(i==2)
           cout<<"■□□□□□□□□□"<<endl;
       if(i==3)
           cout<<"■■□□□□□□□□"<<endl;
       if(i==4)
           cout<<"■■■□□□□□□□"<<endl;
       if(i==5)
           cout<<"□■■■□□□□□□"<<endl;
       if(i==6)
           cout<<"□□■■■□□□□□"<<endl;
       if(i==7)
           cout<<"□□□■■■□□□□"<<endl;
       if(i==8)
           cout<<"□□□□■■■□□□"<<endl;
       if(i==9)
           cout<<"□□□□□■■■□□"<<endl;
       if(i==10)
           cout<<"□□□□□□■■■□"<<endl;
       if(i==11)
           cout<<"□□□□□□□■■■"<<endl;
       if(i==12)
           cout<<"□□□□□□□□■■"<<endl;
       if(i==13)
           cout<<"□□□□□□□□□■"<<endl;
       _sleep(speed);
       system("cls");
   }
   goto re;
   system("pause");   
   return 0;
}

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. //#include<windows.h>
  4. using namespace std;
  5. int main()
  6. {
  7.    int speed=50;
  8.    re:
  9.    for(int i=1; i<=13; i++)
  10.    {
  11.        if(i==1)
  12.            cout<<"□□□□□□□□□□"<<endl;
  13.        if(i==2)
  14.            cout<<"■□□□□□□□□□"<<endl;
  15.        if(i==3)
  16.            cout<<"■■□□□□□□□□"<<endl;
  17.        if(i==4)
  18.            cout<<"■■■□□□□□□□"<<endl;
  19.        if(i==5)
  20.            cout<<"□■■■□□□□□□"<<endl;
  21.        if(i==6)
  22.            cout<<"□□■■■□□□□□"<<endl;
  23.        if(i==7)
  24.            cout<<"□□□■■■□□□□"<<endl;
  25.        if(i==8)
  26.            cout<<"□□□□■■■□□□"<<endl;
  27.        if(i==9)
  28.            cout<<"□□□□□■■■□□"<<endl;
  29.        if(i==10)
  30.            cout<<"□□□□□□■■■□"<<endl;
  31.        if(i==11)
  32.            cout<<"□□□□□□□■■■"<<endl;
  33.        if(i==12)
  34.            cout<<"□□□□□□□□■■"<<endl;
  35.        if(i==13)
  36.            cout<<"□□□□□□□□□■"<<endl;
  37.        _sleep(speed);
  38.        system("cls");
  39.    }
  40.    goto re;
  41.    system("pause");   
  42.    return 0;
  43. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<windows.h>
  4. using namespace std;
  5. int main()
  6. {
  7.    int speed=50;
  8.    re:
  9.    for(int i=1; i<=13; i++)
  10.    {
  11.        if(i==1)
  12.            cout<<"□□□□□□□□□□"<<endl;
  13.        if(i==2)
  14.            cout<<"■□□□□□□□□□"<<endl;
  15.        if(i==3)
  16.            cout<<"■■□□□□□□□□"<<endl;
  17.        if(i==4)
  18.            cout<<"■■■□□□□□□□"<<endl;
  19.        if(i==5)
  20.            cout<<"□■■■□□□□□□"<<endl;
  21.        if(i==6)
  22.            cout<<"□□■■■□□□□□"<<endl;
  23.        if(i==7)
  24.            cout<<"□□□■■■□□□□"<<endl;
  25.        if(i==8)
  26.            cout<<"□□□□■■■□□□"<<endl;
  27.        if(i==9)
  28.            cout<<"□□□□□■■■□□"<<endl;
  29.        if(i==10)
  30.            cout<<"□□□□□□■■■□"<<endl;
  31.        if(i==11)
  32.            cout<<"□□□□□□□■■■"<<endl;
  33.        if(i==12)
  34.            cout<<"□□□□□□□□■■"<<endl;
  35.        if(i==13)
  36.            cout<<"□□□□□□□□□■"<<endl;
  37.        _sleep(speed);
  38.        system("cls");
  39.    }
  40.    goto re;
  41.    system("pause");   
  42.    return 0;
  43. }
複製代碼

TOP

返回列表