返回列表 發帖
  1. [code]#include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     // 開局第一場
  8.     int n =1,blance=0;
  9.     re:   
  10.     system("cls");
  11.     int a=0,b=0,c=0,d=0,r, option, buyin =0,bet,horse ; // 每匹馬前進的進度   
  12.    
  13.     // 當有任一匹跑到終點70 的時候就跳離迴圈
  14.     string words ="賽馬進行中";
  15.     // 代表馬的名子
  16.     string name[4] = {"◆","★","▲","●"};
  17.    
  18.     // 宣告一個暫存的變數
  19.     int position =0;
  20.     cout<<"「好事成雙」賽馬場 第"<<n<<"局"<<endl;
  21.     cout<<"------------------------------------------------------------------------| 終點"<<endl;
  22.     cout<<"◆"<<endl;
  23.     cout<<"★"<<endl;
  24.     cout<<"▲"<<endl;
  25.     cout<<"●"<<endl;
  26.     cout<<endl;
  27.     cout<<"可用餘額:"<<blance<<"元"<<endl;
  28.     cout<<endl;
  29.     cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
  30.     cin>>option;
  31.    
  32.     // 如果買入 把錢加入餘額
  33.     if(option==1)
  34.     {
  35.         cout<<"買入:";
  36.         cin>>buyin;
  37.         blance += buyin;
  38.         goto re;
  39.     }else if(option==2)
  40.     {
  41.         cout<<"請下注:";
  42.         cin>>bet;
  43.         if(bet > blance)
  44.         {
  45.            cout<<"您餘額不足,請重新下注!"<<endl;            
  46.            system("pause");
  47.            goto re;
  48.         }else if(bet >0 && bet<=blance)
  49.         {
  50.            cout<<"(1)◆ (2)★ (3)▲(4)●請選擇:";
  51.            cin>>horse;
  52.            blance -= bet;
  53.            cout<<"即將開始賽馬!"<<endl;
  54.         }else
  55.         {
  56.            cout<<"您輸入錯誤,請重新下注!"<<endl;            
  57.            system("pause");
  58.            goto re;
  59.         }
  60.         
  61.     }else
  62.     {
  63.        // 離開      
  64.         goto end;
  65.     }
  66.    
  67.     system("pause"); // 按下enter 才開始
  68.     system("cls"); // 清空畫面
  69.     srand(time(NULL)); // 撒種子亂數
  70.   
  71.     while(a<=70 && b<=70 && c<=70 && d<=70)
  72.     {  
  73.       cout<<words<<endl;
  74.       cout<<"------------------------------------------------------------------------| 終點"<<endl;   
  75.       // 隨機挑一匹馬
  76.       r = rand()%4+1;
  77.       // 每匹馬 跑的進度
  78.       switch(r)
  79.       {
  80.           case 1:
  81.                a++;
  82.                break;
  83.           case 2:
  84.                b++;
  85.                break;
  86.           case 3:
  87.                c++;
  88.                break;
  89.           case 4:
  90.                d++;
  91.                break;
  92.       }
  93.       
  94.       // 要把每匹馬的進度給輸出
  95.       // 第一匹馬
  96.       for(int i=0;i<=a;i++)
  97.       {
  98.           cout<<" ";
  99.       }
  100.       cout<<name[0]<<endl;
  101.       
  102.       // 第二匹馬
  103.       for(int i=0;i<=b;i++)
  104.       {
  105.           cout<<" ";
  106.       }
  107.       cout<<name[1]<<endl;
  108.       
  109.        // 第三匹馬
  110.       for(int i=0;i<=c;i++)
  111.       {
  112.           cout<<" ";
  113.       }
  114.       cout<<name[2]<<endl;
  115.       
  116.       // 第四匹馬
  117.       for(int i=0;i<=d;i++)
  118.       {
  119.           cout<<" ";
  120.       }
  121.       cout<<name[3]<<endl;
  122.       
  123.    
  124.       if(a==70 || b==70 || c==70 || d==70)
  125.       {  
  126.          if(a==70)
  127.               position = 0;
  128.          if(b==70)
  129.               position =1;
  130.          if(c==70)
  131.               position =2;
  132.          if(d==70)
  133.               position =3;           
  134.          
  135.          words = "比賽結束!由"+name[position]+"先馳得點!";
  136.       }
  137.       if(a==71 || b==71 || c==71 || d==71)
  138.       {               
  139.       }else{      
  140.         system("cls");
  141.       }
  142.       
  143.     }
  144.     n++;                  
  145.     system("pause");
  146.     goto re;
  147.     end:
  148.     system("pause");
  149.     return 0;   
  150. }
複製代碼
[/code]

TOP

返回列表