返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.    
  8.    int n=1,blance=0;   
  9.    re:
  10.         system("cls");
  11.         int a=0,b=0,c=0,d=0,r,opition,buyin,bet,horse,win,money=0;
  12.        string words ="賽馬進行中";
  13.    string name[4]={"Ⅰ","Ⅱ","Ⅲ","Ⅳ"};
  14.         int position =0;
  15.   cout<<"賽馬場 第"<<n<<"局"<<endl;
  16.   cout<<"-----------------------------------------------------------------終點"<<endl;  
  17.    cout<<"Ⅰ"<<endl;
  18.    cout<<"Ⅱ"<<endl;
  19.    cout<<"Ⅲ"<<endl;
  20.    cout<<"Ⅳ"<<endl;
  21.    cout<<endl;
  22.    cout<<"可用餘額"<<blance<<endl;
  23.    cout<<endl;
  24.    cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
  25.    cin>>opition;
  26.     if(opition==1)
  27.     {
  28.         cout<<"買入:";
  29.         cin>>buyin;
  30.         blance += buyin;
  31.         goto re;
  32.     }else if(opition==2)
  33.     {
  34.           cout<<"下注金額:";
  35.           cin>>bet;
  36.           }     
  37.           if(bet>blance)
  38.           {
  39.           cout<<"餘額不足 請重新下注"<<endl;
  40.           system("pause");
  41.           goto re;
  42.           }else if(bet>0 && blance>=bet)
  43.           {
  44.              cout<<"請選擇 (1)Ⅰ (2)Ⅱ (3)Ⅲ (4)Ⅳ"<<endl;
  45.              cin>>horse;
  46.              blance-=bet;
  47.              cout<<"即將開始賽馬"<<endl;
  48.             }else   
  49.             {
  50.                    cout<<"輸入錯誤 請重新輸入"<<endl;
  51.                    system("pause");
  52.                    goto re;
  53.             }
  54.                      
  55.        }else
  56.        {            
  57.          goto end;
  58.        }
  59.                  
  60.    system("pause");
  61.    system("cls");  
  62.    srand(time(NULL));
  63.    
  64.    
  65.    
  66.    while(a<70 && b<70 && c<70 && d<70)
  67.    {
  68.        r=rand()%4+1;
  69.               
  70.           switch(r)
  71.          {
  72.            case 1:      
  73.               a++;           
  74.               break;
  75.            case 2:      
  76.               b++;           
  77.               break;
  78.            case 3:      
  79.               c++;           
  80.               break;      
  81.            case 4:      
  82.               d++;           
  83.               break;   
  84.          }      
  85.        if(a==70 || b==70 || c==70 || d==70)
  86.        {
  87.            int position;     
  88.            if(a==70)
  89.               position = 0;
  90.               win=1;
  91.          if(b==70)
  92.               position =1;
  93.               win=2;
  94.          if(c==70)
  95.               position =2;
  96.               win=3;
  97.          if(d==70)
  98.               position =3;
  99.               win=4;
  100.        }           
  101.            words = "比賽結束,由"+name[position]+"奪魁";
  102.    }
  103.                 cout<<words<<endl;
  104.       cout<<"------------------------------------------------------------------------| 終點"<<endl;   
  105.               
  106.       for(int i=0;i<=a;i++)
  107.       {
  108.           cout<<" ";
  109.       }
  110.        cout<<name[0]<<endl;
  111.      
  112.        for(int i=0;i<=b;i++)
  113.       {
  114.           cout<<" ";
  115.       }
  116.        cout<<name[1]<<endl;
  117.       
  118.        for(int i=0;i<=c;i++)
  119.       {
  120.           cout<<" ";
  121.       }
  122.        cout<<name[2]<<endl;
  123.       
  124.        for(int i=0;i<=d;i++)
  125.       {
  126.           cout<<" ";
  127.       }
  128.        cout<<name[3]<<endl;
  129.       
  130.       
  131.       
  132.        if(a<=69 && b<=69 && c<=69 && d<=69)
  133.        {      
  134.              system("cls");         
  135.        }   
  136.                      
  137.    }
  138.    if(horse==win)
  139.    {
  140.       blance = blance + bet*3;
  141.       money=money+bet*3;
  142.      cout<<"您贏了"<<bet*3<<"元"<<endl;                 
  143.    }else
  144.    {
  145.         money=money-bet;
  146.       cout<<"損失"<<bet<<"元"<<endl;   
  147.    }
  148.   n++;
  149.     system("pause");
  150.     goto re;     
  151.     end:
  152.         
  153.     if(money==0)
  154.     {
  155.         cout<<"沒輸沒贏"<<endl;        
  156.     }else if(money>0)
  157.     {
  158.         cout<<"贏了"<<money<<"元"<<endl;
  159.         
  160.     }else  
  161.      {
  162.       cout<<"賠了"<<-money<<"元,下次加油"<<endl;   
  163.      }
  164.      cout<<"謝謝光臨"<<endl;              
  165.     system("pause");  
  166.     return 0;
  167. }
複製代碼

TOP

返回列表