標題:
賽馬程式 (四)
[打印本頁]
作者:
張翼安
時間:
2016-6-18 02:16
標題:
賽馬程式 (四)
1. 比對比賽結果與玩家下注, 判斷玩家贏了錢還是輸了錢.
2. 對變數balance做加減, 使可用餘額會隨著玩家輸贏而增減.
規則如下:
若最後勝出的選手與玩家下注相同, 玩家贏得下注金3倍的錢.
反之, 玩家損失下注金.
作者:
蔡季樺
時間:
2016-6-19 14:00
本帖最後由 蔡季樺 於 2016-6-25 07:42 編輯
.............
作者:
蔡季樺
時間:
2016-6-25 07:41
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int y=1;
int money=0,takeout=0;
int ctrl;
while(true)
{
int buy=0,bet=0,bh;
srand(time(NULL));
string horse[4]={"◆","★","▲","●"};
int x;
int distance[4]={0,0,0,0};
x=rand()%4;
cout<<"$$$「包你賺」賽馬場 $$$ 第"<<y<<"局 "<<endl;
cout<<"-----------------------------------------------------------------------|終點!"<<endl;
for(int i=0;i<=3;i++)
{
cout<<horse[i]<<endl;
}
cout<<"可用餘額:"<<money<<endl<<endl;
cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
cin>>ctrl;
if(ctrl==1)
{
cout<<"買入幾元:";
cin>>buy;
if(buy<1)
{
cout<<"不要惡搞!!!"<<endl;
system("pause");
system("cls");
continue;
}
money+=buy;
takeout-=buy;
system("cls");
continue;
}else if(ctrl==2)
{
cout<<"下注幾元:";
cin>>bet;
if(bet>money)
{
cout<<"錢不夠喔!!!"<<endl;
system("pause");
system("cls");
continue;
}
if(bet<1)
{
cout<<"你累了嗎???"<<endl;
system("pause");
system("cls");
continue;
}
money-=bet;
cout<<"(1)◆(2)★(3)▲(4)● 請選擇:";
cin>>bh;
if(bh<1 || bh>4)
{
cout<<"眼睛看到哪裡去了!沒有這匹馬!!!"<<endl;
money+=bet;
system("pause");
system("cls");
continue;
}
cout<<endl<<"比賽即將開始,";
bh-=1;
}else if(ctrl==3)
{
takeout+=money;
break;
}else
{
system("cls");
continue;
}
system("pause");
system("cls");
while(true)
{
system("cls");
if(distance[x]==70)
{
cout<<"比賽結束!!!由"<<horse[x]<<"先馳得點!"<<endl;
cout<<"-----------------------------------------------------------------------|終點!"<<endl;
for(int j=0;j<=3;j++)
{
for(int k=0;k<=distance[j];k++)
cout<<" ";
cout<<horse[j]<<endl;
}
if(bh==x)
{
money+=bet*3;
cout<<"賺"<<bet*3<<"元"<<endl;
}else
cout<<"賠"<<bet<<"元"<<endl;
system("pause");
system("cls");
break;
}
x=rand()%4;
cout<<"比賽進行中..."<<endl;
cout<<"-----------------------------------------------------------------------|終點!"<<endl;
x=rand()%4;
for(int l=0;l<=3;l++)
{
if(l==x)
{
distance[l]++;
for(int m=0;m<=distance[l];m++)
cout<<" ";
cout<<horse[l]<<endl;
}
else
{
for(int n=0;n<=distance[l];n++)
cout<<" ";
cout<<horse[l]<<endl;
}
}
_sleep(10);
}
y++;
system("cls");
}
if(takeout<0)
{
cout<<endl<<"哈哈!你賠了"<<takeout<<"元,活該!!!"<<endl;
}else if(takeout>0)
{
cout<<endl<<"「包你賺」賽馬場真的讓你賺了"<<takeout<<"元!!!"<<endl;
}else
{
cout<<endl<<"你不賺也不賠!真厲害!!!(喔,是嗎)"<<endl;
}
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2