返回列表 發帖
本帖最後由 王瑞喻 於 2019-5-9 23:47 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<time>
  4. using namespace std;
  5. int main()
  6. {
  7.     int n=1,money=0; //第n局
  8.     re:
  9.     int a=0,b=0,c=0,d=0,r,option,buyin,bet,horse; //r為亂數選出的馬,x為贏的馬
  10.     system("cls");
  11.     cout<<"賽~馬~"<<"第"<<n<<"局"<<endl;
  12.     cout<<"|起點|--------------------------------------------------------------|終點|"<<endl;
  13.     cout<<"★"<<endl;
  14.     cout<<"㊣"<<endl;
  15.     cout<<"▽"<<endl;
  16.     cout<<"◆"<<endl;
  17.     cout<<endl;
  18.     cout<<"可用餘額:"<<money<<"元"<<endl<<endl;
  19.     cout<<"(1)買入(2)下注(3)離開  請選擇: ";
  20.     cin>>option;
  21.     if(option==1)//買入
  22.     {
  23.         cout<<"買入: ";
  24.         cin>>buyin;
  25.         balance+=buyin; //money=money+buyin
  26.         goto re;
  27.     }else if(option==2)
  28.     {
  29.         cout<<"請下注: ";
  30.         cin>>bet;
  31.         if(bet>money)//下注金額大於餘額
  32.         {
  33.             cout<<"您餘額不足,請重新下注!"<<endl;                                
  34.             system("pause");
  35.             goto re;
  36.         }else if(bet>=0 && bet<=money)
  37.         {
  38.               money-=bet;//money=money-bet
  39.               cout<<"(1)★(2)㊣(3)▽(4)◆ 請選擇:";
  40.               cin>>horse;
  41.               cout<<"比賽即將開始!"<<endl<<endl;
  42.         }else
  43.         {
  44.             cout<<"您輸入錯誤!請重新下注!"<<endl;
  45.             system("pause");
  46.                         goro re;
  47.         }
  48.     }else //離開
  49.         {
  50.             goto end;  
  51.         }
  52.     system("pause");
  53.     system("cls");
  54.     srand(time(NULL));
  55.     while(a!=70 && b!=70 && c!=70 && d!=70)
  56.     {
  57.         cout<<"~賽馬進行中~"<<"第"<<n<<"局"<<endl;
  58.         cout<<"|起點|--------------------------------------------------------------|終點|"<<endl;        
  59.         r=rand()%4;
  60.         if(r==0)
  61.         {
  62.             a++;
  63.         }
  64.         if(r==1)
  65.         {
  66.             b++;
  67.         }
  68.         if(r==2)
  69.         {
  70.             c++;
  71.         }
  72.         if(r==3)
  73.         {
  74.             d++;
  75.         }
  76.         for(int i=0;i<=a;i++)
  77.         {
  78.             cout<<" ";
  79.         }
  80.             cout<<"★"<<endl;
  81.         for(int i=0;i<=b;i++)
  82.         {
  83.             cout<<" ";
  84.         }
  85.             cout<<"㊣"<<endl;
  86.         for(int i=0;i<=c;i++)
  87.         {
  88.             cout<<" ";
  89.         }
  90.             cout<<"▽"<<endl;
  91.         for(int i=0;i<=d;i++)
  92.         {
  93.             cout<<" ";
  94.         }
  95.             cout<<"◆"<<endl;
  96.         system("cls");
  97.     }
  98.    
  99.     if(a==70)
  100.     {
  101.         cout<<"~比賽結束~"<<"第"<<n<<"局"<<"由★先馳得點!"<<endl;
  102.     }
  103.     else if(b==70)
  104.     {
  105.         cout<<"~比賽結束~"<<"第"<<n<<"局"<<"由㊣先馳得點!"<<endl;
  106.     }
  107.     else if(c==70)
  108.     {
  109.         cout<<"~比賽結束~"<<"第"<<n<<"局"<<"由▽先馳得點!"<<endl;
  110.     }
  111.     else
  112.     {
  113.         cout<<"~比賽結束~"<<"第"<<n<<"局"<<"由◆先馳得點!"<<endl;
  114.     }
  115.    
  116.     cout<<"|起點|--------------------------------------------------------------|終點|"<<endl;
  117.     for(int i=0;i<=a;i++)
  118.         {
  119.             cout<<" ";
  120.         }
  121.             cout<<"★"<<endl;
  122.         for(int i=0;i<=b;i++)
  123.         {
  124.             cout<<" ";
  125.         }
  126.             cout<<"㊣"<<endl;
  127.         for(int i=0;i<=c;i++)
  128.         {
  129.             cout<<" ";
  130.         }
  131.             cout<<"▽"<<endl;
  132.         for(int i=0;i<=d;i++)
  133.         {
  134.             cout<<" ";
  135.         }
  136.             cout<<"◆"<<endl;
  137.         system("pause");
  138.         system("cls");
  139.         n++;
  140.         goto re;
  141.         end;
  142.     system("pause");
  143.     return 0;
  144. }
複製代碼

TOP

返回列表