- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- int n=1, winner, balance=0, option, buyin, bet, player,w=0.;
- string l[]={"★","◆","●","▲"};
- srand(time(NULL));
- re:
- system("cls");
- int s[]={0,0,0,0};
- cout<<"「好事成雙」賽馬場 第 "<<n<<" 局"<<endl;
- cout<<"- - - - - - - - - - - 終點"<<endl;
- cout<<"★"<<endl;
- cout<<"◆"<<endl;
- cout<<"●"<<endl;
- cout<<"▲"<<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");
- while(true)
- {
- system("cls");
- int r=rand()%4;
- s[r]+=2;
- cout<<"比賽進行中"<<endl;
- cout<<"- - - - - - - - - - - 終點"<<endl;
- for(int i=0; i<=s[0]; i++)
- cout<<" ";
- cout<<"★"<<endl;
- for(int i=0; i<=s[1]; i++)
- cout<<" ";
- cout<<"◆"<<endl;
- for(int i=0; i<=s[2]; i++)
- cout<<" ";
- cout<<"●"<<endl;
- for(int i=0; i<=s[3]; i++)
- cout<<" ";
- cout<<"▲"<<endl;
- if(s[r]==46)
- {
- winner=r+1;
- break;
- }
- _sleep(60);
- }
- system("cls");
- cout<<"比賽結束! 由 "<<l[winner-1]<<" 選手先馳得點!"<<endl;
- cout<<"- - - - - - - - - - - 終點"<<endl;
- for(int i=0; i<=s[0]; i++)
- cout<<" ";
- cout<<"★"<<endl;
- for(int i=0; i<=s[1]; i++)
- cout<<" ";
- cout<<"◆"<<endl;
- for(int i=0; i<=s[2]; i++)
- cout<<" ";
- cout<<"●"<<endl;
- for(int i=0; i<=s[3]; i++)
- cout<<" ";
- cout<<"▲"<<endl;
- if(player==winner)
- {
- cout<<"增加 "<<bet*3<<"元"<<endl;
- balance+=bet*3;
- w+=bet*3;
- system("pause");
- goto re;
- }
- else
- {
- cout<<"損失 "<<bet<<"元"<<endl;
- balance-=bet;
- w-=bet;
- system("pause");
- goto re;
- }
- n++;
- system("pause");
- goto re;
- end:
- if(w==0)
- cout<<endl<<"沒輸沒贏! 全身而退!"<<endl;
- else if(w>0)
- cout<<endl<<"恭喜你! 這次總共贏了"<<w<<"元!"<<endl;
- else
- cout<<endl<<"不好意思! 讓你損失了"<<-w<<"元"<<endl;
- cout<<endl<<"謝謝光臨! 下次再來!"<<endl;
- system("pause");
- return 0;
- }
複製代碼 |