返回列表 發帖
  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 pay = 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 h1=0, h2=0, h3=0, h4=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.      
  31.        cout<< "(1)儲值 (2) 下注 (3)離開 請選擇:";
  32.        cin >> select;
  33.        switch(select)
  34.        {
  35.         case 1:
  36.            cout << "買入:";
  37.            cin >> buy;
  38.            
  39.            point += (buy<=0) ? point : buy;
  40.            cout<< "可用帳戶餘額:" <<  point << endl;
  41.            break;
  42.         case 2:
  43.                if(point >=0)  
  44.                 {
  45.                  cout << "下注:";
  46.                  cin >> pay;
  47.                  string error = (pay>point || pay<=0) ? "輸入錯誤":"";
  48.                if(error == "error")
  49.                 {
  50.                  break;
  51.                 }
  52.                else
  53.                 {
  54.                   buy_total += pay;
  55.                   point = point - pay;
  56.                   cout<< "帳戶餘額:" <<  point << endl;
  57.                   cout << "請選擇馬匹:" << endl;
  58.                   cout << "(1)◆ (2)★ (3)▲ (4)● ";
  59.                   cin >> my_select;
  60.                   cout << "比賽開始!" << endl;
  61.                   isStart = false;
  62.                 }
  63.                 break;
  64.               }
  65.               else
  66.                {
  67.                  cout << "餘額不足繼續儲值" << endl;
  68.                  continue;
  69.                }
  70.         case 3:
  71.                if(result > buy_total)
  72.                 {
  73.                   cout << "共贏了" << result - buy_total << "元" << endl;
  74.                 }
  75.                else if (result == buy_total)
  76.                 {
  77.                   cout << "沒輸沒贏全輸而退";
  78.                 }
  79.                else if(result <buy_total)
  80.                 {
  81.                
  82.                    cout << "賠" << buy_total - result << "元" << endl;
  83.                 }
  84.                system("pause");
  85.                return 0;
  86.        }
  87.     }
  88.     system("pause");
  89.     system("cls");
  90.    
  91.     while(h1!=75 && h2!=75 && h3!=75 && h4!=75)
  92.     {
  93.         random=rand()%4;   
  94.         if(random==0)
  95.          {
  96.            h1++;
  97.          }  
  98.         else if(random==1)
  99.          {
  100.            h2++;
  101.          }
  102.         else if(random==2)
  103.          {
  104.            h3++;
  105.          }
  106.         else if(random==3)
  107.          {
  108.            h4++;
  109.          }
  110.         cout<<"比賽中"<<endl;
  111.         cout<<"------------------------------------------------------------------------| 終點"<<endl;
  112.       
  113.         for(int i=1; i<=h1; i++)
  114.          {
  115.            cout<<" ";
  116.          }   
  117.         cout<<"◆"<<endl;
  118.         
  119.         for(int i=1; i<=h2; i++)
  120.          {
  121.            cout<<" ";
  122.          }   
  123.         cout<<"★"<<endl;
  124.         
  125.          for(int i=1; i<=h3; i++)
  126.          {
  127.            cout<<" ";
  128.          }   
  129.         cout<<"▲"<<endl;
  130.         
  131.          for(int i=1; i<=h4; i++)
  132.          {
  133.            cout<<" ";
  134.          }   
  135.         cout<<"●"<<endl;
  136.         system("cls");      
  137.     }
  138.     times++;
  139.     system("cls");     
  140.     if(h1 == 75)
  141.     {
  142.       cout<<"比賽結束,由◆先馳得點"<<endl;
  143.       win = 1;
  144.     }
  145.     else if(h2 == 75)
  146.     {
  147.       cout<<"比賽結束,由★先馳得點"<<endl;
  148.       win = 2;
  149.     }
  150.     else if(h3 == 75)
  151.     {
  152.       cout<<"比賽結束,由▲先馳得點"<<endl;
  153.       win = 3;
  154.     }
  155.     else if(h4 == 75)
  156.     {
  157.       cout<<"比賽結束,由●先馳得點"<<endl;
  158.       win = 4;
  159.     }
  160.    
  161.     if(my_select == win)
  162.     {
  163.      result += (pay*3);
  164.      point = point + (pay*3) ;
  165.      cout << "目前金額如下" << endl;
  166.      cout << point << endl;
  167.     }
  168.     else
  169.     {
  170.      cout << "賭注失敗,目前金額如下" << endl;
  171.      cout << point << endl;
  172.     }
  173.     isStart = true;
  174. }
  175.     system("pause");
  176.     return 0;     
  177. }
複製代碼

TOP

返回列表