返回列表 發帖
  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;
  11.         srand(time(NULL));
  12.         while(option==0 || option==1)
  13.         {
  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)離開   請選擇:";
  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;      
  35.             }
  36.             system("pause");
  37.             system("cls");
  38.             while(horse1!=75 && horse2!=75 && horse3!=75 && horse4!=75)
  39.             {
  40.                 random=rand()%4;   //產生0~3之隨機亂數
  41.                 if(random==0)
  42.                 {
  43.                     horse1++;
  44.                 }
  45.                 else if(random==1)
  46.                 {
  47.                     horse2++;
  48.                 }
  49.                 else if(random==2)
  50.                 {
  51.                     horse3++;
  52.                 }
  53.                 else if(random==3)
  54.                 {
  55.                     horse4++;
  56.                 }
  57.                 cout<<"比賽進行中"<<endl;
  58.                 cout<<"------------------------------------------------------------------------| 終點"<<endl;
  59.                 for(int i=1; i<=horse1; i++)
  60.                 {
  61.                     cout<<" ";
  62.                 }
  63.                 cout<<"◆"<<endl;
  64.                 for(int i=1; i<=horse2; i++)
  65.                 {
  66.                     cout<<" ";
  67.                 }
  68.                 cout<<"★"<<endl;
  69.                 for(int i=1; i<=horse3; i++)
  70.                 {
  71.                     cout<<" ";
  72.                 }
  73.                 cout<<"▲"<<endl;
  74.                 for(int i=1; i<=horse4; i++)
  75.                 {
  76.                     cout<<" ";
  77.                 }
  78.                 cout<<"●"<<endl;
  79.                 system("cls");      
  80.                 }
  81.                 times++;
  82.                 cout<<"比賽結束  由";
  83.                 if(horse1==75)
  84.                 {
  85.                     cout<<"◆";              
  86.                 }
  87.                 if(horse2==75)
  88.                 {
  89.                     cout<<"★";              
  90.                 }
  91.                 if(horse3==75)
  92.                 {
  93.                     cout<<"▲";              
  94.                 }
  95.                 if(horse4==75)
  96.                 {
  97.                     cout<<"●";              
  98.                 }
  99.                 cout<<"先馳得點!"<<endl;
  100.                 cout<<"------------------------------------------------------------------------| 終點"<<endl;
  101.                 for(int i=1; i<=horse1; i++)
  102.                 {
  103.                     cout<<" ";
  104.                 }
  105.                 cout<<"◆"<<endl;
  106.                 for(int i=1; i<=horse2; i++)
  107.                 {
  108.                     cout<<" ";
  109.                 }
  110.                 cout<<"★"<<endl;
  111.                 for(int i=1; i<=horse3; i++)
  112.                 {
  113.                     cout<<" ";
  114.                 }
  115.                 cout<<"▲"<<endl;
  116.                 for(int i=1; i<=horse4; i++)
  117.                 {
  118.                     cout<<" ";
  119.                 }
  120.                 cout<<"●"<<endl;
  121.                 system("pause");
  122.                 system("cls");      
  123.             }
  124.         }
  125.     system("pause");
  126.     return 0;   
  127. }
複製代碼

TOP

返回列表