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

  148.     system("pause");
  149.     return 0;
  150.       
  151. }
複製代碼

TOP

返回列表