標題:
賽馬程式 (二)
[打印本頁]
作者:
陳曜誌
時間:
2025-4-21 17:09
標題:
賽馬程式 (二)
本帖最後由 陳曜誌 於 2025-4-25 17:49 編輯
使畫面動起來
本帖隱藏的內容需要回復才可以瀏覽
作者:
陳曜誌
時間:
2025-4-25 17:10
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
複製代碼
作者:
楊炘樺
時間:
2025-4-25 17:56
本帖最後由 楊炘樺 於 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;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2