返回列表 發帖

賽馬程式 (六)

  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.   
  16.     while(horse1!=75 && horse2!=75 && horse3!=75 && horse4!=75)
  17.     {
  18.          
  19.         random=rand()%4;   //產生0~3之隨機亂數
  20.         if(random==0) {
  21.            horse1++;
  22.         }  
  23.         else if(random==1) {
  24.            horse2++;
  25.         }
  26.         else if(random==2) {
  27.            horse3++;
  28.         }
  29.         else if(random==3) {
  30.            horse4++;
  31.         }
  32.         cout<<"比賽進行中"<<endl;
  33.         cout<<"------------------------------------------------------------------------| 終點"<<endl;
  34.       
  35.         for(int i=1; i<=horse1; i++) {
  36.            cout<<" ";
  37.         }   
  38.         cout<<"◆"<<endl;
  39.         
  40.         for(int i=1; i<=horse2; i++) {
  41.            cout<<" ";
  42.         }   
  43.         cout<<"★"<<endl;
  44.         
  45.          for(int i=1; i<=horse3; i++) {
  46.            cout<<" ";
  47.         }   
  48.         cout<<"▲"<<endl;
  49.         
  50.          for(int i=1; i<=horse4; i++) {
  51.            cout<<" ";
  52.         }   
  53.         cout<<"●"<<endl;
  54.         system("cls");      
  55.     }
  56.     times++;
  57.     system("cls");     
  58.     cout<<"比賽結束! 由 ";
  59.     if(horse1 == 75) {
  60.       cout<< "◆" << "先馳得點" << endl;      
  61.     }
  62.     else if (horse2 == 75) {
  63.       cout<< "★" << "先馳得點" << endl;      
  64.     }
  65.     else if (horse3 == 75) {
  66.       cout<< "▲" << "先馳得點" << endl;      
  67.     }
  68.     else if (horse4 == 75) {
  69.       cout<< "●" << "先馳得點" << endl;      
  70.     }
  71.      
  72.       cout<<"------------------------------------------------------------------------| 終點"<<endl;
  73.       
  74.         for(int i=1; i<=horse1; i++) {
  75.            cout<<" ";
  76.         }   
  77.         cout<<"◆"<<endl;
  78.         
  79.         for(int i=1; i<=horse2; i++) {
  80.            cout<<" ";
  81.         }   
  82.         cout<<"★"<<endl;
  83.         
  84.          for(int i=1; i<=horse3; i++) {
  85.            cout<<" ";
  86.         }   
  87.         cout<<"▲"<<endl;
  88.         
  89.          for(int i=1; i<=horse4; i++) {
  90.            cout<<" ";
  91.         }   
  92.         cout<<"●"<<endl;
  93.       
  94.     system("pause");
  95.      
  96.      
  97.      
  98. }

  99. int main()
  100. {

  101.   while(true)
  102.   {
  103.   
  104.     while(option == 0 or option ==1) //第一次或是買入
  105.     {
  106.       srand(time(NULL));
  107.       system("cls");
  108.       cout<<"「好事成雙」賽馬場   " << "第 " <<times << "局 "<<endl;
  109.       cout<<"------------------------------------------------------------------------| 終點"<<endl;
  110.       cout<<"◆"<<endl;
  111.       cout<<"★"<<endl;  
  112.       cout<<"▲"<<endl;
  113.       cout<<"●"<<endl;
  114.    
  115.       cout<<endl<<"可用餘額: "<<balance<<"元"<<endl<<endl;   
  116.       cout<<"(1)買入 (2)下注 (3)離開 請選擇: ";
  117.       cin>>option;
  118.       if(option==1)
  119.       {
  120.           cout<<"買入: ";
  121.           cin>>buyin;
  122.           balance+=buyin;           
  123.       }
  124.       else if(option == 2)
  125.       {
  126.          cout<<"下注: ";
  127.          cin>>bet;
  128.          if(balance > bet)
  129.          {
  130.             balance = balance - bet;
  131.             cout<<endl<<"(1)◆ (2)★ (3)▲ (4)●  請選擇: ";
  132.             cin>>player;
  133.             cout<<"比賽即將開始..."<<endl<<endl;   
  134.             Start();
  135.          }
  136.          else
  137.          {
  138.             cout << "餘額不足,無法購買" << endl;   
  139.             break;
  140.          }
  141.         
  142.       }
  143.       else if(option == 3)
  144.       {
  145.          break;
  146.       }
  147.       system("pause");
  148.       system("cls");
  149.     }
  150.   }

  151.     system("pause");
  152.     return 0;
  153.       
  154. }
複製代碼

返回列表