- #include<iostream>
- #include<cstdlib>
- #include<ctime>
- using namespace std;
- int main()
- {
- // 開局第一場
- int n =1,blance=0;
- re:
- system("cls");
- int a=0,b=0,c=0,d=0,r, option, buyin =0,bet,horse,winer ; // 每匹馬前進的進度
-
- // 當有任一匹跑到終點70 的時候就跳離迴圈
- string words ="賽馬進行中";
- // 代表馬的名子
- string name[4] = {"◆","★","▲","●"};
-
- // 宣告一個暫存的變數
- int position =0;
- cout<<"「好事成雙」賽馬場 第"<<n<<"局"<<endl;
- cout<<"------------------------------------------------------------------------| 終點"<<endl;
- cout<<"◆"<<endl;
- cout<<"★"<<endl;
- cout<<"▲"<<endl;
- cout<<"●"<<endl;
- cout<<endl;
- cout<<"可用餘額:"<<blance<<"元"<<endl;
- cout<<endl;
- cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
- cin>>option;
-
- // 如果買入 把錢加入餘額
- if(option==1)
- {
- cout<<"買入:";
- cin>>buyin;
- blance += buyin;
- goto re;
- }else if(option==2)
- {
- cout<<"請下注:";
- cin>>bet;
- if(bet > blance)
- {
- cout<<"您餘額不足,請重新下注!"<<endl;
- system("pause");
- goto re;
- }else if(bet >0 && bet<=blance)
- {
- cout<<"(1)◆ (2)★ (3)▲(4)●請選擇:";
- cin>>horse;
- blance -= bet;
- cout<<"即將開始賽馬!"<<endl;
- }else
- {
- cout<<"您輸入錯誤,請重新下注!"<<endl;
- system("pause");
- goto re;
- }
-
- }else
- {
- // 離開
- goto end;
- }
-
- system("pause"); // 按下enter 才開始
- system("cls"); // 清空畫面
- srand(time(NULL)); // 撒種子亂數
-
- while(a<=70 && b<=70 && c<=70 && d<=70)
- {
- cout<<words<<endl;
- cout<<"------------------------------------------------------------------------| 終點"<<endl;
- // 隨機挑一匹馬
- r = rand()%4+1;
- // 每匹馬 跑的進度
- switch(r)
- {
- case 1:
- a++;
- break;
- case 2:
- b++;
- break;
- case 3:
- c++;
- break;
- case 4:
- d++;
- break;
- }
-
- // 要把每匹馬的進度給輸出
- // 第一匹馬
- 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==70 || b==70 || c==70 || d==70)
- {
- if(a==70)
- {
- position = 0;
- winer = 1;
- }
- if(b==70)
- {
- position =1;
- winer = 2;
- }
- if(c==70)
- {
- position =2;
- winer = 3;
- }
- if(d==70)
- {
- position =3;
- winer =4;
- }
-
- words = "比賽結束!由"+name[position]+"先馳得點!";
- }
- if(a==71 || b==71 || c==71 || d==71)
- {
- }else{
- system("cls");
- }
-
- }
-
- if(horse == winer)
- {
- blance = blance + bet*3;
- cout<<"您贏了"<<bet*3<<"元"<<endl;
- }else
- {
- cout<<"損失"<<bet<<"元"<<endl;
- }
-
-
- n++;
- system("pause");
- goto re;
- end:
- system("pause");
- return 0;
- }
複製代碼 |