本帖最後由 李泳霖 於 2023-12-23 13:36 編輯
使畫面動起來...參考
- #include<iostream>
- #include<cstdlib>
- #include<ctime>
- using namespace std;
- int main()
- {
- re:
- system("cls");
- srand(time(NULL));
- int s[]={0,0,0,0};
- string p[]={"◆","★","▲","●"};
- int r=0;
- cout<<"「好事成雙」賽馬場"<<endl;
- cout<<"-------------------------------------------------------------------------| 終點"<<endl;
- for(int i=0; i<4; i++)
- cout<<p[i]<<endl;
- system("pause");
- system("cls");
- while(s[r]<=73)
- {
- r=rand()%4; //0~3
- s[r]++;
- cout<<"比賽進行中"<<endl;
- cout<<"-------------------------------------------------------------------------| 終點"<<endl;
- for(int i=0; i<4; i++)
- {
- for(int j=0; j<s[i]; j++)
- cout<<" ";
- cout<<p[i]<<endl;
- }
- _sleep(50);
- system("cls");
- }
- cout<<"比賽結束"<<endl;
- cout<<"-------------------------------------------------------------------------| 終點"<<endl;
- for(int i=0; i<4; i++)
- {
- for(int j=0; j<s[i]; j++)
- cout<<" ";
- cout<<p[i]<<endl;
- }
- system("pause");
- goto re;
- return 0;
- }
複製代碼 |