- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- int n=1, money=0, total=0;
- re:
- int a=0, b=0, c=0, d=0, r, option, buyin, bet, winner;
- system("cls");
- cout<<"+++好事成雙->賽馬場+++ 第"<<n<<"局"<<endl;
- cout<<"-------------------------------------------|終點"<<endl;
- cout<<"◆"<<endl;
- cout<<"★"<<endl;
- cout<<"▲"<<endl;
- cout<<"●"<<endl;
- cout<<endl;
- cout<<"可用餘額:"<<money<<"元"<<endl<<endl;
- cout<<"(1)買入 (2)下注 (3)離開 請選擇"<<endl;
- cin>>option;
- if(option==1)
- {
- cout<<"買入:"<<endl;
- cin>>buyin;
- money+=buyin;
- goto re;
- }
- else if(option==2)
- {
- if(money==0)
- {
- cout<<"可用餘額不足!請先買入!!"<<endl;
- system("pause");
- goto re;
- }
- cout<<"下注:";
- cin>>bet;
- if(bet>money)
- {
- cout<<"可用餘額不足!請先買入!!"<<endl;
- system("pause");
- goto re;
- }
- else
- {
- cout<<"(1)◆(2)★(3)▲(4)● 請選擇:"<<endl;
- cin>>option;
- cout<<"比賽即將開始....."<<endl<<endl;
- system("pause");
- }
- }
- else if(option==3)
- {
- goto end;
- }
- else
- {
- cout<<"輸入錯誤"<<endl;
- system("pause");
- goto re;
- }
- system("pause");
- system("cls");
- srand(time(NULL));
-
- while(a!=20 && b!=20 && c!=20 && d!=20)
- {
- cout<<"賽馬進行中..."<<endl;
- cout<<"-------------------------------------------|終點"<<endl;
- r = rand()%4+1;
- 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;
- a++;
- for(int i=0;i<=b;i++)
- cout<<" ";
- cout<<"★"<<endl;
- b++;
- for(int i=0;i<=c;i++)
- cout<<" ";
- cout<<"▲"<<endl;
- c++;
- for(int i=0;i<=d;i++)
- cout<<" ";
- cout<<"●"<<endl;
- d++;
- system("cls");
-
- }
- cout<<"賽馬結束...!由 ";
- if(a==20)
- {
- cout<<"◆";
- winner = 1;
- }
- else if(b==20)
- {
- cout<<"★";
- winner = 2;
- }
- else if(c==20)
- {
- cout<<"▲";
- winner = 3;
- }
- else
- {
- cout<<"●";
- winner = 4;
- }
- cout<<"先抵達終點!"<<endl;
- cout<<"-------------------------------------------|終點"<<endl;
- for(int i=0;i<=a;i++)
- cout<<" ";
- cout<<"◆"<<endl;
- a++;
- for(int i=0;i<=b;i++)
- cout<<" ";
- cout<<"★"<<endl;
- b++;
- for(int i=0;i<=c;i++)
- cout<<" ";
- cout<<"▲"<<endl;
- c++;
- for(int i=0;i<=d;i++)
- cout<<" ";
- cout<<"●"<<endl;
- d++;
- if(option==winner)
- {
- cout<<"贏了"<<bet*3<<"元!"<<endl;
- money+=bet*3;
- total+=bet*3;
- }else
- {
- cout<<"損失"<<bet<<"元!"<<endl;
- money-=bet;
- total-=bet;
- }
- system("pause");
- n++;
- goto re;
- end:
- if(total==0)
- {
- cout<<"沒輸沒贏!"<<endl;
- }
- else if(total>0)
- {
- cout<<"恭喜!這次共贏了:"<<total<<"元"<<endl;
- }
- else
- {
- cout<<"可惜!你損失了:"<<total<<"元"<<endl;
- }
- cout<<"謝謝光臨!!!下次再來~~~"<<endl;
- system("pause");
- return 0;
- }
複製代碼 |