- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- int n=1,f=0,win,money=0;
- re:
- int a=0,b=0,c=0,d=0,r,j,k,bet,horse,winner;
- system("cls");
- cout<<"「好事成雙」賽馬場 第"<<n<<"局"<<endl;
- cout<<"------------------------------------------------------------------------| 終點"<<endl;
- cout<<"◆"<<endl;
- cout<<"★"<<endl;
- cout<<"▲"<<endl;
- cout<<"●"<<endl;
- cout<<endl;
- cout<<"可用餘額: "<<f<<"元"<<endl;
- cout<<"(1)買入(2)下注(3)離開 請選擇: "<<endl;
- cin>>j;
- if(j==1)
- {
- cout<<"買入: ";
- cin>>k;
- f+=k;
- goto re;
- }else if(j==2)
- {
- cout<<"請下注";
- cin>>bet;
- if(bet>k)
- {
- cout<<"您餘額不足,請重新下注!"<<endl;
- system("pause");
- goto re;
- }else if(bet>=0 && bet<= f)
- {
-
- cout<<"(1)◆ (2)★ (3)▲(4)● 請選擇:";
- cin>>horse;
- 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) //判斷四隻馬只要有一隻到終點就跳離while
- {
- cout<<"賽馬進行中"<<endl;
- cout<<"------------------------------------------------------------------------| 終點"<<endl;
- r = rand()%4+1; //產生1~4亂數 隨機挑馬1~4其中一隻
- if(r==1)
- a++;
- if(r==2)
- b++;
- if(r==3)
- c++;
- if(r==4)
- d++;
-
-
- for(int i=0;i<=a;i++) //第一匹馬前進
- {
- cout<<" ";
- }
- cout<<"◆"<<endl;
- for(int i=0;i<=b;i++) //第二匹馬前進
- {
- cout<<" ";
- }
- cout<<"★"<<endl;
- for(int i=0;i<=c;i++) //第三匹馬前進
- {
- cout<<" ";
- }
- cout<<"▲"<<endl;
- for(int i=0;i<=d;i++) //第四匹馬前進
- {
- cout<<" ";
- }
- cout<<"●"<<endl;
- system("cls"); //清空畫面
- }
-
-
- cout<<"賽馬結束!";
- if(a==70)
- {
- cout<<"由◆先馳得點!"<<endl;
- }else if(b==70)
- {
- cout<<"由★先馳得點!"<<endl;
- }else if(c==70)
- {
- cout<<"由▲先馳得點!"<<endl;
- }else
- {
- cout<<"由●先馳得點!"<<endl;
- }
-
-
-
-
- cout<<"------------------------------------------------------------------------| 終點"<<endl;
- for(int i=0;i<=a;i++) //第一匹馬最後的位子
- {
- cout<<" ";
- }
- cout<<"◆"<<endl;
- for(int i=0;i<=b;i++) //第二匹馬最後的位子
- {
- cout<<" ";
- }
- cout<<"★"<<endl;
- for(int i=0;i<=c;i++) //第三匹馬最後的位子
- {
- cout<<" ";
- }
- cout<<"▲"<<endl;
- for(int i=0;i<=d;i++) //第四匹馬最後的位子
- {
- cout<<" ";
- }
- cout<<"●"<<endl;
- if(horse==winner)
- {
- cout<<"贏了"<<bet*3<<"元!"<<endl;
- f+=bet*3;
- money=bet*3;
- }else
- {
-
- f-=bet;
- money-=bet;
- cout<<"損失"<<bet<<"元"<<endl;
- }
- n++;
- system("pause");
- system("cls");
- goto re;
- end:
- if(money==0)
- {
- cout<<"沒輸沒贏!全身而退"<<endl;
- }else if(money>0)
- {
- cout<<"恭喜你! 贏了"<<money<<"元"<<endl;
- }else
- {
- cout<<"不好意思,讓你輸了"<<-money<<"元"<<endl;
- }
- system("pause");
- return 0;
- }
複製代碼 |