返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     srand(time(NULL));
  7.     int win;
  8.     int num=1;
  9.     int balance=0;
  10.     int buyin;
  11.     int option;
  12.     int bet;
  13.     int players;
  14.     re:
  15.     system("cls");
  16.     int s[]={0,0,0,0};
  17.     string horse[]={"◆", "★", "▲", "●"};
  18.     cout<<"「好事成雙」賽馬場 第"<<num<<"局"<<endl;
  19.     cout<<"-------------------------------------------------------------------------| 終點"<<endl;
  20.     cout<<"◆"<<endl;
  21.     cout<<"★"<<endl;
  22.     cout<<"▲"<<endl;
  23.     cout<<"●"<<endl;
  24.     cout<<"可用餘額"<<balance<<"元"<<endl<<endl;
  25.     cout<<"(1)買入 (2)下注 (3)離開 請選擇: ";
  26.     cin>>option;
  27.     if(option==1)
  28.     {
  29.         cout<<"買入: ";
  30.         cin>>buyin;
  31.         if(buyin<=0)
  32.         {
  33.             cout<<"輸入錯誤!";
  34.             _sleep(1500);
  35.             goto re;            
  36.         }
  37.         balance+=buyin;
  38.         goto re;            
  39.     }
  40.     if(option==2)
  41.     {
  42.         cout<<"下注: ";
  43.         cin>>bet;
  44.         if(bet<=0)
  45.         {
  46.             cout<<"輸入錯誤!";
  47.             _sleep(1500);
  48.             goto re;
  49.         }
  50.         if(bet>balance)
  51.         {
  52.             cout<<"可用餘額不足,請先買入!";
  53.             _sleep(1500);
  54.             goto re;            
  55.         }
  56.         cout<<endl<<"(1)◆ (2)★ (3)▲ (4)● 請選擇: ";
  57.         cin>>players;
  58.         if(players<=0 || players>4)
  59.         {
  60.             cout<<"輸入錯誤!";
  61.             _sleep(1500);
  62.             goto re;            
  63.         }      
  64.         balance-=bet;
  65.         goto start;            
  66.     }
  67.     else
  68.     {
  69.         cout<<"輸入錯誤!";
  70.             _sleep(1500);
  71.             goto re;      
  72.     }
  73.     start:
  74.     cout<<"比賽即將開始..."<<endl<<endl;
  75.     system("pause");
  76.     while(true)
  77.     {
  78.         system("cls");
  79.         int r=rand()%4;
  80.         s[r]++;
  81.         cout<<"比賽進行中"<<endl;
  82.         cout<<"-------------------------------------------------------------------------| 終點"<<endl;
  83.         for(int i=0; i<=s[0]; i++)
  84.             cout<<" ";           
  85.         cout<<"◆"<<endl;
  86.         for(int i=0; i<=s[1]; i++)
  87.             cout<<" ";
  88.         cout<<"★"<<endl;
  89.         for(int i=0; i<=s[2]; i++)
  90.             cout<<" ";
  91.         cout<<"▲"<<endl;
  92.         for(int i=0; i<=s[3]; i++)
  93.             cout<<" ";
  94.         cout<<"●"<<endl;
  95.         win=r;
  96.         if(s[r]==73)
  97.             break;      
  98.         _sleep(50);               
  99.     }
  100.     system("cls");
  101.     cout<<"比賽結束! 由 "<<horse[win]<<" 勝出!"<<endl;
  102.     cout<<"-------------------------------------------------------------------------| 終點"<<endl;
  103.     for(int i=0; i<=s[0]; i++)
  104.         cout<<" ";           
  105.     cout<<"◆"<<endl;
  106.     for(int i=0; i<=s[1]; i++)
  107.         cout<<" ";
  108.     cout<<"★"<<endl;
  109.     for(int i=0; i<=s[2]; i++)
  110.         cout<<" ";
  111.     cout<<"▲"<<endl;
  112.     for(int i=0; i<=s[3]; i++)
  113.         cout<<" ";
  114.     cout<<"●"<<endl;
  115.     if(win==players)
  116.     {
  117.         balance+=bet*3;               
  118.     }
  119.     else
  120.     {
  121.         cout<<"損失"<<bet<<"元!"<<endl;   
  122.     }   
  123.     system("pause");   
  124.     num++;
  125.     goto re;
  126.     return 0;
  127. }
複製代碼

TOP

返回列表