- #include<iostream>
- #include<cstdlib>
- #include<ctime>
- using namespace std;
- int main()
- {
- cout<<"「智慧」賽馬場"<<endl;
- cout<<"------------------------------------------------------------------------| 終點"<<endl;
- cout<<"◆"<<endl;
- cout<<"★"<<endl;
- cout<<"▲"<<endl;
- cout<<"●"<<endl;
- system("pause"); // 按下enter 才開始
- system("cls"); // 清空畫面
- srand(time(NULL)); // 撒種子亂數
- int a=0,b=0,c=0,d=0,r; // 每匹馬前進的進度
- // 當有任一匹跑到終點70 的時候就跳離迴圈
- string words ="賽馬進行中";
- while(a<=70 && b<=70 && c<=70 && d<=70)
- {
- cout<<words<<endl;
- cout<<"------------------------------------------------------------------------| 終點"<<endl;
- // 隨機挑一匹馬
- r = rand()%4+1;
- // 每匹馬 跑的進度
- switch(r)
- {
- case 1:
- a++;
- break;
- case 2:
- b++;
- break;
- case 3:
- c++;
- break;
- case 4:
- d++;
- break;
- }
-
- // 要把每匹馬的進度給輸出
- // 第一匹馬
- for(int i=0;i<=a;i++)
- {
- cout<<" ";
- }
- cout<<"◆"<<endl;
-
- // 第二匹馬
- for(int i=0;i<=b;i++)
- {
- cout<<" ";
- }
- cout<<"★"<<endl;
-
- // 第三匹馬
- for(int i=0;i<=c;i++)
- {
- cout<<" ";
- }
- cout<<"▲"<<endl;
-
- // 第四匹馬
- for(int i=0;i<=d;i++)
- {
- cout<<" ";
- }
- cout<<"●"<<endl;
-
- if(a==70 || b==70 || c==70 || d==70)
- {
- words = "賽馬完成";
- }
- // 當有任一個跑到71 就代表到終點 不要清空畫面
- if(a==71 || b==71 || c==71 || d==71)
- {
- }else{
- system("cls"); // 清空畫面
- }
-
- }
-
- system("pause");
- return 0;
- }
複製代碼 |