返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<time.h>  
  4. using namespace std;
  5.   int times=1;
  6.   int balance=0; //錢包
  7.   int horse1=0, horse2=0, horse3=0, horse4=0, random=0;
  8.    
  9.     int option=0; //讓他做選擇  ,ABC => string
  10.     int buyin=0; //輸入的錢
  11.     int bet=0;
  12.     int player=0;
  13.     void start()
  14.     {
  15.           while(horse1!=75 && horse2!=75 && horse3!=75 && horse4!=75)
  16.     {
  17.          
  18.         random=rand()%4;   //產生0~3之隨機亂數
  19.         if(random==0) {
  20.            horse1++;
  21.         }  
  22.         else if(random==1) {
  23.            horse2++;
  24.         }
  25.         else if(random==2) {
  26.            horse3++;
  27.         }
  28.         else if(random==3) {
  29.            horse4++;
  30.         }
  31.         cout<<"比賽進行中"<<endl;
  32.         cout<<"------------------------------------------------------------------------| 終點"<<endl;
  33.       
  34.         for(int i=1; i<=horse1; i++) {
  35.            cout<<" ";
  36.         }   
  37.         cout<<"◆"<<endl;
  38.         
  39.         for(int i=1; i<=horse2; i++) {
  40.            cout<<" ";
  41.         }   
  42.         cout<<"★"<<endl;
  43.         
  44.          for(int i=1; i<=horse3; i++) {
  45.            cout<<" ";
  46.         }   
  47.         cout<<"▲"<<endl;
  48.         
  49.          for(int i=1; i<=horse4; i++) {
  50.            cout<<" ";
  51.         }   
  52.         cout<<"●"<<endl;
  53.         system("cls");      
  54.     }
  55.     times++;
  56.     system("cls");     
  57.     cout<<"比賽結束! 由 ";
  58.     if(horse1 == 75) {
  59.       cout<< "◆" << "先馳得點" << endl;      
  60.     }
  61.     else if (horse2 == 75) {
  62.       cout<< "★" << "先馳得點" << endl;      
  63.     }
  64.     else if (horse3 == 75) {
  65.       cout<< "▲" << "先馳得點" << endl;      
  66.     }
  67.     else if (horse4 == 75) {
  68.       cout<< "●" << "先馳得點" << endl;      
  69.     }
  70.      
  71.       cout<<"------------------------------------------------------------------------| 終點"<<endl;
  72.       
  73.         for(int i=1; i<=horse1; i++) {
  74.            cout<<" ";
  75.         }   
  76.         cout<<"◆"<<endl;
  77.         
  78.         for(int i=1; i<=horse2; i++) {
  79.            cout<<" ";
  80.         }   
  81.         cout<<"★"<<endl;
  82.         
  83.          for(int i=1; i<=horse3; i++) {
  84.            cout<<" ";
  85.         }   
  86.         cout<<"▲"<<endl;
  87.         
  88.          for(int i=1; i<=horse4; i++) {
  89.            cout<<" ";
  90.         }   
  91.         cout<<"●"<<endl;
  92.         option =0;
  93.     system("pause");
  94.     }
  95. int main()
  96. {


  97.   while(true)
  98.   {
  99.    
  100.     while(option == 0 or option ==1) //第一次或是買入
  101.     {
  102.       srand(time(NULL));
  103.       system("cls");
  104.       cout<<"「好事成雙」賽馬場   " << "第 " <<times << "局 "<<endl;
  105.       cout<<"------------------------------------------------------------------------| 終點"<<endl;
  106.       cout<<"◆"<<endl;
  107.       cout<<"★"<<endl;  
  108.       cout<<"▲"<<endl;
  109.       cout<<"●"<<endl;
  110.    
  111.       cout<<endl<<"可用餘額: "<<balance<<"元"<<endl<<endl;   
  112.       cout<<"(1)買入 (2)下注 (3)離開 請選擇: ";
  113.       cin>>option;
  114.       if(option==1)
  115.       {
  116.           cout<<"買入: ";
  117.           cin>>buyin;
  118.           balance+=buyin;
  119.            system("pause");
  120.       system("cls");         
  121.       }
  122.       if(option==2)
  123.       {
  124.       cout<<"下注"<<endl;
  125.       cin>>bet;
  126.       if(balance>=bet)
  127.       {
  128.       balance=balance-bet;
  129.        cout<<"1◆2★3▲4●"<<endl;
  130.       cin>>player;
  131.       cout<<"進行中"<<endl ;
  132.       start();   
  133.       }
  134.      else
  135.      {

  136. break;
  137.      }
  138.       }
  139.       if(option==3)
  140.       {
  141.       break;            
  142.       }
  143.       system("pause");
  144.       system("cls");
  145.     }
  146.    

  147. }

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

TOP

返回列表