本帖最後由 徐譽豈 於 2022-4-2 11:32 編輯
- #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 ; // 每匹馬前進的進度
- string words ="賽馬進行中";
- string name[4] = {"◆","★","▲","●"};
- int position =0;
- cout<<"日本東京競馬場<東京優駿>[2400m草地] 第"<<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");
- 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;
- }
複製代碼 |