返回列表 發帖
  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 loose=0;
  16.   int buy_toto=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.      
  31.        cout<< "(1)儲值 (2) 下注 (3)離開 請選擇:";
  32.        cin >> select;
  33.        switch(select)
  34.        {
  35.         case 1:
  36.            cout << "買入:";
  37.            cin >> buy;
  38.            point += (buy<=0) ? point : buy;
  39.            cout<< "可用帳戶餘額:" <<  point << endl;
  40.            break;
  41.         case 2:
  42.                if(point >=0)  
  43.               {
  44.                cout << "下注:";
  45.                cin >> bet;
  46.                string error = (bet>point || bet<=0) ? "輸入錯誤":"";
  47.                if(error == "error")
  48.                {
  49.                 break;
  50.                }
  51.                else
  52.                {
  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(buy_toto<loose)
  70.                {
  71.                cout<<"恭喜你! 這次總共贏了"<<buy_toto-loose<<"元"<<endl;
  72.                }
  73.                 else if(buy_toto==loose)
  74.                {
  75.                cout<<"沒輸沒贏! 全身而退!"<<endl;
  76.                }
  77.                else if(loose>buy_toto)
  78.                {
  79.                     cout<<"不好意思! 讓你損失了"<<buy_toto-loose<<"元"<<endl;
  80.                }
  81.        }
  82.     }     
  83.     system("pause");
  84.     system("cls");
  85.    
  86.     while(horse1!=75 && horse2!=75 && horse3!=75 && horse4!=75)
  87.     {
  88.         random=rand()%4;   
  89.         if(random==0) {
  90.            horse1++;
  91.         }  
  92.         else if(random==1) {
  93.            horse2++;
  94.         }
  95.         else if(random==2) {
  96.            horse3++;
  97.         }
  98.         else if(random==3) {
  99.            horse4++;
  100.         }
  101.         cout<<"比賽進行中"<<endl;
  102.         cout<<"------------------------------------------------------------------------| 終點"<<endl;
  103.       
  104.         for(int i=1; i<=horse1; i++) {
  105.            cout<<" ";
  106.         }   
  107.         cout<<"◆"<<endl;
  108.         
  109.         for(int i=1; i<=horse2; i++) {
  110.            cout<<" ";
  111.         }   
  112.         cout<<"★"<<endl;
  113.         
  114.          for(int i=1; i<=horse3; i++) {
  115.            cout<<" ";
  116.         }   
  117.         cout<<"▲"<<endl;
  118.         
  119.          for(int i=1; i<=horse4; i++) {
  120.            cout<<" ";
  121.         }   
  122.         cout<<"●"<<endl;
  123.         system("cls");      
  124.     }
  125.     times++;
  126.     system("cls");     
  127.     if(horse1 == 75)
  128.     {
  129.       cout<<"比賽結束,由◆先馳得點"<<endl;
  130.       win=1;
  131.     }
  132.     else if(horse2 == 75)
  133.     {
  134.       cout<<"比賽結束,由★先馳得點"<<endl;
  135.       win=2;
  136.     }
  137.     else if(horse3 == 75)
  138.     {
  139.       cout<<"比賽結束,由▲先馳得點"<<endl;
  140.       win=3;
  141.     }
  142.     else if(horse4 == 75)
  143.     {
  144.       cout<<"比賽結束,由●先馳得點"<<endl;
  145.       win=4;
  146.     }
  147.     if(my_select==win)
  148.     {
  149.       loose += (win*3);              
  150.       point += loose+(win*3);
  151.       cout<<"你贏了"<<endl;
  152.       cout<<point<<endl;               
  153.     }
  154.     else
  155.     {
  156.         cout<<"失敗"<<endl;
  157.         cout<<point<<endl;   
  158.     }
  159.     isStart=true;
  160.     }
  161.     system("pause");
  162.     return 0;     
  163. }
複製代碼

TOP

返回列表