標題:
賽馬程式 (三)
[打印本頁]
作者:
鄭繼威
時間:
2023-3-18 12:11
標題:
賽馬程式 (三)
1. 在比賽首頁顯示第幾局
2. 在比賽結束頁顯示哪一位選手勝出
#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-3-18 14:20
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int round=1;
re:
system("cls");
srand(time(NULL));
string p[]={"◆","★","▲","●"};
int s[]={0,0,0,0};
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]++;
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(10);
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-3-18 14: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;
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-3-18 14:23
#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<<"「壞事成三」賽馬場(照夜玉獅子)"<<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(1);
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;
system("pause");
return 0;
}
複製代碼
作者:
羅暐傑
時間:
2023-3-18 14:24
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main(){
int round=1;
re:
system("cls");
srand(time(NULL));
string p[]={"◆","★","▲","●"};
int s[]={0,0,0,0};
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]++;
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("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;
}
round++;
system("pause");
goto re;
return 0;
}
複製代碼
作者:
宜儒
時間:
2023-3-18 14:24
本帖最後由 宜儒 於 2023-3-18 14:30 編輯
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main(){
int round=1; //局數
srand(time(NULL));
re:
system("cls");
int r=0; //0~3
string p[]={"◆","★","▲","●"}; //存放馬
int s[]={0,0,0,0}; //每匹馬左側的空白數
cout<<"好事成雙賽馬場 第"<<round<<"局"<<endl;
cout<<"--------------------------------------------------------------------|終點"<<endl;
for(int i=0;i<=3;i++)
cout<<p[i]<<endl;
system("pause");
while(s[r]<70){ //只要有任何一匹馬到達終點,迴圈就會停下來
r=rand()%4; //r=0~3
s[r]++;
system("cls");
cout<<"比賽進行中"<<endl;
cout<<"--------------------------------------------------------------------|終點"<<endl;
for(int j=0;j<=3;j++){
for(int i=0;i<s[j];i++)
cout<<" ";
cout<<p[j]<<endl;
}
_sleep(10);
}
system("cls");
cout<<"比賽結束! 由"<<p[r]<<"勝出!"<<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++; //局數+1
goto re;
return 0;
}
複製代碼
作者:
林雋喆
時間:
2023-3-18 14:24
#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;
}
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-3-18 14:24
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int round = 1;
srand(time(NULL));
string shape[] = { "◆","★","▲","●" };
re:
int steps[] = {0,0,0,0};
cout<<"第"<<round<<"局"<<endl;
cout << "超坑錢賽馬場" << endl;
cout << "-------------------------------------------------------------------------|終點";
_sleep(2000);
int w = 0;int plus;
while (w <= 71)
{
cout << "比賽進行中" << endl;
cout << "-------------------------------------------------------------------------|終點" << endl;
steps[rand() % 4] += 1;
w = steps[rand() % 4];
for (int s = 0;s <= steps[0];s++)
cout << " ";
cout << shape[0] << endl;
for (int s = 0;s <= steps[1];s++)
cout << " ";
cout << shape[1] << endl;;
for (int s = 0;s <= steps[2];s++)
cout << " ";
cout << shape[2] << endl;
for (int s = 0;s <= steps[3];s++)
cout << " ";
cout << shape[3] << endl;
_sleep(10);
if (w ==71)
{
round++;
cout<<"由"<<shape[rand() % 4]<<"獲勝" <<endl;
_sleep(1000);
system("pause");
goto re;
}
system("cls");
}
}
複製代碼
作者:
陳宥霖
時間:
2023-3-18 14:27
#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]++;
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-3-18 14:29
本帖最後由 羅紹齊 於 2023-3-18 14:31 編輯
#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(1);
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-3-18 14:32
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
re:
system("cls");
int s[]={0,0,0,0};
srand(time(NULL));
cout<<"「好事成單」賽馬場"<<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;
_sleep(50);
}
system("cls");
cout<<"比賽結束! 由 "<<p[r]<<" 先馳得點!"<<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;
system("pause");
goto re;
return 0;
}
複製代碼
作者:
翁川祐
時間:
2023-3-24 19:24
#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;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2