- #include<iostream>
- #include<cstdlib>
- #include<ctime>
- using namespace std;
- int main()
- {
- int t=1,z=0,money=0;
- re:
- system("cls");
- int a=0,b=0,c=0,d=0,r,tmp=0,o,buy=0,bet,horse,winer;
- string words ="賽馬進行中";
- string name[4] = {"◆","★","▲","●"};
- cout<<"「好事成雙」賽馬場"<<"第"<<t<<"局"<<endl;
- cout<<"------------------------------------------------------------------------| 終點"<<endl;
- cout<<"◆"<<endl;
- cout<<"★"<<endl;
- cout<<"▲"<<endl;
- cout<<"●"<<endl<<endl;
- cout<<"可用餘額:"<<z<<"元"<<endl<<endl;
- cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
- cin>>o;
- if(o==1)
- {
- cout<<"買入:";
- cin>>buy;
- z += buy;
- goto re;
- }else if(o==2)
- {
- cout<<"請下注:";
- cin>>bet;
- if(bet > z)
- {
- cout<<"您餘額不足,請重新下注!"<<endl;
- }else if(bet >0 && bet<=z)
- {
- cout<<"(1)◆ (2)★ (3)▲(4)●請選擇:";
- cin>>horse;
- z -= bet;
- cout<<"即將開始賽馬!"<<endl;
- }else
- {
- cout<<"您輸入錯誤,請重新下注!"<<endl;
- system("pause");
- goto re;
- }
- }else
- {
- goto end;
- }
- system("pause");
- system("cls");
- srand(time(NULL));
- while(a<70 && b<70 && c<70 && d<70)
- {
- r = rand()%4+1;
- switch(r)
- {
- case 1:
- a++;
- break;
- case 2:
- b++;
- break;
- case 3:
- c++;
- break;
- case 4:
- d++;
- }
- if(a==70 || b==70 || c==70 || d==70)
- {
- if(a==70)
- {
- tmp = 0;
- winer = 1;
- }
- if(b==70)
- {
- tmp = 1;
- winer = 2;
- }
- if(c==70)
- {
- tmp = 2;
- winer = 3;
- }
- if(d==70)
- {
- tmp =3;
- winer = 4;
- }
- words = "比賽結束!由"+name[tmp]+"先馳得點!";;
- }
- cout<<words<<endl;
- cout<<"------------------------------------------------------------------------| 終點"<<endl;
- for(int i=0;i<=a;i++)
- {
- cout<<" ";
- }
- cout<<name[0]<<endl;
- for(int i=0;i<=b;i++)
- {
- cout<<" ";
- }
- cout<<name[1]<<endl;
- for(int i=0;i<=c;i++)
- {
- cout<<" ";
- }
- cout<<name[2]<<endl;
- for(int i=0;i<=d;i++)
- {
- cout<<" ";
- }
- cout<<name[3]<<endl;
- if(a<=69 && b<=69 && c<=69 && d<=69)
- {
- system("cls");
- }
- }
- if(horse == winer)
- {
- z = z + bet*3;
- cout<<"您贏了"<<bet*3<<"元"<<endl;
- money = money + bet*3;
- }else
- {
- cout<<"損失"<<bet<<"元"<<endl;
- money = money - bet;
- }
- system("pause");
- t++;
- goto re;
- end:
- if(money ==0 )
- {
- cout<<"沒輸沒贏! 全身而退!"<<endl;
- }else if( money > 0)
- {
- cout<<"恭喜你! 這次總共贏了"<<money<<"元"<<endl;
- }else
- {
- cout<<"不好意思! 讓你損失了"<<-money<<"元"<<endl;
- }
- system("pause");
- return 0;
- }
複製代碼 |