標題:
賽馬程式 (六)
[打印本頁]
作者:
方浩葦
時間:
2024-7-13 07:28
標題:
賽馬程式 (六)
1. 比對比賽結果與玩家下注,判斷玩家贏了錢還是輸了錢。
2. 對變數balance做加減,使可用餘額會隨著玩家輸贏而增減。
規則如下:
若最後勝出的選手與玩家下注相同,玩家贏得下注金3倍的錢。
反之,玩家損失下注金。
本帖隱藏的內容需要回復才可以瀏覽
作者:
邱博宥
時間:
2024-8-18 18:20
#include<iostream>
#include<ctime>
using namespace std;
int main()
{
int e=0;
int b,d,g,h,money=0;
srand(time(NULL));
re:
e++;
start:
system("cls");
int a[4]= {0,0,0,0};
string j[4]= {"△","▲","☆","★"};
cout<<"賽馬場"<<"第"<<e<<"局"<<endl;
cout<<"---------------------------------------------------------|終點"<<endl;//57
cout<<"△"<<endl;
cout<<"▲"<<endl;
cout<<"☆"<<endl;
cout<<"★"<<endl;
cout<<endl<<endl<<"你的餘額:"<<money<<endl;
cout<<"[1]買入[2]下注[3]離開:";
cin>>d;
if(d==1)
{
cout<<"你要買入多少錢?:";
cin>>b;
if(b<0)
{
cout<<"輸入錯誤";
_sleep(1500);
goto start;
}
money+=b;
goto start;
}
else if(d==2)
{
cout<<"下注:";
cin>>g;
if(g>money)
{
cout<<"輸入錯誤";
_sleep(1500);
goto start;
}
if(g<=0)
{
cout<<"輸入錯誤";
_sleep(1500);
goto start;
}
cout<<"請選擇1△ 2▲ 3☆ 4★: ";
cin>>h;
}
else if(d==3)
goto end;
else
{
cout<<"輸入錯誤";
_sleep(1500);
goto start;
}
system("pause");
system("cls");
while(true)
{
system("cls");
int c=rand()%4;
cout<<"賽馬場"<<"第"<<e<<"局"<<endl;
cout<<"---------------------------------------------------------|終點"<<endl;
a[c]+=3;
for(int m=1; m<=a[0]; m++)
cout<<" ";
cout<<"△"<<endl;
for(int m=1; m<=a[1]; m++)
cout<<" ";
cout<<"▲"<<endl;
for(int m=1; m<=a[2]; m++)
cout<<" ";
cout<<"☆"<<endl;
for(int m=1; m<=a[3]; m++)
cout<<" ";
cout<<"★"<<endl;
if(a[c]>=57)
{
system("cls");
cout<<"賽馬場"<<"第"<<e<<"局"<<"由"<<j[c]<<"先馳得點"<<endl;
cout<<"---------------------------------------------------------|終點"<<endl;
for(int m=1; m<=a[0]; m++)
cout<<" ";
cout<<"△"<<endl;
for(int m=1; m<=a[1]; m++)
cout<<" ";
cout<<"▲"<<endl;
for(int m=1; m<=a[2]; m++)
cout<<" ";
cout<<"☆"<<endl;
for(int m=1; m<=a[3]; m++)
cout<<" ";
cout<<"★"<<endl;
if(c==h-1)
{
cout<<endl<<"你贏得了"<<g<<"元"<<endl;
money+=g;
}
else
{
cout<<endl<<"你損失了"<<g<<"元"<<endl;
money-=g;
}
break;
}
_sleep(50);
}
system("pause");
system("cls");
goto re;
end:
cout<<"遊戲結束";
return 0;
}
複製代碼
作者:
鄭豊翰
時間:
2024-9-7 11:02
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int s[]={0,0,0,0};
string k[]={"◆","★","▲","●"};
int o, r, balance=0, option, buyin, bet, contestant;
re:
o++;
be:
system("cls");
srand(time(NULL));
cout<<"「好事成雙」賽馬場 第"<<o<<"局"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl<<endl;
option=0;
cout<<"可用餘額: "<<balance<<"元"<<endl<<endl;
cout<<"<1>買入 <2>下注 <3>離開 請選擇: ";
cin>>option;
if(option==1){
cout<<"買入: ";
cin>>buyin;
if(buyin<=0){
cout<<"輸入錯誤";
_sleep(1500);
goto be;
}
else{
balance+=buyin;
goto be;}
}
else if(option==2){
cout<<"下注: ";
cin>>bet;
if(bet > balance){
cout<<"餘額不足!!請買入"<<endl;
_sleep(1500);
goto be;
}
else if (bet>0 && bet<=balance){
cout<<"<1>◆ <2>★ <3>▲ <4>● 請選擇: ";
cin>>contestant;
}
else{
cout<<"輸入錯誤";
_sleep(1500);
goto be;
}
}
else if(option==3){
goto end;
}
else{
cout<<"輸入錯誤"<<endl;
_sleep(1500);
goto be;
}
system("pause");
while(true)
{
system("cls");
r=rand()%4;
s[r]++;
cout<<"比賽進行中 第"<<o<<"局"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<=s[0]; i++)
cout<<" ";
cout<<"◆"<<endl;
for(int i=0; i<=s[1]; i++)
cout<<" ";
cout<<"★"<<endl;
for(int i=0; i<=s[2]; i++)
cout<<" ";
cout<<"▲"<<endl;
for(int i=0; i<=s[3]; i++)
cout<<" ";
cout<<"●"<<endl;
if(s[r]==73)
break;
_sleep(50);
}
system("cls");
cout<<"比賽結束 由"<<k[r]<<"獲勝"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<=s[0]; i++)
cout<<" ";
cout<<"◆"<<endl;
for(int i=0; i<=s[1]; i++)
cout<<" ";
cout<<"★"<<endl;
for(int i=0; i<=s[2]; i++)
cout<<" ";
cout<<"▲"<<endl;
for(int i=0; i<=s[3]; i++)
cout<<" ";
cout<<"●"<<endl;
if(contestant - 1 == r){
cout<<"你獲得"<<bet*3<<"元"<<endl;
balance+=(bet*3);
}
else{
cout<<"你輸了"<<bet<<"元"<<endl;
balance-=bet;
}
cout<<"可用餘額: "<<balance<<"元"<<endl<<endl;
cout<<"<1>買入 <2>下注 <3>離開 請選擇: ";
cin>>option;
system("pause");
goto re;
end:
cout<<"Bye Bye";
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2