標題:
賽馬程式 (三)
[打印本頁]
作者:
鄭繼威
時間:
2023-6-30 21:04
標題:
賽馬程式 (三)
本帖最後由 鄭繼威 於 2023-7-7 20:54 編輯
1. 在比賽首頁顯示第幾局
2. 在比賽結束頁顯示哪一位選手勝出
法1:看哪隻馬跑到終點(s
==73),就代表他贏
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int round=1;
re:
system("cls");
int s[]={0,0,0,0}; //存放進度用的
string n[]={"◆","★","▲","●"}; //存放馬用的
srand(time(NULL));
cout<<"「好事成雙」賽馬場 round:"<<round<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
//把馬印出來
for(int i=0;i<=3;i++)
{
cout<<n[i]<<endl;
}
system("pause");
//開始賽馬
while(true)
{
system("cls"); //清空畫面
int r=rand()%4; //0~3 (抽馬)
s[r]++; //看電腦抽到哪隻馬就+1
cout<<"比賽進行中"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int j=0;j<=3;j++)
{
for(int i=0; i<=s[j]; i++)
{
cout<<" ";
}
cout<<n[j]<<endl;
}
//
//抵達終點
if(s[r]==73)
break;
_sleep(0.05);
}
system("cls");
for(int i=0;i<=3;i++)
{
if(s[i]==73)
{
cout<<"比賽結束! 由 "<<n[i]<<" 先馳得點!"<<endl;
}
}
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
//印空格(看進度是多少就印多少空格)
//把馬印出來
for(int j=0;j<=3;j++)
{
for(int i=0; i<=s[j]; i++)
{
cout<<" ";
}
cout<<n[j]<<endl;
}
system("pause");
round++;
goto re;
return 0;
}
複製代碼
法2:取最大數(max)並將馬紀錄下來(win=i;),就代表他贏
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int round=1; //局數
re:
system("cls");
srand(time(NULL));
int s[]={0,0,0,0}; //存放進度用的
string p[]={"◆","★","▲","●"}; //存放馬用的
int r=0;
cout<<"「好事成雙」賽馬場 第"<<round<<"局"<<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]++; //看電腦抽到哪隻馬就+1
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");
}
//取最大數
int max=0,win;
for(int i=0;i<=3;i++)
{
if(max<s[i])
{
max=s[i];
win=i;
}
}
cout<<"比賽結束! 由 "<<n[win]<<" 先馳得點!"<<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");
round++; //局數+1
goto re;
return 0;
}
複製代碼
作者:
呂宗晉
時間:
2023-7-7 17:20
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int round=1; //局數
re:
system("cls");
srand(time(NULL));
int s[]={0,0,0,0}; //存放進度用的
string p[]={"◆","★","▲","●"}; //存放馬用的
int r=0;
cout<<"「好事成雙」賽馬場 第"<<round<<"局"<<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]++; //看電腦抽到哪隻馬就+1
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<<"比賽結束! 由 "<<p[r]<<" 先馳得點!"<<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");
round++; //局數+1
goto re;
return 0;
}
複製代碼
作者:
蔡沛倢
時間:
2023-7-7 19:53
本帖最後由 蔡沛倢 於 2023-7-7 20:40 編輯
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int d=1;
re:
system("cls");
int a[]={0,0,0,0};
string e[]={"◆","★","▲","●"};
srand(time(NULL));
int b=0;
cout<<"****賽馬場-第"<<d<<"場****"<<endl;
cout<<"-------------------------------------------------------------------------|終點線"<<endl;
for(int i=0;i<=3;i++)
{
cout<<e[i]<<endl;
}
system("pause");
system("cls");
while(true)
{
b=rand()%4;
a[b]++;
cout<<"比賽進行中"<<endl;
cout<<"-------------------------------------------------------------------------|終點線"<<endl;
for(int i=0;i<4;i++)
{
for(int j=0;j<=a[i];j++)
{
cout<<" ";
}
cout<<e[i]<<endl;
}
if(a[b]==73)
{
break;
}
_sleep(50);
system("cls");
}
cout<<"!比賽結束 由"<<e[b]<<"勝利!"<<endl;
cout<<"-------------------------------------------------------------------------|終點線"<<endl;
for(int i=0;i<4;i++)
{
for(int j=0;j<=a[i];j++)
{
cout<<" ";
}
cout<<e[i]<<endl;
}
system("pause");
d++;
goto re;
return 0;
}
複製代碼
作者:
何權晉
時間:
2023-7-7 20:21
本帖最後由 何權晉 於 2023-7-7 21:04 編輯
#include<iostream>
#include<ctime>
using namespace std;
int main()
{
int r=1;
re:
int s[]={0,0,0,0};
string h[]={"◆","★","▲","●"};
srand(time(NULL));
cout<<"Round "<<r<<endl;
cout<<"★★★The Wetherby Racecourse★★★"<<endl;
cout<<"-------------------------------------------------------------------------|Finish"<<endl;
for(int i=0;i<=3;i++)
cout<<h[i]<<endl;
system("pause");
while(true)
{
system("cls");
int o=rand()%4;
s[o]++;
cout<<"Round "<<r<<endl;
cout<<"★★★The Wetherby Racecourse★★★"<<endl;
cout<<"-------------------------------------------------------------------------|Finish"<<endl;
for(int i=0; i<4; i++)
{
for(int j=0; j<s[i]; j++)
{
cout<<" ";
}
cout<<h[i]<<endl;
}
if (s[o]==73)
break;
_sleep(50);
}
system("cls");
cout<<"Race Finished"<<endl;
cout<<"Round "<<r<<endl;
cout<<"★★★The Wetherby Racecourse★★★"<<endl;
cout<<"-------------------------------------------------------------------------|Finish"<<endl;
for(int i=0; i<4; i++)
{
for(int j=0; j<s[i]; j++)
{
cout<<" ";
}
cout<<h[i]<<endl;
}
for(int i=0;i<=3;i++)
{
if(s[i]==73)
{
cout<<h[i]<<" Won The Race"<<endl;
}
}
r++;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
呂宗晉
時間:
2023-7-7 20:29
#include<iostream>哥哥
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int round=1;
re:
system("cls");
srand(time(NULL));
int s[]={0,0,0,0};
string p[]={"◆","★","▲","●"};
int r=0;
cout<<"「好事成雙」賽馬場 第"<<round<<"局"<<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;
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<<"比賽結束! 由 "<<p[r]<<" 先馳得點!"<<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");
round++;
goto re;
return 0;
}
複製代碼
作者:
黃子豪
時間:
2023-7-7 21:04
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int round=1;
re:
system("cls");
int s[]={0,0,0,0};
string p[]={"◆", "★", "▲", "●"};
int win;
srand(time(NULL));
cout<<"「好事成雙」賽馬場 第"<<round<<"局"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<4; i++)
{
cout<<p[i]<<endl;
}
system("pause");
while(true)
{
system("cls");
int r=rand()%4;
s[r]++;
cout<<"比賽進行中"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int j=0; j<4; j++){
for(int i=0; i<=s[j]; i++){
cout<<" ";
}
cout<<p[j]<<endl;
}
if(s[r]==73){
win=r;
break;
}
_sleep(5);
}
cout<<"比賽結束! 由 "<<p[win]<<" 先馳得點!"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int j=0; j<4; j++){
for(int i=0; i<=s[j]; i++){
cout<<" ";
}
cout<<p[j]<<endl;
}
system("pause");
round++;
goto re;
return 0;
}
複製代碼
作者:
盧玄皓
時間:
2023-7-7 21:05
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
re:
system("cls");
int s[]={0,0,0,0};
string p[]={"○","€","§","◎"};
srand(time(NULL));
cout<<"賽馬場"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<4; i++)
{
cout<<p[i]<<endl;
}
system("pause");
while(true)
{
system("cls");
int r=rand()%4;
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;
}
if(s[r]==73)
break;
_sleep(1);
}
system("cls");
for(int i=0;i<=3;i++)
{
if(s[i]==73)
{
cout<<"比賽結束! 由 "<<p[i]<<" 先得點!"<<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;
}
複製代碼
作者:
廖秝瑜
時間:
2023-7-10 09:53
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int a=1;
re:
system("cls");
srand(time(NULL));
int s[]={0,0,0,0};
string p[]={"◆","★","▲","●"};
int r=0;
cout<<"賽馬場 第"<<a<<"局"<<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;
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");
}
int max=0,win;
for(int i=0;i<=3;i++)
{
if(max<s[i])
{
max=s[i];
win=i;
}
}
cout<<"比賽結束!"<<endl;
cout<<"由"<<n[win]<<" 先抵達終點!"<<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");
a++;
goto re;
return 0;
}
複製代碼
作者:
黃品禎
時間:
2023-7-15 16:31
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int round=1;
while(true)
{
system("cls");
int s[]={0,0,0,0};
string p[]={"◆","★","▲","●"};
srand(time(NULL));
cout<<"「好事成雙」賽馬場 第"<<round<<"局"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0;i<=3;i++)
{
cout<<p[i]<<endl;
}
while(true)
{
system("cls");
int r=rand()%4;
s[r]++;
cout<<"比賽進行中"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int j=0; j<=3; j++)
{
for(int i=0; i<=s[j]; i++)
cout<<" ";
cout<<p[j]<<endl;
}
if(s[r]==72)
break;
_sleep(0.005);
}
string win;
for(int i=0; i<=3; i++)
{
if(s[i]==73)
{
win=p[i];
}
}
cout<<"比賽結束"<<win<<"贏"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int j=0; j<=3; j++)
{
for(int i=0; i<=s[j]; i++)
cout<<" ";
cout<<p[j]<<endl;
system("pause");
round++;
}
}
system("pause");
return 0;
}
複製代碼
作者:
張絜晰
時間:
2023-8-3 20:39
本帖最後由 張絜晰 於 2023-8-3 20:53 編輯
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int counter=0;
re:
counter++;
int s[]={0,0,0,0};
string h[]={"◆","★","▲","●"};
srand(time(NULL));
system("cls");
cout<<"Racehorse thing: Round "<<counter<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0;i<=3;i++){
cout<<h[i]<<endl;}
system("pause");
while(1)
{
system("cls");
int r=rand()%4;
s[r]++;
cout<<"Race in progress..."<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0;i<=3;i++){
for(int j=0; j<=s[i];j++){
cout<<" ";
}
cout<<h[i]<<endl;
}
if(s[r]==73)
break;
_sleep(10);
}
system("cls");
string win;
for (int i=0;i<=3; i++){
if (s[i]==73){
win=h[i];}}
cout<<"Race ended! The winner was:"<<win<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0;i<=3;i++){
for(int j=0; j<=s[i];j++){
cout<<" ";
}
cout<<h[i]<<endl;
}
system("pause");
goto re;
return 0;
}
複製代碼
作者:
吳柏潁
時間:
2023-8-10 17:28
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int round=1;
system("cls");
string h[]={"◆","★","▲","●"};
srand(time(NULL));
re:
int s[]={0,0,0,0};
system("cls");
cout<<"「好事成雙」賽馬場,第"<<round<<"局"<<endl;
cout<<"------------------------------------------------------------------------------------------------------------------| 終點"<<endl;
for(int i=0;i<=3;i++)
{
cout<<h[i]<<endl;
}
cout<<"按enter開始 1.一般 2.快速"<<endl;
int option;
cin>>option;
system("pause");
while(true)
{
system("cls");
int r=rand()%4;
cout<<"比賽進行中"<<endl;
cout<<"------------------------------------------------------------------------------------------------------------------| 終點"<<endl;
if(option==1)
{
s[r]++;
for(int j=0; j<=3; j++)
{
for(int i=0; i<=s[j]; i++)
cout<<" ";
cout<<h[j]<<endl;
}
if(s[r]==112)
break;
_sleep(50);
}
else if(option==2)
{
s[r]+=8;
for(int j=0; j<=3; j++)
{
for(int i=0; i<=s[j]; i++)
cout<<" ";
cout<<h[j]<<endl;
}
if(s[r]>=112)
break;
_sleep(100);
}
}
system("cls");
cout<<"比賽結束,";
for(int i=0;i<=3;i++)
{
if(s[i]>=112)
{
cout<<h[i]<<"贏了"<<endl;
break;
}
}
cout<<"------------------------------------------------------------------------------------------------------------------| 終點"<<endl;
for(int j=0; j<=3; j++)
{
for(int i=0; i<=s[j]; i++)
cout<<" ";
cout<<h[j]<<endl;
}
round++;
system("pause");
goto re;
return 0;
}
複製代碼
作者:
邱品惟
時間:
2023-8-11 23:42
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int round=1;
re:
int s[]={0,0,0,0};
srand(time(NULL));
cout<<"「好事成雙」賽馬場第"<<round<<"場"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
system("pause");
while(true)
{
system("cls");
int r=rand()%4;
s[r]++;
cout<<"比賽進行中"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<=s[0]; i++)
cout<<" ";
cout<<"◆"<<endl;
for(int i=0; i<=s[1]; i++)
cout<<" ";
cout<<"★"<<endl;
for(int i=0; i<=s[2]; i++)
cout<<" ";
cout<<"▲"<<endl;
for(int i=0; i<=s[3]; i++)
cout<<" ";
cout<<"●"<<endl;
if(s[r]==73)
break;
}
system("cls");
cout<<"比賽結束"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<=s[0]; i++)
cout<<" ";
cout<<"◆"<<endl;
for(int i=0; i<=s[1]; i++)
cout<<" ";
cout<<"★"<<endl;
for(int i=0; i<=s[2]; i++)
cout<<" ";
cout<<"▲"<<endl;
for(int i=0; i<=s[3]; i++)
cout<<" ";
cout<<"●"<<endl;
round=round+1;
if(s[0]==73)
cout<<"恭喜◆獲勝"<<endl;
else if(s[1]==73)
cout<<"恭喜★獲勝"<<endl;
else if(s[2]==73)
cout<<"恭喜▲獲勝"<<endl;
else if(s[3]==73)
cout<<"恭喜●獲勝"<<endl;
system("pause");
system("cls");
goto re;
system("pause");
return 0;
}
複製代碼
作者:
朱奕祈
時間:
2024-3-4 20:09
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int round=1;
re:
system("cls");
int s[]={0,0,0,0};
string h[]={"◆","★","▲","●"};
srand(time(NULL));
cout<<"「好事成雙」賽馬場,第"<<round<<"局"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0;i<4;i++)
{
cout<<h[i]<<endl;
}
system("pause");
while(true)
{
system("cls");
int r=rand()%4;
s[r]++;
cout<<"比賽進行中"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int j=0;j<4;j++)
{
for(int i=0;i<s[j];i++)
{
cout<<" ";
}
cout<<h[j]<<endl;
}
if(s[r]==73)
{
break;
_sleep(50);
}
}
system("cls");
for(int i=0;i<=3;i++)
{
if(s[i]==73)
{
cout<<"比賽結束! 由 "<<h[i]<<" 先馳得點!"<<endl;
}
}
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int x=0;x<4;x++)
{
for(int y=0;y<s[x];y++)
{
cout<<" ";
}
cout<<h[x]<<endl;
}
system("pause");
round++;
goto re;
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2