標題:
賽馬程式 (六)
[打印本頁]
作者:
陳曜誌
時間:
2025-5-2 10:30
標題:
賽馬程式 (六)
本帖最後由 陳曜誌 於 2025-5-2 18:33 編輯
1. 比對比賽結果與玩家下注,判斷玩家贏了錢還是輸了錢。
2. 對變數balance做加減,使可用餘額會隨著玩家輸贏而增減。
規則如下:
若最後勝出的選手與玩家下注相同,玩家贏得下注金3倍的錢。
反之,玩家損失下注金。
本帖隱藏的內容需要回復才可以瀏覽
作者:
楊炘樺
時間:
2025-5-2 18:04
本帖最後由 楊炘樺 於 2025-5-9 17:14 編輯
#include<bits/stdc++.h>
using namespace std;
string Players[6]={"◆","★","▲","●","▼","■"};
int balance=0;
int bet2=0;
void show(int L[],bool showbalance)
{
for(int i=0;i<39;i++)
cout<<"══";
cout<<"| 終點"<<endl;
for(int i=0;i<6;i++)
{
if(bet2==i+1)
cout<<"☆";
else
cout<<" ";
cout<<i+1<<'.';
for(int j=0;j<L[i];j++)
cout<<" ";
cout<<Players[i]<<endl;
}
for(int i=0;i<39;i++)
cout<<"══";
cout<<"| 終點"<<endl;
if(showbalance)
cout<<"\n\n可用餘額: "<<balance<<"元\n\n";
}
int main()
{
int Round=1;
int option, buyin;
int bet,bet3;
srand(time(NULL));
while(true)
{
int First;
int Location[6]={0,0,0,0,0,0};
bet=0;
bet2=0;
do
{
system("cls");
cout<<"「好事成雙」賽馬場 "<<"第"<<Round<<"局\n";
show(Location,true);
cout<<"(1)買入 (2)下注並比賽 (3)離開 請選擇: ";
cin>>option;
if(option==1)
{
cout<<"買入: ";
cin>>buyin;
if(buyin<1)
{
cout<<"輸入錯誤!\n";
_sleep(1500);
continue;
}
balance+=buyin;
}
else if(option==2)
{
cout<<"下注(1~65535) (0)取消: ";
cin>>bet3;
if(bet3==0)
continue;
else if(bet3>balance)
{
cout<<"可用餘額不足,請先買入!\n";
_sleep(1500);
continue;
}
if(bet3<1)
{
cout<<"輸入錯誤!\n";
_sleep(1500);
continue;
}
cout<<"你覺得誰會贏?(1~6) 賭 否則(其他) 取消 :";
cin>>bet2;
if(bet2>6 || bet2<1)
{
bet=0;
continue;
}
bet+=bet3;
balance-=bet3;
}
else if(option==3)
goto breakgame;
system("cls");
show(Location,true);
}while(option!=2);
system("cls");
while(true)
{
int prr=rand()%6;
int endnum=37;
cout<<"比賽進行中\n";
Location[prr]++;
show(Location,false);
_sleep(100);
system("cls");
First=prr;
if(Location[0]==endnum || Location[1]==endnum || Location[2]==endnum|| Location[3]==endnum || Location[4]==endnum|| Location[5]==endnum)
break;
}
cout<<"比賽結束! 由"<<Players[First]<<"先馳得點!"<<endl;
show(Location,true);
if(bet!=0)
{
cout<<"你下注" << Players[bet2-1] << "," << bet <<"元,";
if(bet2-1==First)
{
balance+=bet*3;
cout<<"你賭贏了!";
}
else
cout<<"你賭輸了!";
}
cout<<"\n\n\n";
system("pause");
system("cls");
Round++;
}
breakgame:
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2