標題:
賽馬程式 (四)
[打印本頁]
作者:
鄭繼威
時間:
2023-7-7 20:58
標題:
賽馬程式 (四)
加入首頁選單, 新增
買入
(儲值)
的功能, 執行畫面如下:
(1)買入
(2)下注 (3)離開 請選擇:
在使用者輸入數值後, 畫面更新如下:
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int round=1; //局數
int balance=0; //餘額
int option; //選項
int buy; //儲值金額
re:
system("cls");
srand(time(NULL));
int s[]={0,0,0,0}; //存放進度用的
string p[]={"◆","★","▲","●"}; //存放馬用的
int r=0;
cout<<"「好事成雙」賽馬場 第"<<round<<"局"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<4; i++)
cout<<p[i]<<endl; //把馬印出來
cout<<endl<<"可用餘額: "<<balance<<"元"<<endl<<endl;
cout<<"(1)買入 (2)下注 (3)離開 請選擇: ";
cin>>option;
//輸入等於1執行買入(儲值)
if(option==1){
//買入
cout<<"買入: ";
cin>>buy;
balance=balance+buy; //儲值
goto re;
}
system("pause");
system("cls"); //清空畫面
while(s[r]<=73) //開始賽馬
{
r=rand()%4; //0~3 (抽馬)
s[r]++; //看電腦抽到哪隻馬就+1
cout<<"比賽進行中"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<4; i++)
{
for(int j=0; j<s[i]; j++)
cout<<" "; //印空格(看進度是多少就印多少空格)
cout<<p[i]<<endl; //把馬印出來
}
_sleep(50);
system("cls");
}
cout<<"比賽結束! 由 "<<p[r]<<" 先馳得點!"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<4; i++)
{
for(int j=0; j<s[i]; j++)
cout<<" ";
cout<<p[i]<<endl;
}
system("pause");
round++; //局數+1
goto re;
return 0;
}
複製代碼
作者:
蔡沛倢
時間:
2023-7-14 19:46
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int f=0;
int d=1;
re:
system("cls");
int a[]={0,0,0,0};
string e[]={"◆","★","▲","●"};
srand(time(NULL));
int b=0;
cout<<"****賽馬場-第"<<d<<"場****"<<endl;
cout<<"-------------------------------------------------------------------------|終點線"<<endl;
for(int i=0;i<=3;i++)
{
cout<<e[i]<<endl;
}
cout<<endl<<"可用餘額:"<<f<<endl<<endl;
cout<<"(1)儲值 (2)下注 (3)離開 請選擇:";
int g;
cin>>g;
if(g==1)
{
cout<<"你要儲值多少錢?";
int h;
cin>>h;
f=f+h;
goto re;
}
system("pause");
system("cls");
while(true)
{
b=rand()%4;
a[b]++;
cout<<"比賽進行中"<<endl;
cout<<"-------------------------------------------------------------------------|終點線"<<endl;
for(int i=0;i<4;i++)
{
for(int j=0;j<=a[i];j++)
{
cout<<" ";
}
cout<<e[i]<<endl;
}
if(a[b]==73)
{
break;
}
_sleep(50);
system("cls");
}
cout<<"!比賽結束 由"<<e[b]<<"勝利!"<<endl;
cout<<"-------------------------------------------------------------------------|終點線"<<endl;
for(int i=0;i<4;i++)
{
for(int j=0;j<=a[i];j++)
{
cout<<" ";
}
cout<<e[i]<<endl;
}
system("pause");
d++;
goto re;
return 0;
}
複製代碼
作者:
何權晉
時間:
2023-7-14 19:48
#include<iostream>
#include<ctime>
using namespace std;
int main()
{
int r=1;
int op;
int pur;
int bal=0;
re:
int s[]={0,0,0,0};
string h[]={"◆","★","▲","●"};
srand(time(NULL));
cout<<endl<<endl;
cout<<"Round "<<r<<endl;
cout<<"★★★The Wetherby Racecourse★★★"<<endl;
cout<<"-------------------------------------------------------------------------|Finish"<<endl;
for(int i=0;i<=3;i++)
cout<<h[i]<<endl;
cout<<endl<<"Balance: $"<<bal<<endl<<endl;
cout<<"(1)Deposit (2) Place Bid (3)Return to main menu"<<endl;
cout<<"Enter option: ";
cin>>op;
if(op==1){
cout<<"Deposit Amount: ";
cin>>pur;
bal=bal+pur;
goto re;
}
system("pause");
while(true)
{
system("cls");
int o=rand()%4;
s[o]++;
cout<<"Round "<<r<<endl;
cout<<"★★★The Wetherby Racecourse★★★"<<endl;
cout<<"-------------------------------------------------------------------------|Finish"<<endl;
for(int i=0; i<4; i++)
{
for(int j=0; j<s[i]; j++)
{
cout<<" ";
}
cout<<h[i]<<endl;
}
if (s[o]==73)
break;
_sleep(50);
}
system("cls");
cout<<"Race Finished"<<endl;
cout<<"Round "<<r<<endl;
cout<<"★★★The Wetherby Racecourse★★★"<<endl;
cout<<"-------------------------------------------------------------------------|Finish"<<endl;
for(int i=0; i<4; i++)
{
for(int j=0; j<s[i]; j++)
{
cout<<" ";
}
cout<<h[i]<<endl;
}
for(int i=0;i<=3;i++)
{
if(s[i]==73)
{
cout<<h[i]<<" Won The Race"<<endl;
}
}
r++;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
黃子豪
時間:
2023-7-14 19:49
#include<iostream>
#include<ctime>
using namespace std;
int main()
{
int balance=0;
int round=1;
re:
system("cls");
int s[]={0,0,0,0};
string p[]={"◆", "★", "▲", "●"};
int win;
srand(time(NULL));
cout<<"「好事成雙」賽馬場 第"<<round<<"局"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<4; i++)
{
cout<<p[i]<<endl;
}
int option;
cout<<endl<<"可用餘額: "<<balance<<"元\n\n(1)儲值 (2)下注 (3)離開 請選擇: ";
cin>>option;
if(option==1){
cout<<"儲多少: ";
int buy;
cin>>buy;
balance+=buy;
goto re;
}
system("pause");
while(true)
{
system("cls");
int r=rand()%4;
s[r]++;
cout<<"比賽進行中"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int j=0; j<4; j++){
for(int i=0; i<=s[j]; i++){
cout<<" ";
}
cout<<p[j]<<endl;
}
if(s[r]==73){
win=r;
break;
}
_sleep(5);
}
cout<<"比賽結束! 由 "<<p[win]<<" 先馳得點!"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int j=0; j<4; j++){
for(int i=0; i<=s[j]; i++){
cout<<" ";
}
cout<<p[j]<<endl;
}
system("pause");
round++;
goto re;
return 0;
}
複製代碼
作者:
盧玄皓
時間:
2023-7-14 19:56
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int round=1;
int balance=0;
int option;
int buy;
re:
system("cls");
int s[]={0,0,0,0};
string p[]={"○","€","§","◎"};
srand(time(NULL));
cout<<"賽馬場"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<4; i++)
{
cout<<p[i]<<endl;
}
cout<<endl<<"可用餘額: "<<balance<<"元"<<endl<<endl;
cout<<"(1)買入 (2)下注 (3)離開 請選擇: ";
cin>>option;
if(option==1){
cout<<"買入: ";
cin>>buy;
balance=balance+buy;
goto re;
}
system("pause");
while(true)
{
system("cls");
int r=rand()%4;
s[r]++;
cout<<"比賽"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<4; i++)
{
for(int j=0; j<s[i]; j++)
cout<<" ";
cout<<p[i]<<endl;
}
if(s[r]==73)
break;
_sleep(1);
}
system("cls");
for(int i=0;i<=3;i++)
{
if(s[i]==73)
{
cout<<"比賽結束! 由 "<<p[i]<<" 先得點!"<<endl;
}
}
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<4; i++)
{
for(int j=0; j<s[i]; j++)
cout<<" ";
cout<<p[i]<<endl;
}
system("pause");
goto re;
return 0;
}
複製代碼
作者:
黃品禎
時間:
2023-7-15 16:56
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int money=0;
int round=1;
while(true)
{
system("cls");
int s[]={0,0,0,0};
string p[]={"◆","★","▲","●"};
srand(time(NULL));
while(true)
{
system("cls");
cout<<"「好事成雙」賽馬場 第"<<round<<"局"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0;i<=3;i++)
{
cout<<p[i]<<endl;
}
cout<<"\n可用餘額:"<<money<<"元"<<endl;
int option;
cout<<"(1)買入 (2)下注 (3)離開\n"<<"請選擇:";
cin>>option;
if(option==1)
{
int plus;
cout<<"要儲值多少?"<<endl;
cin>>plus;
money=money+plus;
}
}
while(true)
{
system("cls");
int r=rand()%4;
s[r]++;
cout<<"比賽進行中"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int j=0; j<=3; j++)
{
for(int i=0; i<=s[j]; i++)
cout<<" ";
cout<<p[j]<<endl;
}
if(s[r]==72)
break;
_sleep(0.005);
}
string win;
for(int i=0; i<=3; i++)
{
if(s[i]==73)
{
win=p[i];
}
}
cout<<"比賽結束"<<win<<"贏"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int j=0; j<=3; j++)
{
for(int i=0; i<=s[j]; i++)
cout<<" ";
cout<<p[j]<<endl;
system("pause");
round++;
}
}
system("pause");
return 0;
}
複製代碼
作者:
廖秝瑜
時間:
2023-7-19 10:23
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int f=0;
int d=1;
re:
system("cls");
int a[]={0,0,0,0};
string c[]={"◆","★","▲","●"};
srand(time(NULL));
int b=0;
cout<<"賽馬場--第"<<d<<"場"<<endl;
cout<<"-------------------------------------------------------------------------|終點線"<<endl;
for(int i=0;i<=3;i++)
{
cout<<c[i]<<endl;
}
cout<<endl<<"可用餘額:"<<f<<endl<<endl;
cout<<"(1)儲值 (2)下注 (3)離開 ";
int g;
cin>>g;
if(g==1)
{
cout<<"你要儲值多少錢?";
int h;
cin>>h;
f=f+h;
goto re;
}
system("pause");
system("cls");
while(true)
{
b=rand()%4;
a[b]++;
cout<<"比賽進行中"<<endl;
cout<<"-------------------------------------------------------------------------|終點線"<<endl;
for(int i=0;i<4;i++)
{
for(int j=0;j<=a[i];j++)
{
cout<<" ";
}
cout<<c[i]<<endl;
}
if(a[b]==73)
{
break;
}
_sleep(50);
system("cls");
}
cout<<"!比賽結束 由"<<c[b]<<"勝利"<<endl;
cout<<"-------------------------------------------------------------------------|終點線"<<endl;
for(int i=0;i<4;i++)
{
for(int j=0;j<=a[i];j++)
{
cout<<" ";
}
cout<c[i]<<endl;
}
system("pause");
d++;
goto re;
return 0;
}
複製代碼
作者:
呂宗晉
時間:
2023-7-20 20:18
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int round=1;
int balance=0;
int option;
int buy;
re:
system("cls");
srand(time(NULL));
int s[]={0,0,0,0};
string p[]={"◆","★","▲","●"};
int r=0;
cout<<"「好事成雙」賽馬場 第"<<round<<"局"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<4; i++)
cout<<p[i]<<endl;
cout<<endl<<"可用餘額: "<<balance<<"元"<<endl<<endl;
cout<<"(1)買入 (2)下注 (3)離開 請選擇: ";
cin>>option;
if(option==1){
//買入
cout<<"買入: ";
cin>>buy;
balance=balance+buy;
goto re;
}
system("pause");
system("cls");
while(s[r]<=73)
{
r=rand()%4;
s[r]++;
cout<<"比賽進行中"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<4; i++)
{
for(int j=0; j<s[i]; j++)
cout<<" ";
cout<<p[i]<<endl;
}
_sleep(50);
system("cls");
}
cout<<"比賽結束! 由 "<<p[r]<<" 先馳得點!"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<4; i++)
{
for(int j=0; j<s[i]; j++)
cout<<" ";
cout<<p[i]<<endl;
}
system("pause");
round++;
goto re;
return 0;
}
複製代碼
作者:
呂得銓
時間:
2023-7-20 22:38
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int round=1;
int balance=0;
int option;
int buy;
re:
system("cls");
srand(time(NULL));
int s[]={0,0,0,0};
string p[]={"◆","★","▲","●"};
int r=0;
cout<<"「好事成雙」賽馬場 第"<<round<<"局"<<endl;
cout<<"--------------------------------------------------------- ---------------| 終點"<<endl;
for(int i=0; i<4; i++)
cout<<p[i]<<endl;
cout<<endl<<"可用餘額: "<<balance<<"元"<<endl<<endl;
cout<<"(1)買入 (2)下注 (3)離開 請選擇: ";
cin>>option;
if(option==1){
cout<<"買入: ";
cin>>buy;
balance=balance+buy;
goto re;
}
system("pause");
system("cls");
while(s[r]<=73)
{
r=rand()%4;
s[r]++;
cout<<"比賽進行中"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<4; i++)
{
for(int j=0; j<s[i]; j++)
cout<<" ";
cout<<p[i]<<endl;
}
_sleep(50);
system("cls");
}
cout<<"比賽結束! 由 "<<p[r]<<" 先馳得點!"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<4; i++)
{
for(int j=0; j<s[i]; j++)
cout<<" ";
cout<<p[i]<<endl;
}
system("pause");
round++;
goto re;
return 0;
}
複製代碼
作者:
張絜晰
時間:
2023-8-3 21:04
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int counter=0;
int m=0;
re:
counter++;
int s[]={0,0,0,0};
string h[]={"◆","★","▲","●"};
srand(time(NULL));
system("cls");
cout<<"Racehorse thing: Round "<<counter<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0;i<=3;i++){
cout<<h[i]<<endl;}
cout<<"Your balance:"<<m<<endl;
cout<<"Choose an action: (1)Buy more tokens (2)Place a bet (3) Leave "<<endl;
int opt;
cin>>opt;
if(opt==1){
int waste;
cout<<"How much money do you want to spend?";
cin>>waste;
m=m+waste;
goto re;
}
system("pause");
while(1)
{
system("cls");
int r=rand()%4;
s[r]++;
cout<<"Race in progress..."<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0;i<=3;i++){
for(int j=0; j<=s[i];j++){
cout<<" ";
}
cout<<h[i]<<endl;
}
if(s[r]==73)
break;
_sleep(10);
}
system("cls");
string win;
for (int i=0;i<=3; i++){
if (s[i]==73){
win=h[i];}}
cout<<"Race ended! The winner was:"<<win<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0;i<=3;i++){
for(int j=0; j<=s[i];j++){
cout<<" ";
}
cout<<h[i]<<endl;
}
system("pause");
goto re;
return 0;
}
複製代碼
作者:
邱品惟
時間:
2023-8-12 00:24
本帖最後由 邱品惟 於 2023-8-15 20:01 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int monny=0,choose,x,y,m,r,d;
int round=1;
re:
int s[]={0,0,0,0};
string p[]={"◆","★","▲","●"};
srand(time(NULL));
cout<<"「好事成雙」賽馬場第"<<round<<"場"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<4; i++)
cout<<p[i]<<endl;
cout<<endl;
cout<<"可用餘額:"<<monny<<endl<<endl;
cout<<"(1)買入 (2)下注 (3)離開 (4)開始賽馬"<<endl;
cin>>choose;
if(choose==1)
{
cout<<"儲值";
cin>>m;
monny=m+monny;
system("cls");
goto re;
}
else if(choose==2)
{
cout<<"(1)◆ (2)★ (3)▲ (4)●"<<endl;
cin>>y;
if(y<=4&&y>=1)
{
cout<<"下注"<<endl;
cin>>x;
if(monny>=x)
{
monny=monny-x;
system("cls");
}
else if(x>monny)
{
cout<<"你還不夠"<<x-monny<<"元"<<endl;
system("pause");
system("cls");
}
goto re;
}
else
{
cout<<"輸入錯誤"<<endl;
system("pause");
system("cls");
goto re;
}
}
else if(choose==3)
{
goto bye;
}
else if(choose==4)
{
if(x==0)
{
cout<<"你真的不賭?";
cout<<"(1)賭 (2)不賭";
cin>>d;
if(d==1)
{
system("cls");
goto re;
}
if(d==2)
{
goto see;
}
}
}
else
{
cout<<"輸入錯誤"<<endl;
system("pause");
system("cls");
goto re;
}
see:
system("pause");
while(true)
{
system("cls");
r=rand()%4;
s[r]++;
cout<<"比賽進行中"<<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;
}
system("cls");
cout<<"比賽結束"<<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;
round=round+1;
cout<<"恭喜"<<p[r]<<"獲勝"<<endl;
if(y-1==r)
{
cout<<"恭喜你押對了,得到了雙倍"<<endl;
monny=monny+x*2;
}
else
cout<<"謝謝你的錢,我會拿去吃好料的"<<endl;
system("pause");
system("cls");
x=0;
goto re;
bye:
if(monny+x>0)
{
cout<<"還你"<<monny+x<<"元"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
朱奕祈
時間:
2024-3-4 20:51
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int round=1;
int balance=0;
int option;
int buy;
re:
system("cls");
int s[]={0,0,0,0};
string h[]={"◆","★","▲","●"};
srand(time(NULL));
cout<<"「好事成雙」賽馬場,第"<<round<<"局"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0;i<4;i++)
{
cout<<h[i]<<endl;
}
cout<<"可用餘額"<<balance<<"元";
cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
cin>>option;
if(option==1)
{
cout<<"你要儲值多少元?";
cin>>buy;
cout<<"買入"<<buy<<"元";
balance=buy+balance;
goto re;
}
system("pause");
while(true)
{
system("cls");
int r=rand()%4;
s[r]++;
cout<<"比賽進行中"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int j=0;j<4;j++)
{
for(int i=0;i<s[j];i++)
{
cout<<" ";
}
cout<<h[j]<<endl;
}
if(s[r]==73)
{
break;
_sleep(50);
}
}
system("cls");
for(int i=0;i<=3;i++)
{
if(s[i]==73)
{
cout<<"比賽結束! 由 "<<h[i]<<" 先馳得點!"<<endl;
}
}
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int x=0;x<4;x++)
{
for(int y=0;y<s[x];y++)
{
cout<<" ";
}
cout<<h[x]<<endl;
}
system("pause");
round++;
goto re;
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2