返回列表 發帖
  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 paid = 0;
  12.   bool isStart= true;
  13.   int my_select = 0;
  14.   int win = 0;
  15.   while(true)
  16.   {
  17.     int h1=0, h2=0, h3=0, h4=0, random=0;
  18.     srand(time(NULL));
  19.    
  20.     cout<<"「好事成雙」賽馬場   " << "第 " <<times << "局 "<<endl;
  21.     cout<<"------------------------------------------------------------------------| 終點"<<endl;
  22.     cout<<"◆"<<endl;
  23.     cout<<"★"<<endl;
  24.     cout<<"▲"<<endl;
  25.     cout<<"●"<<endl;
  26.     cout<< "可用帳戶餘額:" <<  point << endl;
  27.     while(isStart)
  28.     {
  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 >> paid;
  45.                string error = (paid>point || paid<=0) ? "輸入錯誤":"";
  46.                if(error == "error")
  47.                {
  48.                 break;
  49.                }
  50.                else
  51.                {
  52.                  point = point - paid;
  53.                  cout<<"可用餘額:"<<point<<endl;
  54.                  cout << "請選擇最順眼的馬匹:" << endl;
  55.                  cout << "(1)◆ (2)★ (3)▲ (4)● ";
  56.                  cin >> my_select;
  57.                  cout << "比賽開始!" << endl;
  58.                  isStart = false;
  59.                }
  60.                 break;
  61.               }
  62.               else
  63.               {
  64.                cout << "餘額不足,繼續儲值" << endl;
  65.                continue;
  66.               }

  67.        }
  68.     }
  69.    
  70.    
  71.     system("pause");
  72.     system("cls");
  73.    
  74.     while(h1!=75 && h2!=75 && h3!=75 && h4!=75)
  75.     {
  76.         random=rand()%4;   
  77.         if(random==0)
  78.         {
  79.            h1++;
  80.         }  
  81.         else if(random==1)
  82.         {
  83.            h2++;
  84.         }
  85.         else if(random==2)
  86.         {
  87.            h3++;
  88.         }
  89.         else if(random==3)
  90.         {
  91.            h4++;
  92.         }
  93.         cout<<"比賽進行中"<<endl;
  94.         cout<<"------------------------------------------------------------------------| 終點"<<endl;
  95.       
  96.         for(int i=1; i<=h1; i++)
  97.         {
  98.            cout<<" ";
  99.         }   
  100.         cout<<"◆"<<endl;
  101.         
  102.         for(int i=1; i<=h2; i++)
  103.         {
  104.            cout<<" ";
  105.         }   
  106.         cout<<"★"<<endl;
  107.         
  108.          for(int i=1; i<=h3; i++)
  109.          {
  110.            cout<<" ";
  111.          }   
  112.         cout<<"▲"<<endl;
  113.         
  114.          for(int i=1; i<=h4; i++)
  115.          {
  116.            cout<<" ";
  117.          }   
  118.         cout<<"●"<<endl;
  119.         system("cls");      
  120.     }
  121.     times++;
  122.     system("cls");     
  123.     if(h1 == 75)
  124.     {
  125.       cout<<"比賽結束,由◆先馳得點"<<endl;
  126.       win = 1;
  127.     }
  128.     else if(h2 == 75)
  129.     {
  130.       cout<<"比賽結束,由★先馳得點"<<endl;
  131.       win = 2;
  132.     }
  133.     else if(h3 == 75)
  134.     {
  135.       cout<<"比賽結束,由▲先馳得點"<<endl;
  136.       win = 3;
  137.     }
  138.     else if(h4 == 75)
  139.     {
  140.       cout<<"比賽結束,由●先馳得點"<<endl;
  141.       win = 4;
  142.     }
  143.    
  144.     if(my_select == win)
  145.     {
  146.      point = point + (paid*3);
  147.      cout << "目前金額:" << endl;
  148.      cout << point << endl;
  149.     }
  150.     else
  151.     {
  152.      cout << "賭注失敗,目前金額如下" << endl;
  153.      cout << point << endl;
  154.     }
  155.     isStart = true;
  156. }

  157.     system("pause");
  158.     return 0;
  159.       
  160. }
複製代碼

TOP

返回列表