返回列表 發帖
  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 myselect=0;
  14.   int win=0; // 判斷是哪一批馬勝利
  15.   int result=0;
  16.   int all=0;
  17.   while(true)
  18.   {
  19.     int horse1=0, horse2=0, horse3=0, horse4=0, random=0;
  20.     srand(time(NULL));
  21.    
  22.     cout<<"「好事成雙」賽馬場   " << "第 " <<times << "局 "<<endl;
  23.     cout<<"------------------------------------------------------------------------| 終點"<<endl;
  24.     cout<<"◆"<<endl;
  25.     cout<<"★"<<endl;
  26.     cout<<"▲"<<endl;
  27.     cout<<"●"<<endl;
  28.     cout<< "可用帳戶餘額:" <<  point << endl;
  29.     while(isStart)
  30.     {
  31.      
  32.        cout<< "(1)儲值 (2) 下注 (3)離開 請選擇:";
  33.        cin >> select;
  34.        switch(select)
  35.        {
  36.         case 1:
  37.            cout << "買入:";
  38.            cin >> buy;
  39.            // 三元運算子
  40.            point += (buy<=0) ? point : buy;
  41.            cout<< "可用帳戶餘額:" <<  point << endl;
  42.            break;
  43.         case 2:
  44.                if(point >=0)  
  45.               {
  46.                cout << "下注:";
  47.                cin >> bet;
  48.                string error = (bet>point || bet<=0) ? "輸入錯誤":"";
  49.                if(error == "error")
  50.                {
  51.                 break;
  52.                }
  53.                else
  54.                {
  55.                  all += bet;
  56.                  point = point - bet;
  57.                  cout<< "可用帳戶餘額:" <<  point << endl;
  58.                  cout << "請選擇以下的馬匹:" << endl;
  59.                  cout << "(1)◆ (2)★ (3)▲ (4)● ";
  60.                  cin >> myselect;
  61.                  cout << "比賽正式開始!" << endl;
  62.                  isStart = false;
  63.                }
  64.                 break;
  65.               }
  66.               else
  67.               {
  68.                cout << "餘額不足,請先進行儲值" << endl;
  69.                continue;
  70.               }
  71.         case 3:
  72.                if(result > all)
  73.                {
  74.                  cout << "恭喜你! 這次總共贏了" << result - all << "元!" << endl;
  75.                }
  76.                else if (result == all)
  77.                {
  78.                  cout << "沒輸沒贏! 全身而退!"<<endl;
  79.                  
  80.                }
  81.                else if(result <all)
  82.                {
  83.                
  84.                    cout << "不好意思! 讓你損失了" << all - result << "元!" << endl;
  85.                }
  86.                system("pause");
  87.                return 0;

  88.        }
  89.       

  90.     }
  91.    
  92.    
  93.     system("pause");
  94.     system("cls");
  95.    
  96.     while(horse1!=75 && horse2!=75 && horse3!=75 && horse4!=75)
  97.     {
  98.         random=rand()%4;   //產生0~3之隨機亂數
  99.         if(random==0) {
  100.            horse1++;
  101.         }  
  102.         else if(random==1) {
  103.            horse2++;
  104.         }
  105.         else if(random==2) {
  106.            horse3++;
  107.         }
  108.         else if(random==3) {
  109.            horse4++;
  110.         }
  111.         cout<<"比賽進行中"<<endl;
  112.         cout<<"------------------------------------------------------------------------| 終點"<<endl;
  113.       
  114.         for(int i=1; i<=horse1; i++) {
  115.            cout<<" ";
  116.         }   
  117.         cout<<"◆"<<endl;
  118.         
  119.         for(int i=1; i<=horse2; i++) {
  120.            cout<<" ";
  121.         }   
  122.         cout<<"★"<<endl;
  123.         
  124.          for(int i=1; i<=horse3; i++) {
  125.            cout<<" ";
  126.         }   
  127.         cout<<"▲"<<endl;
  128.         
  129.          for(int i=1; i<=horse4; i++) {
  130.            cout<<" ";
  131.         }   
  132.         cout<<"●"<<endl;
  133.         system("cls");      
  134.     }
  135.     times++;
  136.     system("cls");     
  137.     if(horse1 == 75)
  138.     {
  139.       cout<<"比賽結束,由◆先馳得點"<<endl;
  140.       win = 1;
  141.     }
  142.     else if(horse2 == 75)
  143.     {
  144.       cout<<"比賽結束,由★先馳得點"<<endl;
  145.       win = 2;
  146.     }
  147.     else if(horse3 == 75)
  148.     {
  149.       cout<<"比賽結束,由▲先馳得點"<<endl;
  150.       win = 3;
  151.     }
  152.     else if(horse4 == 75)
  153.     {
  154.       cout<<"比賽結束,由●先馳得點"<<endl;
  155.       win = 4;
  156.     }
  157.    
  158.     if(myselect == win)
  159.     {
  160.      result += (bet*3);
  161.      point = point + (bet*3) ;
  162.      cout << "恭喜您獲得勝利!,目前金額如下" << endl;
  163.      cout << point << endl;
  164.     }
  165.     else
  166.     {
  167.      cout << "賭注失敗,目前金額如下" << endl;
  168.      cout << point << endl;
  169.     }
  170.     isStart = true;
  171. }

  172.     system("pause");
  173.     return 0;
  174.       
  175. }
複製代碼

TOP

返回列表