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

TOP

返回列表