Board logo

標題: 賽馬程式 (六) [打印本頁]

作者: 陳曜誌    時間: 2025-5-2 10:30     標題: 賽馬程式 (六)

本帖最後由 陳曜誌 於 2025-5-2 18:33 編輯

1. 比對比賽結果與玩家下注,判斷玩家贏了錢還是輸了錢。
2. 對變數balance做加減,使可用餘額會隨著玩家輸贏而增減。

規則如下:
若最後勝出的選手與玩家下注相同,玩家贏得下注金3倍的錢。
反之,玩家損失下注金。







本帖隱藏的內容需要回復才可以瀏覽

作者: 楊炘樺    時間: 2025-5-2 18:04

本帖最後由 楊炘樺 於 2025-5-9 17:14 編輯
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. string Players[6]={"◆","★","▲","●","▼","■"};
  4. int balance=0;
  5. int bet2=0;
  6. void show(int L[],bool showbalance)
  7. {
  8.     for(int i=0;i<39;i++)
  9.         cout<<"══";
  10.     cout<<"| 終點"<<endl;
  11.     for(int i=0;i<6;i++)
  12.     {
  13.         if(bet2==i+1)
  14.             cout<<"☆";
  15.         else
  16.             cout<<"  ";
  17.         cout<<i+1<<'.';
  18.         for(int j=0;j<L[i];j++)
  19.             cout<<"  ";
  20.         cout<<Players[i]<<endl;
  21.     }
  22.     for(int i=0;i<39;i++)
  23.         cout<<"══";
  24.     cout<<"| 終點"<<endl;
  25.     if(showbalance)
  26.         cout<<"\n\n可用餘額: "<<balance<<"元\n\n";
  27. }
  28. int main()
  29. {
  30.     int Round=1;
  31.     int option, buyin;
  32.     int bet,bet3;
  33.     srand(time(NULL));
  34.     while(true)
  35.     {
  36.         int First;
  37.         int Location[6]={0,0,0,0,0,0};
  38.         bet=0;
  39.         bet2=0;
  40.         do
  41.         {
  42.             system("cls");
  43.             cout<<"「好事成雙」賽馬場 "<<"第"<<Round<<"局\n";
  44.             show(Location,true);
  45.             cout<<"(1)買入 (2)下注並比賽 (3)離開 請選擇: ";
  46.             cin>>option;
  47.             if(option==1)
  48.             {
  49.                 cout<<"買入: ";
  50.                 cin>>buyin;
  51.                 if(buyin<1)
  52.                 {
  53.                     cout<<"輸入錯誤!\n";
  54.                     _sleep(1500);
  55.                     continue;
  56.                 }
  57.                 balance+=buyin;
  58.             }
  59.             else if(option==2)
  60.             {
  61.                 cout<<"下注(1~65535) (0)取消: ";
  62.                 cin>>bet3;
  63.                 if(bet3==0)
  64.                      continue;
  65.                 else if(bet3>balance)
  66.                 {
  67.                     cout<<"可用餘額不足,請先買入!\n";
  68.                     _sleep(1500);
  69.                     continue;
  70.                 }
  71.                 if(bet3<1)
  72.                 {
  73.                     cout<<"輸入錯誤!\n";
  74.                     _sleep(1500);
  75.                     continue;
  76.                 }
  77.                 cout<<"你覺得誰會贏?(1~6) 賭 否則(其他) 取消 :";
  78.                 cin>>bet2;
  79.                 if(bet2>6 || bet2<1)
  80.                 {
  81.                     bet=0;
  82.                     continue;
  83.                 }
  84.                 bet+=bet3;
  85.                 balance-=bet3;
  86.             }
  87.             else if(option==3)
  88.                 goto breakgame;
  89.                 system("cls");
  90.             show(Location,true);
  91.         }while(option!=2);
  92.         system("cls");
  93.         while(true)
  94.         {
  95.             int prr=rand()%6;
  96.             int endnum=37;
  97.             cout<<"比賽進行中\n";
  98.             Location[prr]++;
  99.             show(Location,false);
  100.             _sleep(100);
  101.             system("cls");
  102.             First=prr;
  103.             if(Location[0]==endnum || Location[1]==endnum || Location[2]==endnum|| Location[3]==endnum || Location[4]==endnum|| Location[5]==endnum)
  104.                 break;
  105.         }
  106.         cout<<"比賽結束! 由"<<Players[First]<<"先馳得點!"<<endl;
  107.         show(Location,true);
  108.         if(bet!=0)
  109.         {
  110.             cout<<"你下注" << Players[bet2-1] << "," << bet <<"元,";
  111.             if(bet2-1==First)
  112.             {
  113.                balance+=bet*3;
  114.                cout<<"你賭贏了!";
  115.             }
  116.             else
  117.                 cout<<"你賭輸了!";
  118.         }
  119.         cout<<"\n\n\n";
  120.         system("pause");
  121.         system("cls");
  122.         Round++;
  123.     }
  124.     breakgame:
  125.     return 0;
  126. }
複製代碼





歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/) Powered by Discuz! 7.2