- #include<iostream>
- #include<cstdlib>
- #include<time.h>
- using namespace std;
- void Result(int horse1,int horse2,int horse3,int horse4)
- {
- cout<<"------------------------------------------------------------------------| 終點"<<endl;
- for(int i=1; i<=horse1; i++)
- {
- cout<<" ";
- }
- cout<<"◆"<<endl;
- for(int i=1; i<=horse2; i++)
- {
- cout<<" ";
- }
- cout<<"★"<<endl;
- for(int i=1; i<=horse3; i++)
- {
- cout<<" ";
- }
- cout<<"▲"<<endl;
- for(int i=1; i<=horse4; i++)
- {
- cout<<" ";
- }
- cout<<"●"<<endl;
- }
- int main()
- {
- int times=1;
- while(true)
- {
- int horse1=0, horse2=0, horse3=0, horse4=0,random=0;
- srand(time(NULL));
- system("cls");
- cout<<"「好事成雙」賽馬場 "<<"第"<<times<<"次"<<endl;
- cout<<"------------------------------------------------------------------------| 終點"<<endl;
- cout<<"◆"<<endl;
- cout<<"★"<<endl;
- cout<<"▲"<<endl;
- cout<<"●"<<endl;
- system("pause");
- system("cls");
- while(horse1!=75 && horse2!=75 && horse3!=75 && horse4!=75)
- {
- random=rand()%4; //產生0~3之隨機亂數
- if(random==0)
- {
- horse1++;
- }
- else if(random==1)
- {
- horse2++;
- }
- else if(random==2)
- {
- horse3++;
- }
- else if(random==3)
- {
- horse4++;
- }
- cout<<"比賽進行中"<<endl;
- Result(horse1,horse2,horse3,horse4);
- system("cls");
- }
- times++;
- cout<<"比賽結束 由";
- if(horse1==75)
- {
- cout<<"◆";
- }
- if(horse2==75)
- {
- cout<<"★";
- }
- if(horse3==75)
- {
- cout<<"▲";
- }
- if(horse4==75)
- {
- cout<<"●";
- }
- cout<<"先馳得點!"<<endl;
- Result(horse1,horse2,horse3,horse4);
- system("pause");
- system("cls");
- }
- system("pause");
- return 0;
- }
複製代碼 |