本帖最後由 楊炘樺 於 2025-4-25 18:24 編輯
- #include<bits/stdc++.h>
- using namespace std;
- string Players[4]={"◆","★","▲","●"};
- int Location[4]={0,0,0,0};
- void show()
- {
- for(int i=0;i<37;i++)
- cout<<"══";
- cout<<"| 終點"<<endl;
- for(int i=0;i<4;i++)
- {
- for(int j=0;j<Location[i];j++)
- cout<<" ";
- cout<<Players[i]<<endl;
- }
- }
- int main()
- {
- while(true)
- {
- srand(time(NULL));
- for(int i=0;i<4;i++)
- Location[i]=0;
- for(int i=0;i<27;i++)
- cout<<' ';
- cout<<"「好事成雙」賽馬場\n";
- show();
- cout<<"\n\n\n";
- system("pause");
- system("cls");
- while(true)
- {
- for(int i=0;i<32;i++)
- cout<<' ';
- cout<<"比賽進行中\n";
- Location[rand()%4]++;
- show();
- _sleep(300);
- system("cls");
- if(Location[0]==37 || Location[1]==37)
- break;
- if(Location[2]==37 || Location[3]==37)
- break;
- }
- for(int i=0;i<30;i++)
- cout<<' ';
- cout<<"比賽結束\n";
- show();
- cout<<"\n\n\n";
- system("pause");
- system("cls");
- }
- return 0;
- }
複製代碼 六位參賽者:- #include<bits/stdc++.h>
- using namespace std;
- string Players[6]={"◆","★","▲","●","▼","■"};
- int Location[6]={0,0,0,0,0,0};
- void show()
- {
- for(int i=0;i<37;i++)
- cout<<"══";
- cout<<"| 終點"<<endl;
- for(int i=0;i<6;i++)
- {
- for(int j=0;j<Location[i];j++)
- cout<<" ";
- cout<<Players[i]<<endl;
- }
- }
- int main()
- {
- while(true)
- {
- srand(time(NULL));
- for(int i=0;i<6;i++)
- Location[i]=0;
- for(int i=0;i<27;i++)
- cout<<' ';
- cout<<"「好事成雙」賽馬場\n";
- show();
- cout<<"\n\n\n";
- system("pause");
- system("cls");
- while(true)
- {
- for(int i=0;i<32;i++)
- cout<<' ';
- cout<<"比賽進行中\n";
- Location[rand()%6]++;
- show();
- _sleep(300);
- system("cls");
- if(Location[0]==37 || Location[1]==37 || Location[2]==37)
- break;
- if(Location[3]==37 || Location[4]==37 || Location[5]==37)
- break;
- }
- for(int i=0;i<30;i++)
- cout<<' ';
- cout<<"比賽結束\n";
- show();
- cout<<"\n\n\n";
- system("pause");
- system("cls");
- }
- return 0;
- }
複製代碼 |