10楼的 两个都是爆牌啊 当然是平局了
我又对程序做了点修改
#include <iostream>
#include <stdlib.h>
#include <ctime>
using namespace std;
//金钱类
class money
{public:
money(){M=50;}
int shift(int a,int b);
private:
int M;
};
//21点类
class point21
{public:
void Sru();
void Cli();
void display();
private:
int a;
int b;
money c;
};
//21点程序
void point21::Sru()
{int i=1,j=0; char c;
b=0;a=0;
srand(time(0));
while(j==0)
{if(b<13)
{if(rand()%6<4)
b+=(rand()%9+1);}
else if(b>=13&&b<=21)
{if(rand()%6<2)
b+=(rand()%9+1);}
if(b>18)j=1;
}
while(i==1)
{
cout<<"要牌请按Y/y,亮牌请按T/t: "<<endl;
cin>>c;
if(c=='y'||c=='Y')
{a+=(rand()%9+1);cout<<"您的牌点是:"<<a<<endl;}
if(c=='T'||c=='t')
i=0;}
}
void point21::Cli()
{cout<<"您的牌点是:"<<a<<" "<<"电脑的牌点是:"<<b<<endl;
a=21-a;
b=21-b;
}
void point21::display()
{int x;
if(a>=0&&b>=0)
{if(a<b)
{
cout<<"您胜利赢了10枚金币"<<endl;
cout<<"您还有 "<<c.shift(10,x=1)<<" 枚金币"<<endl;}
else if(a>b)
{
cout<<"您输了10枚金币"<<endl;
cout<<"您还有 "<<c.shift(10,x=0)<<" 枚金币"<<endl;}
else {
cout<<"平局"<<endl;
cout<<"您还有 "<<c.shift(0,x=-1)<<" 枚金币"<<endl;}
}
else if(a<0&&b>=0)
{cout<<"您爆牌了,输了20枚金币"<<endl;
cout<<"您还有 "<<c.shift(20,x=0)<<" 枚金币"<<endl;}
else if(a>=0&&b<0)
{cout<<"电脑爆牌了您赢了20枚金币"<<endl;
cout<<"您还有 "<<c.shift(20,x=1)<<" 枚金币"<<endl;}
else
{
cout<<"平局"<<endl;
cout<<"您还有 "<<c.shift(0,x=-1)<<" 枚金币"<<endl;}
}
//欢迎界面
void welcome()
{
cout<<" #########################"<<endl;
cout<<" # #"<<endl;
cout<<" # 21点 #"<<endl;
cout<<" # 欢迎您 #"<<endl;
cout<<" # #"<<endl;
cout<<" #########################"<<endl;
cout<<"游戏规则:"<<endl;
cout<<"在游戏中,每个玩家都争取拿到最接近21点的牌,<可以多次要牌,然后点数累加>;但是不能超过21点,超过为“爆牌”即失败,只有最接近21点的人才有可能得到胜利。"<<endl;
cout<<"游戏开始:";
}
int money::shift(int a,int b)
{if(b==1)
M+=a;
else if(b==0)
M-=a;
return M;
}
int main()
{point21 D;char i;
welcome();
do
{
D.Sru();
D.Cli();
D.display();
if(D.display()==0)break;
cout<<"您要在来一局吗? 按1键继续,退出请按q。"<<endl;
cin>>i;
}
while(int(i)!='q');
cout<<"欢迎再来"<<endl;
return 0;
}