返回列表 發帖

賽馬程式 (六)

1. 比對比賽結果與玩家下注,判斷玩家贏了錢還是輸了錢。
2. 對變數balance做加減,使可用餘額會隨著玩家輸贏而增減。

規則如下:
若最後勝出的選手與玩家下注相同,玩家贏得下注金3倍的錢。
反之,玩家損失下注金。







本帖隱藏的內容需要回復才可以瀏覽

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.         int s[]={0,0,0,0};
  8.     string k[]={"◆","★","▲","●"};
  9.         int o, r, balance=0, option, buyin, bet, contestant;
  10.        
  11.        
  12.        
  13.         re:
  14.     o++;
  15.        
  16.         be:
  17.         system("cls");      
  18.     srand(time(NULL));
  19.    
  20.    
  21.         cout<<"「好事成雙」賽馬場 第"<<o<<"局"<<endl;
  22.     cout<<"-------------------------------------------------------------------------| 終點"<<endl;
  23.     cout<<"◆"<<endl;
  24.     cout<<"★"<<endl;
  25.     cout<<"▲"<<endl;
  26.     cout<<"●"<<endl<<endl;


  27.         option=0;
  28.         cout<<"可用餘額: "<<balance<<"元"<<endl<<endl;
  29.         cout<<"<1>買入  <2>下注  <3>離開  請選擇: ";
  30.         cin>>option;
  31.        
  32.         if(option==1){
  33.                 cout<<"買入: ";
  34.                 cin>>buyin;
  35.                 if(buyin<=0){
  36.                         cout<<"輸入錯誤";
  37.                         _sleep(1500);
  38.                         goto be;
  39.                 }
  40.                 else{
  41.                 balance+=buyin;
  42.                 goto be;}
  43.         }
  44.         else if(option==2){
  45.                 cout<<"下注: ";
  46.                 cin>>bet;
  47.                 if(bet > balance){
  48.                         cout<<"餘額不足!!請買入"<<endl;
  49.                         _sleep(1500);
  50.                         goto be;
  51.                 }
  52.                 else if (bet>0 && bet<=balance){
  53.                         cout<<"<1>◆ <2>★ <3>▲ <4>● 請選擇: ";
  54.                         cin>>contestant;
  55.                 }
  56.                 else{
  57.                         cout<<"輸入錯誤";
  58.                         _sleep(1500);
  59.                         goto be;
  60.                 }               
  61.                
  62.         }
  63.        
  64.     else if(option==3){
  65.             goto end;
  66.         }
  67.     else{
  68.                 cout<<"輸入錯誤"<<endl;
  69.                 _sleep(1500);
  70.                 goto be;
  71.         }
  72.    
  73.    
  74.         system("pause");
  75.     while(true)
  76.     {
  77.         system("cls");
  78.         r=rand()%4;
  79.         s[r]++;   
  80.         cout<<"比賽進行中 第"<<o<<"局"<<endl;
  81.         cout<<"-------------------------------------------------------------------------| 終點"<<endl;
  82.         for(int i=0; i<=s[0]; i++)
  83.             cout<<" ";
  84.         cout<<"◆"<<endl;
  85.         for(int i=0; i<=s[1]; i++)
  86.             cout<<" ";
  87.         cout<<"★"<<endl;
  88.         for(int i=0; i<=s[2]; i++)
  89.             cout<<" ";
  90.         cout<<"▲"<<endl;
  91.         for(int i=0; i<=s[3]; i++)
  92.             cout<<" ";
  93.         cout<<"●"<<endl;
  94.         if(s[r]==73)
  95.             break;
  96.         _sleep(50);                     
  97.     }
  98.    
  99.    
  100.         system("cls");
  101.     cout<<"比賽結束 由"<<k[r]<<"獲勝"<<endl;
  102.     cout<<"-------------------------------------------------------------------------| 終點"<<endl;
  103.     for(int i=0; i<=s[0]; i++)
  104.         cout<<" ";
  105.     cout<<"◆"<<endl;
  106.     for(int i=0; i<=s[1]; i++)
  107.         cout<<" ";
  108.     cout<<"★"<<endl;
  109.     for(int i=0; i<=s[2]; i++)
  110.         cout<<" ";
  111.     cout<<"▲"<<endl;
  112.     for(int i=0; i<=s[3]; i++)
  113.         cout<<" ";
  114.     cout<<"●"<<endl;
  115.    
  116.     if(contestant - 1 == r){
  117.                 cout<<"你獲得"<<bet*3<<"元"<<endl;
  118.                 balance+=(bet*3);
  119.         }
  120.         else{
  121.                 cout<<"你輸了"<<bet<<"元"<<endl;
  122.                 balance-=bet;
  123.         }
  124.     cout<<"可用餘額: "<<balance<<"元"<<endl<<endl;
  125.         cout<<"<1>買入  <2>下注  <3>離開  請選擇: ";
  126.         cin>>option;
  127.        
  128.     system("pause");
  129.     goto re;
  130.    
  131.     end:
  132.             cout<<"Bye Bye";
  133.         return 0;
  134. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<ctime>
  3. using namespace std;
  4. int main()
  5. {
  6.     int e=0;
  7.     int b,d,g,h,money=0;
  8.     srand(time(NULL));
  9. re:
  10.     e++;
  11. start:
  12.     system("cls");
  13.     int a[4]= {0,0,0,0};
  14.     string j[4]= {"△","▲","☆","★"};
  15.     cout<<"賽馬場"<<"第"<<e<<"局"<<endl;
  16.     cout<<"---------------------------------------------------------|終點"<<endl;//57
  17.     cout<<"△"<<endl;
  18.     cout<<"▲"<<endl;
  19.     cout<<"☆"<<endl;
  20.     cout<<"★"<<endl;
  21.     cout<<endl<<endl<<"你的餘額:"<<money<<endl;
  22.     cout<<"[1]買入[2]下注[3]離開:";
  23.     cin>>d;
  24.     if(d==1)
  25.     {
  26.         cout<<"你要買入多少錢?:";
  27.         cin>>b;
  28.         if(b<0)
  29.         {
  30.             cout<<"輸入錯誤";
  31.             _sleep(1500);
  32.             goto start;
  33.         }
  34.         money+=b;
  35.         goto start;
  36.     }
  37.     else if(d==2)
  38.     {
  39.         cout<<"下注:";
  40.         cin>>g;
  41.         if(g>money)
  42.         {
  43.             cout<<"輸入錯誤";
  44.             _sleep(1500);
  45.             goto start;
  46.         }
  47.         if(g<=0)
  48.         {
  49.             cout<<"輸入錯誤";
  50.             _sleep(1500);
  51.             goto start;
  52.         }
  53.         cout<<"請選擇1△ 2▲ 3☆ 4★: ";
  54.         cin>>h;
  55.     }
  56.     else if(d==3)
  57.         goto end;
  58.     else
  59.     {
  60.         cout<<"輸入錯誤";
  61.         _sleep(1500);
  62.         goto start;
  63.     }
  64.     system("pause");
  65.     system("cls");
  66.     while(true)
  67.     {
  68.         system("cls");
  69.         int c=rand()%4;

  70.         cout<<"賽馬場"<<"第"<<e<<"局"<<endl;
  71.         cout<<"---------------------------------------------------------|終點"<<endl;
  72.         a[c]+=3;
  73.         for(int m=1; m<=a[0]; m++)
  74.             cout<<" ";
  75.         cout<<"△"<<endl;
  76.         for(int m=1; m<=a[1]; m++)
  77.             cout<<" ";
  78.         cout<<"▲"<<endl;
  79.         for(int m=1; m<=a[2]; m++)
  80.             cout<<" ";
  81.         cout<<"☆"<<endl;
  82.         for(int m=1; m<=a[3]; m++)
  83.             cout<<" ";
  84.         cout<<"★"<<endl;
  85.         if(a[c]>=57)
  86.         {
  87.             system("cls");
  88.             cout<<"賽馬場"<<"第"<<e<<"局"<<"由"<<j[c]<<"先馳得點"<<endl;
  89.             cout<<"---------------------------------------------------------|終點"<<endl;
  90.             for(int m=1; m<=a[0]; m++)
  91.                 cout<<" ";
  92.             cout<<"△"<<endl;
  93.             for(int m=1; m<=a[1]; m++)
  94.                 cout<<" ";
  95.             cout<<"▲"<<endl;
  96.             for(int m=1; m<=a[2]; m++)
  97.                 cout<<" ";
  98.             cout<<"☆"<<endl;
  99.             for(int m=1; m<=a[3]; m++)
  100.                 cout<<" ";
  101.             cout<<"★"<<endl;
  102.             if(c==h-1)
  103.             {
  104.                 cout<<endl<<"你贏得了"<<g<<"元"<<endl;
  105.                 money+=g;
  106.             }
  107.             else
  108.             {
  109.                 cout<<endl<<"你損失了"<<g<<"元"<<endl;
  110.                 money-=g;
  111.             }

  112.             break;
  113.         }
  114.         _sleep(50);

  115.     }
  116.     system("pause");
  117.     system("cls");
  118.     goto re;
  119. end:
  120.     cout<<"遊戲結束";
  121.     return 0;
  122. }
複製代碼

TOP

返回列表