本帖最後由 葉桔良 於 2022-9-17 15:53 編輯
完成選項 (3)離開 的相對應程式碼
在離開時顯示戰果,譬如:
"沒輸沒贏!全身而退!"
"恭喜你!這次總共贏了100元!"
"不好意思!讓你損失了200元!"
- #include<iostream>
- #include<cstdlib>
- #include<ctime>
- using namespace std;
- int main()
- {
- int n=1, balance=0;
- int option, buyin, bet, player;
- re:
- system("cls");
- srand(time(NULL));
- int s[]={0,0,0,0};
- string p[]={"◆","★","▲","●"};
- int r=0;
- cout<<"「好事成雙」賽馬場 第 "<<n<<" 局"<<endl;
- cout<<"-------------------------------------------------------------------------| 終點"<<endl;
- for(int i=0; i<4; i++)
- cout<<p[i]<<endl;
- cout<<endl<<"可用餘額: "<<balance<<"元"<<endl<<endl;
- cout<<"(1)買入 (2)下注 (3)離開 請選擇: ";
- cin>>option;
- if(option==1)
- {
- cout<<"買入: ";
- cin>>buyin;
- if(buyin<=0)
- {
- cout<<"輸入錯誤!";
- _sleep(1500);
- goto re;
- }
- balance+=buyin;
- goto re;
- }
- else if(option==2)
- {
- cout<<"下注: ";
- cin>>bet;
- if(bet<=0)
- {
- cout<<"輸入錯誤!";
- _sleep(1500);
- goto re;
- }
- if(bet>balance)
- {
- cout<<"可用餘額不足,請先買入!";
- _sleep(1500);
- goto re;
- }
- cout<<endl<<"(1)◆ (2)★ (3)▲ (4)● 請選擇: ";
- cin>>player;
- cout<<"比賽即將開始..."<<endl<<endl;
- }
- else if(option==3)
- {
- goto end;
- }
- else
- {
- cout<<"輸入錯誤!";
- _sleep(1500);
- goto re;
- }
- system("pause");
- system("cls");
- while(s[r]<=73)
- {
- r=rand()%4; //0~3
- s[r]++;
- cout<<"比賽進行中"<<endl;
- cout<<"-------------------------------------------------------------------------| 終點"<<endl;
- for(int i=0; i<4; i++)
- {
- for(int j=0; j<s[i]; j++)
- cout<<" ";
- cout<<p[i]<<endl;
- }
- _sleep(25);
- system("cls");
- }
- cout<<"比賽結束! 由 "<<p[r]<<" 先馳得點!"<<endl;
- cout<<"-------------------------------------------------------------------------| 終點"<<endl;
- for(int i=0; i<4; i++)
- {
- for(int j=0; j<s[i]; j++)
- cout<<" ";
- cout<<p[i]<<endl;
- }
- if(player==r+1)
- {
- cout<<"贏了 "<<bet*3<<" 元!"<<endl;
- balance+=bet*3;
- }else
- {
- cout<<"損失 "<<bet<<" 元!"<<endl;
- balance-=bet;
- }
- system("pause");
- n++;
- goto re;
- end:
- cout<<endl<<"慢走!"<<endl;
- _sleep(1500);
- return 0;
- }
複製代碼 |