返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     cout<<"「智慧」賽馬場"<<endl;
  8.     cout<<"------------------------------------------------------------------------| 終點"<<endl;
  9.     cout<<"◆"<<endl;
  10.     cout<<"★"<<endl;
  11.     cout<<"▲"<<endl;
  12.     cout<<"●"<<endl;
  13.     system("pause"); // 按下enter 才開始
  14.     system("cls"); // 清空畫面
  15.     srand(time(NULL)); // 撒種子亂數

  16.     int a=0,b=0,c=0,d=0,r; // 每匹馬前進的進度
  17.     // 當有任一匹跑到終點70 的時候就跳離迴圈
  18.     string words ="賽馬進行中";
  19.     while(a<=70 && b<=70 && c<=70 && d<=70)
  20.     {  
  21.       cout<<words<<endl;
  22.       cout<<"------------------------------------------------------------------------| 終點"<<endl;   
  23.       // 隨機挑一匹馬
  24.       r = rand()%4+1;
  25.       // 每匹馬 跑的進度
  26.       switch(r)
  27.       {
  28.           case 1:
  29.                a++;
  30.                break;
  31.           case 2:
  32.                b++;
  33.                break;
  34.           case 3:
  35.                c++;
  36.                break;
  37.           case 4:
  38.                d++;
  39.                break;
  40.       }
  41.       
  42.       // 要把每匹馬的進度給輸出
  43.       // 第一匹馬
  44.       for(int i=0;i<=a;i++)
  45.       {
  46.           cout<<" ";
  47.       }
  48.       cout<<"◆"<<endl;
  49.       
  50.       // 第二匹馬
  51.       for(int i=0;i<=b;i++)
  52.       {
  53.           cout<<" ";
  54.       }
  55.       cout<<"★"<<endl;
  56.       
  57.        // 第三匹馬
  58.       for(int i=0;i<=c;i++)
  59.       {
  60.           cout<<" ";
  61.       }
  62.       cout<<"▲"<<endl;
  63.       
  64.       // 第四匹馬
  65.       for(int i=0;i<=d;i++)
  66.       {
  67.           cout<<" ";
  68.       }
  69.       cout<<"●"<<endl;
  70.       
  71.       if(a==70 || b==70 || c==70 || d==70)
  72.       {
  73.          words = "賽馬完成";
  74.       }
  75.       // 當有任一個跑到71 就代表到終點 不要清空畫面
  76.       if(a==71 || b==71 || c==71 || d==71)
  77.       {      
  78.       }else{      
  79.         system("cls"); // 清空畫面
  80.       }
  81.       
  82.     }
  83.       
  84.     system("pause");
  85.     return 0;   
  86. }
複製代碼

TOP

返回列表