返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<time.h>
  4. using namespace std;
  5. int main()
  6. {
  7.   int times=1;
  8.   int point = 0;
  9.   int select = 0;
  10.   int buy = 0;
  11.   int bet = 0;
  12.   bool isStart= true;
  13.   int my_select;
  14.   while(true)
  15.   {
  16.     int horse1=0, horse2=0, horse3=0, horse4=0, random=0;
  17.     srand(time(NULL));   
  18.     cout<<"「好事成雙」賽馬場   " << "第 " <<times << "局 "<<endl;
  19.     cout<<"------------------------------------------------------------------------| 終點"<<endl;
  20.     cout<<"◆"<<endl;
  21.     cout<<"★"<<endl;
  22.     cout<<"▲"<<endl;
  23.     cout<<"●"<<endl;
  24.     cout<< "可用帳戶餘額:" <<  point << endl;
  25.     while(isStart)
  26.     {     
  27.        cout<< "(1)儲值 (2) 下注 (3)離開 請選擇:";
  28.        cin >> select;
  29.        switch(select)
  30.        {
  31.         case 1:
  32.            cout << "買入:";
  33.            cin >> buy;
  34.            point = (buy<=0) ? point : buy;
  35.            cout<< "可用帳戶餘額:" <<  point << endl;
  36.            break;
  37.         case 2:
  38.               cout << "下注:";
  39.               cin >> bet;
  40.               cout<<"請下注(1)◆(2)★(3)▲(4)●"<<endl;
  41.               cin>>my_select;
  42.               if(point<=0 || point<bet)
  43.               {
  44.               cout<<"餘額不足"<<endl;
  45.               break;
  46.               }
  47.               string error = (bet>point || bet<=0) ? "輸入錯誤":"";
  48.               if(error == "error")
  49.               {
  50.                  break;
  51.               }                                    
  52.               else
  53.               {
  54.                  isStart = false;
  55.               }
  56.            point=point-my_select ;
  57.            break;
  58.        }
  59.     }   
  60.     system("pause");
  61.     system("cls");
  62.    
  63.     while(horse1!=75 && horse2!=75 && horse3!=75 && horse4!=75)
  64.     {
  65.         random=rand()%4;
  66.         if(random==0) {
  67.            horse1++;
  68.         }  
  69.         else if(random==1) {
  70.            horse2++;
  71.         }
  72.         else if(random==2) {
  73.            horse3++;
  74.         }
  75.         else if(random==3) {
  76.            horse4++;
  77.         }
  78.         cout<<"比賽進行中"<<endl;
  79.         cout<<"------------------------------------------------------------------------| 終點"<<endl;
  80.       
  81.         for(int i=1; i<=horse1; i++) {
  82.            cout<<" ";
  83.         }   
  84.         cout<<"◆"<<endl;
  85.         
  86.         for(int i=1; i<=horse2; i++) {
  87.            cout<<" ";
  88.         }   
  89.         cout<<"★"<<endl;
  90.         
  91.          for(int i=1; i<=horse3; i++) {
  92.            cout<<" ";
  93.         }   
  94.         cout<<"▲"<<endl;
  95.         
  96.          for(int i=1; i<=horse4; i++) {
  97.            cout<<" ";
  98.         }   
  99.         cout<<"●"<<endl;
  100.         system("cls");      
  101.     }
  102.          times++;
  103.          system("cls");     
  104.          if(horse1 == 75)
  105.          {
  106.            cout<<"比賽結束,由◆先馳得點"<<endl;
  107.          }
  108.          else if(horse2 == 75)
  109.          {
  110.            cout<<"比賽結束,由★先馳得點"<<endl;
  111.          }
  112.          else if(horse3 == 75)
  113.          {
  114.            cout<<"比賽結束,由▲先馳得點"<<endl;
  115.          }
  116.          else if(horse4 == 75)
  117.          {
  118.            cout<<"比賽結束,由●先馳得點"<<endl;
  119.          }   
  120.    
  121.       }

  122.     system("pause");
  123.     return 0;        
  124. }
複製代碼

TOP

返回列表