返回列表 發帖
  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.   while(true)
  16.   {
  17.     int horse1=0, horse2=0, horse3=0, horse4=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 >> bet;
  45.                string error = (bet>point || bet<=0) ? "輸入錯誤":"";
  46.                if(error == "error")
  47.                {
  48.                 break;
  49.                }
  50.                else
  51.                {
  52.                  point = point - bet;
  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(horse1!=75 && horse2!=75 && horse3!=75 && horse4!=75)
  75.     {
  76.         random=rand()%4;   
  77.         if(random==0) {
  78.            horse1++;
  79.         }  
  80.         else if(random==1) {
  81.            horse2++;
  82.         }
  83.         else if(random==2) {
  84.            horse3++;
  85.         }
  86.         else if(random==3) {
  87.            horse4++;
  88.         }
  89.         cout<<"比賽進行中"<<endl;
  90.         cout<<"------------------------------------------------------------------------| 終點"<<endl;
  91.       
  92.         for(int i=1; i<=horse1; i++) {
  93.            cout<<" ";
  94.         }   
  95.         cout<<"◆"<<endl;
  96.         
  97.         for(int i=1; i<=horse2; i++) {
  98.            cout<<" ";
  99.         }   
  100.         cout<<"★"<<endl;
  101.         
  102.          for(int i=1; i<=horse3; i++) {
  103.            cout<<" ";
  104.         }   
  105.         cout<<"▲"<<endl;
  106.         
  107.          for(int i=1; i<=horse4; i++) {
  108.            cout<<" ";
  109.         }   
  110.         cout<<"●"<<endl;
  111.         system("cls");      
  112.     }
  113.     times++;
  114.     system("cls");     
  115.     if(horse1 == 75)
  116.     {
  117.       cout<<"比賽結束,由◆先馳得點"<<endl;
  118.       win=1;
  119.     }
  120.     else if(horse2 == 75)
  121.     {
  122.       cout<<"比賽結束,由★先馳得點"<<endl;
  123.       win=2;
  124.     }
  125.     else if(horse3 == 75)
  126.     {
  127.       cout<<"比賽結束,由▲先馳得點"<<endl;
  128.       win=3;
  129.     }
  130.     else if(horse4 == 75)
  131.     {
  132.       cout<<"比賽結束,由●先馳得點"<<endl;
  133.       win=4;
  134.     }
  135.     if(my_select==win)
  136.     {
  137.       point += win*3;
  138.       cout<<"你贏了"<<endl;
  139.       cout<<point<<endl;               
  140.     }
  141.     else
  142.     {
  143.         cout<<"失敗"<<endl;
  144.         cout<<point<<endl;   
  145.     }
  146.     isStart=true;
  147.     }

  148.     system("pause");
  149.     return 0;
  150.       
  151. }
複製代碼

TOP

返回列表