- #include<iostream>
- #include<cstdlib>
- #include<ctime>
- using namespace std;
- int main()
- {
- int a=1, win, x=0, y, z, b, c;
- srand(time(NULL));
- re:
- system("cls");
- int s[]={0,0,0,0};
- cout<<"「好事成雙」賽馬場! 第 "<<a<<" 局"<<endl;
- cout<<"-------------------------------------------------------------------------| 終點"<<endl;
- cout<<"1"<<endl;
- cout<<"2"<<endl;
- cout<<"3"<<endl;
- cout<<"4"<<endl;
- cout<<endl<<"可用餘額: "<<x<<" 元"<<endl<<endl;
- cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
- cin>>y;
- if(y==1)
- {
- cout<<"買入: ";
- cin>>z;
- if(z<=0)
- {
- cout<<"輸入錯誤!";
- _sleep(1500);
- goto re;
- }
- x+=z;
- goto re;
- }else if(y==2)
- {
- cout<<"下注: ";
- cin>>b;
- if(b<=0)
- {
- cout<<"輸入錯誤!";
- _sleep(1500);
- goto re;
- }
- if(b>x)
- {
- cout<<"可用餘額不足,請先買入!";
- _sleep(1500);
- goto re;
- }
- cout<<"(1)1 (2)2 (3)3 (4)4 請選擇: ";
- cin>>c;
- cout<<"比賽即將開始..."<<endl<<endl;
- }else if(y==3)
- {
- goto end;
- }else
- {
- cout<<"輸入錯誤!";
- _sleep(1500);
- goto re;
- }
- system("pause");
- while(true)
- {
- system("cls");
- int r=rand()%4;
- s[r]++;
- cout<<"比賽進行中"<<endl;
- cout<<"-------------------------------------------------------------------------| 終點"<<endl;
- for(int i=0; i<=s[0]; i++)
- cout<<" ";
- cout<<"1"<<endl;
- for(int i=0; i<=s[1]; i++)
- cout<<" ";
- cout<<"2"<<endl;
- for(int i=0; i<=s[2]; i++)
- cout<<" ";
- cout<<"3"<<endl;
- for(int i=0; i<=s[3]; i++)
- cout<<" ";
- cout<<"4"<<endl;
- if(s[r]==73)
- {
- win=r+1;
- break;
- }
- _sleep(50);
- }
- system("cls");
- cout<<"比賽結束! 由 "<<win<<" 先持得點!"<<endl;
- cout<<"-------------------------------------------------------------------------| 終點"<<endl;
- for(int i=0; i<=s[0]; i++)
- cout<<" ";
- cout<<"1"<<endl;
- for(int i=0; i<=s[1]; i++)
- cout<<" ";
- cout<<"2"<<endl;
- for(int i=0; i<=s[2]; i++)
- cout<<" ";
- cout<<"3"<<endl;
- for(int i=0; i<=s[3]; i++)
- cout<<" ";
- cout<<"4"<<endl;
- if(c==win)
- {
- cout<<"贏得 "<<b*3<<"元"<<endl;
- x+=b*3;
- }else
- {
- cout<<"損失 "<<b<<" 元"<<endl;
- x-=b;
- }
- cout<<endl<<"可用餘額: "<<x<<" 元"<<endl<<endl;
-
- system("pause");
- a++;
- goto re;
- end:
- cout<<endl<<"慢走!"<<endl;
- _sleep(1500);
- return 0;
- }
複製代碼 |