返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<time.h>
  4. using namespace std;
  5. int horse1=0, horse2=0, horse3=0, horse4=0,random=0,money=0,option=0,buyin=0,bet=0,player=0,times=1;
  6. void play()
  7. {
  8.      while(horse1!=75 && horse2!=75 && horse3!=75 && horse4!=75)
  9.      {
  10.             random=rand()%4;   //產生0~3之隨機亂數
  11.             if(random==0)
  12.             {
  13.                 horse1++;
  14.             }
  15.             else if(random==1)
  16.             {
  17.                 horse2++;
  18.             }
  19.             else if(random==2)
  20.             {
  21.                 horse3++;
  22.             }
  23.             else if(random==3)
  24.             {
  25.                 horse4++;
  26.             }
  27.             cout<<"比賽進行中"<<endl;
  28.             cout<<"------------------------------------------------------------------------| 終點"<<endl;
  29.             for(int i=1; i<=horse1; i++)
  30.             {
  31.                 cout<<" ";
  32.             }
  33.             cout<<"◆"<<endl;
  34.             for(int i=1; i<=horse2; i++)
  35.             {
  36.                 cout<<" ";
  37.             }
  38.             cout<<"★"<<endl;
  39.             for(int i=1; i<=horse3; i++)
  40.             {
  41.                 cout<<" ";
  42.             }
  43.             cout<<"▲"<<endl;
  44.             for(int i=1; i<=horse4; i++)
  45.             {
  46.                 cout<<" ";
  47.             }
  48.             cout<<"●"<<endl;
  49.             system("cls");      
  50.         }
  51.         times++;
  52.         cout<<"比賽結束  由";
  53.         if(horse1==75)
  54.         {
  55.             cout<<"◆";              
  56.         }
  57.         if(horse2==75)
  58.         {
  59.             cout<<"★";              
  60.         }
  61.         if(horse3==75)
  62.         {
  63.             cout<<"▲";              
  64.         }
  65.         if(horse4==75)
  66.         {
  67.             cout<<"●";              
  68.         }
  69.         cout<<"先馳得點!"<<endl;
  70.         cout<<"------------------------------------------------------------------------| 終點"<<endl;
  71.         for(int i=1; i<=horse1; i++)
  72.         {
  73.             cout<<" ";
  74.         }
  75.         cout<<"◆"<<endl;
  76.         for(int i=1; i<=horse2; i++)
  77.         {
  78.             cout<<" ";
  79.         }
  80.         cout<<"★"<<endl;
  81.         for(int i=1; i<=horse3; i++)
  82.         {
  83.             cout<<" ";
  84.         }
  85.         cout<<"▲"<<endl;
  86.         for(int i=1; i<=horse4; i++)
  87.         {
  88.             cout<<" ";
  89.         }
  90.         cout<<"●"<<endl;
  91. }
  92. int main()
  93. {
  94.     while(true)
  95.     {
  96.         while(option==0 || option==1)
  97.         {
  98.             srand(time(NULL));
  99.             system("cls");
  100.             cout<<"「好事成雙」賽馬場  "<<"第"<<times<<"次"<<endl;
  101.             cout<<"------------------------------------------------------------------------| 終點"<<endl;
  102.             cout<<"◆"<<endl;
  103.             cout<<"★"<<endl;
  104.             cout<<"▲"<<endl;
  105.             cout<<"●"<<endl;
  106.             cout<<"可用餘額:"<<money<<"元"<<endl;
  107.             cout<<"(1)買入 (2)下注 (3)離開   請選擇:"<<endl;
  108.             cin>>option;
  109.             if(option==1)
  110.             {
  111.                 cout<<"買入:";
  112.                 cin>>buyin;
  113.                 money=money+buyin;        
  114.             }
  115.             else if(option==2)
  116.             {
  117.                 cout<<"下注:";
  118.                 cin>>bet;
  119.                 if(money>=bet)
  120.                 {
  121.                     money=money-bet;         
  122.                     cout<<endl<<"(1)◆ (2)★ (3)▲ (4)●  請選擇: ";
  123.                     cin>>player;
  124.                     cout<<"比賽即將開始..."<<endl;
  125.                     play();     
  126.                 }
  127.                 else
  128.                 {
  129.                     cout<<"餘額不足,輸入錯誤!!!"<<endl;   
  130.                     option = 0;
  131.                     break;
  132.                 }         
  133.             }
  134.             else if(option == 3)
  135.             {
  136.                 break;
  137.             }
  138.             system("pause");
  139.             system("cls");
  140.         }
  141.         
  142.         system("pause");
  143.         system("cls");      
  144.     }
  145.     system("pause");
  146.     return 0;   
  147. }
複製代碼

TOP

返回列表