void Wait_f(int);
void Pause_f();/*暂停,按任意键继续*/
int Random_f(long ,long );/*返回两个参数之间的随机数*/
void Replay_f(char *);/*询问是否重开一局*/
void Hit_f(int *);/*发一张牌*/
void Deal_f(int *,int *,int *,int *);/*双方各发两张牌*/
void Bet_f(int *,int *);/*接受下注的数目*/
void Print_f(int ,int ,int ,int );/*打印结果*/
void Rules_f();/*显示游戏规则*/
void Results_f(int ,int ,int ,int *,int *,int *,int *);/*统计结果(输赢平)*/ void Hit_f2(int * npTotal,int a);
int nnn;
int main()
{
int nPlayer=0,nCpu=0,nWin=0,nLose=0,nDraw=0,nPlayerTurns=0,
nCpuTurns=0,nMoney=0,nBet;
/* nPlayer——玩家手中全部牌的点数和,nPlayerTurns——玩家手中牌的数量*/
char chAnswer;
char mmm;
int a;
system(\"cls\");/* 执行系统命令“清屏” */
Rules_f();
printf(\"\\\WOULD YOU LIKE TO PLAY? \");
scanf(\"%c\
if((chAnswer=='y')||(chAnswer=='Y'))
{
2
printf(\"\\\I WILL LET YOU START WITH $100\\n\");
nMoney=100;
printf(\"\\\\");
Pause_f();
}
else
{
return(0);
}
do
{
system(\"cls\");
if(nMoney<0)
{
printf(\"Your broke\\n\");
return(0);
}
Bet_f(&nBet,&nMoney);/*接受下注的数目*/
Deal_f(&nPlayer,&nCpu,&nPlayerTurns,&nCpuTurns);/*双方各发两张牌*/
printf(\"\\\Would you want to cheat? yes or no?\");
scanf(\"%c\
if((mmm=='y')||(mmm=='Y'))
{
printf(\"%d\
printf(\"\\\which card do you want?\");
scanf(\"%d\
}
system(\"cls\");
do
{
printf(\"\\\Would You Like To Hit or Stay :\");/*询问玩家是否接着要牌*/
scanf(\" %c\
if((chAnswer=='h')||(chAnswer=='H'))
3
{
nPlayerTurns++;/*计算总牌数*/
if(nPlayerTurns>5)/*看是否允许再要牌*/
{
printf(\"\\\You Can't Have more than 5 cards\");
}
}
if((nPlayerTurns<6)&&(chAnswer=='h'))
{
printf(\"\\n\");
if((mmm=='y')||(mmm=='Y'))
Hit_f2(&nPlayer,a);
else Hit_f(&nPlayer);/*为玩家发一张牌*/
}
}
while((chAnswer=='h')||(chAnswer=='H'));
for(;(nCpu<16)&&(nCpuTurns<6);nCpuTurns++)/*计算机要牌的条件*/ {
printf(\"\\n\");
printf(\"\\\The Dealer Takes A Card\");
Hit_f(&nCpu);/*为计算机发一张牌*/
}
printf(\"\\n\\n\");
printf(\"\\\The Dealer Has A Total: %d\\n\显示总点数*/
printf(\"\\\You Have A Total Of: %d\\n\
printf(\"\\n\");
Results_f(nPlayer,nCpu,nBet,&nMoney,&nDraw,&nWin,&nLose);/*计算最后的结果(统计输赢平的局数)*/
Replay_f(&chAnswer);/*询问是否重开一局*/
}while((chAnswer=='y')||(chAnswer=='Y')); Print_f(nWin,nLose,nDraw,nMoney);/*打印最后结果*/
printf(\"\\n\");
printf(\"\\\\\");
return(0);
}
4
void Rules_f() /*这个函数显示游戏规则*/
{
printf(\"\\ WELCOME TO ISAAC SHAFFERS BLACK JACK GAME\\n\");
printf(\"\\\ HERE ARE SOME SIMPLE RULES\\n\");
printf(\"\\\1:You Can only have a max of 5 cards.\\n\");
printf(\"\\\2:If you bust you automatically lose.\\n\");
printf(\"\\\3:If you win you win double what you bet\");
printf(\"\\\4:The Dealer stops at or after 16.\\n\");
printf(\"\\\\\");
getchar();
}
void Bet_f(int* npBet,int* npMoney) /*该函数接受玩家下注,并计算赌资的总数
*/
{
system(\"cls\");
printf(\"\\\YOU HAVE:$%d\\n\
printf(\"\\\How Much Do You Wish To Bet:\");
scanf(\"%d\
if(*npBet<0)
{
*npBet=*npBet*(-1);
}
*npMoney=*npMoney-*npBet;
}
void Deal_f(int* npPlayer,int*npCpu,int*npPlayeReturns,int *npCpuReturns)
/*该函数是给计算机与玩家各发两张牌*/
{
int nPlayerCard1,nPlayerCard2,nCpuCard1,nCpuCard2;
*npPlayeReturns=2;
*npCpuReturns=2;
nPlayerCard1=Random_f(13,1);
printf(\"\\n\\\DEALING HAND\\n\");
getchar();
Pause_f();
nPlayerCard2=Random_f(13,1);
Pause_f();
nCpuCard1=Random_f(13,1);
Pause_f();
nCpuCard2=Random_f(13,1);
5
if (nPlayerCard1>=10)
{
nPlayerCard1=10;
}
if (nPlayerCard2>=10)
{
nPlayerCard2=10;
}
if (nCpuCard1>=10)
{
nCpuCard1=10;
}
if (nCpuCard2>=10)
{
nCpuCard2=10;
}
*npPlayer=nPlayerCard1+nPlayerCard2; *npCpu=nCpuCard1+nCpuCard2;
printf(\"\\\YOU HAVE a total of:%d\\n\
printf(\"[%d]\
printf(\"\\\The DEALER HAS A %d SHOWING\
printf(\"\\n\");
printf(\"[*][%d]\
}
void Hit_f(int * npTotal) /* 发一张牌,返回点数之和*/
{
int nCard;
nCard=Random_f(13,1);
if(nCard>=10)
{
nCard=10;
}
* npTotal=* npTotal+nCard;
printf(\"\\\The card is a :%d\\n\
printf(\"\\\Total is :%d\\n\
}
void Results_f(int nPlayer,int nCpu,int nBet,int * npMoney,int * npDraw,int
* npWin,int * npLose)/*统计结果(输赢平及输赢平的局数)*/ {
if(nCpu==nPlayer)
{
6
printf(\"\\\IT WAS A DRAW HOUSE WINS\\n\");
++* npDraw;
}
if(nPlayer>21)
{
printf(\"\\\You Bust\\n\");
++* npLose;
}
else
{
if(nCpu{printf(\"\\n\\\YOU WIN\");
*npMoney=*npMoney+(nBet*2);
++* npWin;
}
}
if(nCpu>21)
{
printf(\"\\\Dealer Bust\\n\");
if(nPlayer<=21)
{
printf(\"\\n\\\YOU WIN\");
++* npWin;
*npMoney=*npMoney+(nBet*2);
}
}
else
{
if(nCpu>nPlayer)
{
printf(\"\\\YOU LOSE\\n\");
++* npLose;
}
}
}
void Replay_f(char *chpAns) /*询问是否重开一局*/ {
printf(\"\\n\\Would You Like To Play This Game Again:\");
scanf(\"%c\
7
}
void Print_f(int nWins,int nLose,int nDraw,int nMoney)
{
printf(\"\\\\WINS:%d\\n\
printf(\"\\\\LOSE:%d\\n\
printf(\"\\\\DRAWS:%d\\n\
printf(\"\\\\MONEY:%d\\n\
}
void Wait_f(int nMilli)
{
int nStart1,nStart2;
for(nStart1=0;nStart1for(nStart2=0;nStart2{;}}
void Pause_f()
{
printf(\"Press Any Key To Continue\");
getchar();
}
int Random_f(long lBigNumber, long lSmallNumber) /*选择两个参数之间的随机数*/
{
int nRan;
srand((unsigned)time(NULL));
nRan=rand()%(lBigNumber-(lSmallNumber-1))+lSmallNumber;
return(nRan);
}
void Hit_f2(int * npTotal,int a) /* 发一张牌,返回点数之和*/
{
int nCard;
nCard=a;
if(nCard>=10)
{
nCard=10;
}
* npTotal=* npTotal+nCard;
printf(\"\\\The card is a :%d\\n\
printf(\"\\\Total is :%d\\n\
}
8