- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- int a,b,c,d,f,g,h,i,j,k;
- srand(time(NULL));
- start:
- int n=0,e=0,ce=0,cn=0;
- cout<<"**決戰21點v1.0**"<<endl;
- system("pause");
- system("cls");
- re:
-
- a=rand()%4+3;
- b=rand()%13+1;
- c=rand()%4+3;
- d=rand()%13+1;
- cout<<"你抽到到的是 "<<char(a);
- n++;
- if(b==1)
- cout<<"A ";
- else if(b==11)
- cout<<"J ";
- else if(b==12)
- cout<<"Q ";
- else if(b==13)
- cout<<"K ";
- else
- cout<<b<<" ";
- cout<<char(c);
- n++;
- if(d==1)
- cout<<"A ";
- else if(d==11)
- cout<<"J ";
- else if(d==12)
- cout<<"Q ";
- else if(d==13)
- cout<<"K ";
- else
- cout<<d<<endl;
- if(b==10 || b==11 || b==12 || b==13 || b==1 )
- {
- e=e+10;
- }else
- {
- e=e+b;
- }
- if(d==10 || d==11 || d==12 || d==13 || d==1)
- {
- e=e+10;
- }else
- {
- e=e+d;
- }
- if(e>21)
- {
- cout<<"你目前的點數是:"<<e<<endl;
- loose:
- cout<<"你輸了!!"<<endl;
- system("pause");
- system("cls");
- goto start;
- }else
- if(n>=6 && e<=21)
- {
- cout<<"你目前的點數是:"<<e<<endl;
- win:
- cout<<"你贏了"<<endl;
- system("pause");
- system("cls");
- goto start;
- }
- if(e==21 && n<6)
- {
- cout<<"Black Jack!!"<<endl;
- }
- cout<<"你目前的點數是: "<<e<<endl;
- hi:
- cout<<"還要再抽牌嗎? (1)yes(2)no"<<endl;
- cin>>f;
- if(f==1)
- goto re;
- else if(f==2)
- goto com;
- else
- {
- goto hi;
- }
- com:
- g=rand()%4+3;
- h=rand()%13+1;
- i=rand()%4+3;
- j=rand()%13+1;
- cout<<"電腦抽到到的是 "<<char(g);
- cn++;
- if(h==1)
- cout<<"A ";
- else if(h==11)
- cout<<"J ";
- else if(h==12)
- cout<<"Q ";
- else if(h==13)
- cout<<"K ";
- else
- cout<<h<<" ";
- cout<<char(i);
- ce++;
- if(j==1)
- cout<<"A ";
- else if(j==11)
- cout<<"J ";
- else if(j==12)
- cout<<"Q ";
- else if(j==13)
- cout<<"K ";
- else
- cout<<j<<endl;
- if(h==10 || h==11 || h==12 || h==13 || h==1 )
- {
- ce=ce+10;
- }else
- {
- ce=ce+b;
- }
- if(j==10 || j==11 || j==12 || j==13 || j==1)
- {
- ce=ce+10;
- }else
- {
- ce=ce+j;
- }
- if(cn>=6 && ce<=21)
- {
- cout<<"電腦目前的點數是:"<<ce<<endl;
- cout<<"電腦贏了"<<endl;
- goto loose;
- }
- if(ce>21)
- {
- cout<<"電腦目前的點數是:"<<ce<<endl;
- cout<<"點腦爆了!!"<<endl;
- goto win;
- }
- if(ce==21 && n<6)
- {
- cout<<"Black Jack!!"<<endl;
- }
- cout<<"電腦目前的點數是:"<<ce<<endl;
- if(ce>16 && ce>0)
- {
- cout<<"電腦決定再抽一次!!"<<endl;
- goto com;
- }else if(ce>=16 || ce>=17 || ce>=18)
- {
- cout<<"電腦決定不要再抽牌了"<<endl;
- goto end;
- }
- end:
- cout<<"玩家"<<e<<"點,電腦"<<ce<<"點"<<endl;
- if(ce>e)
- {
- goto loose;
- }else if(e>ce)
- {
- goto win;
- }else if(e==ce)
- {
- cout<<"平手"<<endl;
- goto start;
- }
- system("pause");
- return 0;
- }
複製代碼 |