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

  85.        }
  86.       

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

  169.     system("pause");
  170.     return 0;
  171.       
  172. }
複製代碼

TOP

返回列表