返回列表 發帖

動畫及遊戲設計_三 找出勝利的那匹馬

本帖最後由 李泳霖 於 2024-3-9 11:31 編輯

1. 在比賽首頁顯示第幾局
2. 在比賽結束頁顯示哪一位選手勝出

執行畫面
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int s[]= {0,0,0,0};
  7.     string a[]= {"◆","★","▲","●"};
  8.     cout<<"「好事成雙」賽馬場"<<endl;
  9.     cout<<"-------------------------------------------------------------------------| 終點"<<endl;
  10.     for(int i=0; i<=4; i++)
  11.         cout<<a[i]<<endl;
  12.     system("pause");
  13.     system("cls");
  14.     while(true)
  15.     {
  16.         cout<<"比賽進行中"<<endl;
  17.         cout<<"-------------------------------------------------------------------------| 終點"<<endl;
  18.         int r=rand()%4;
  19.         s[r]++;
  20.         for(int i=0; i<4; i++) //哪一匹馬
  21.         {
  22.             for(int j=1; j<=s[i]; j++) //這匹馬前面的空格數
  23.             {
  24.                 cout<<" ";
  25.             }
  26.             cout<<a[i]<<endl;//這匹馬是誰
  27.         }
  28.         _sleep(10);
  29.         system("cls");
  30.         if(s[r]>=72)
  31.             break;
  32.     }
  33.     cout<<"比賽結束"<<endl;
  34.     cout<<"-------------------------------------------------------------------------| 終點"<<endl;
  35.     for(int i=0; i<4; i++) //哪一匹馬
  36.     {
  37.         for(int j=1; j<=s[i]; j++) //這匹馬前面的空格數
  38.         {
  39.             cout<<" ";
  40.         }
  41.         cout<<a[i]<<endl;//這匹馬是誰
  42.     }
  43.     system("pause");
  44.     return 0;
  45. }
複製代碼
istak.teach2@gmail.com

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見
istak.teach2@gmail.com

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

返回列表