#ifndef PLAYER_H
#define PLAYER_H
#include <stdio.h>
*/
#define MAXLEN 20
#define MAXC 12/*
这个枚举类型列出了玩家的4种状态,要牌,爆点,不要牌,已经21点
这种写法使代码更具可读性
*/
enum Status{ HIT, BURST, HOLD, DONE };struct Player{
int card[MAXC]; //持有的具体牌值,用于显示
char name[MAXLEN]; //姓名,用于显示
int count; //已有的牌张数
int total; //目前牌面的总点数
enum Status status; //目前状态,只能取前述枚举值
};void init( struct Player *p, char *s )
{
p->count=0;
p->total=0;
p->status=HIT;
p->name=s;}
/*
init函数用于初始化
将p->count,p->total均初始化为0,p->status初始化为HIT
并将p->name初始化为s的值
*/void getCard( struct Player *p, int card )
{
p->card[count]=card;
p->count++;
p->total+=card;
if(p->total==21)
p->status=DONE;
else if(p->total>21)
p->status=BURST;
}/*
getCard函数用于发牌card给玩家p
需要将card存入p->card
更新p->count,p->total
检查如果p->total的值变成了21点,则更新状态为DONE
如果p->total的值超过了21点,则更新状态为BURST
*/void judgeByComputer( struct Player *p, struct Player *oppo )
{if(p->total==21)
oppo->status=DONE;
else if(p->total>21)
oppo->status=BURST;
else if(p->total<21&&p->total>16)
oppo->status=HOLD;
else oppo->status=HIT;}
/*
judgeByComputer用于为玩家p制定策略,对手信息存放在oppo中
注意如果p当前的状态是已经达到21点,或者已经爆点,或者已经决定不要牌则本函数不需要做任何工作
否则进行决策
可以简单实现为如果p现在的点数小于等于16,则要牌,否则不要牌,并输出相应决策
*/void judgeByPerson( struct Player *p )
{
char ch;
if(p->status!=BURST&&p->status!=DONE)
{
printf("do you want to get a card:\n");
ch=getchar();
if(ch=='y'||ch='Y')
p->status=HIT;
else p->status=HOLD;
}
}
/*
judgeByPerson通过人机交互制定策略
注意如果p当前的状态是已经达到21点,或者已经爆点,或者已经决定不要牌则本函数不需要做任何工作
否则进行决策,让玩家从键盘输入y或者n表示是否继续要牌
做为标准要求,需要判断输入合法性,非法则继续要求输入
*/void showCard( struct Player *p )
{
int i,j;
printf("%s\n",p->name);
for(i=1;i<=p->count;i++)
{
switch(p->card[i]/100)
     {
        case 1:printf(" \003");break;//黑桃
        case 2:printf(" \006");break;//红桃
        case 3:printf(" \005");break;//梅花
        case 4:printf(" \004");break;//方块
     }
if(p->card[i]%100==1)
printf("A");
else if(p->card[i]%100<=10)
printf("%d\t",card[i]%100);
else if(p->card[i]%100==11)
printf("J");
else if(p->card[i]%100==12)
printf("Q");
else 
printf("K");
}
if(p->status==BURST)
{
printf("BURST");
}
else
printf("%d\n",p->total);
}
/*
showCard显示玩家信息
需要输出玩家名字
以及玩家的牌
注意扑克牌的四个花色对应ASCII码为3、4、5、6
需要输出花色,同时1,11,12,13要显示为A,J,Q,K
最后输出玩家的总点数,如果已经爆点,则不输出点数,输出BURST
*/
以上是我写的BLACK JACK中player。h的文件,整体项目运行的时候出现了下面的一堆问题,不知道怎么回事?1>------ Build started: Project: BLACK JACK, Configuration: Debug Win32 ------
1>Compiling...
1>main.cpp
1>e:\program files\microsoft visual studio 9.0\vc\include\player.h(34) : error C2440: '=' : cannot convert from 'char *' to 'char [20]'
1>        There are no conversions to array types, although there are conversions to references or pointers to arrays
1>e:\program files\microsoft visual studio 9.0\vc\include\player.h(45) : error C2065: 'count' : undeclared identifier
1>e:\program files\microsoft visual studio 9.0\vc\include\player.h(89) : warning C4305: '=' : truncation from 'char' to 'bool'
1>e:\program files\microsoft visual studio 9.0\vc\include\player.h(89) : error C2106: '=' : left operand must be l-value
1>e:\program files\microsoft visual studio 9.0\vc\include\player.h(117) : error C2065: 'card' : undeclared identifier
1>e:\program files\microsoft visual studio 9.0\vc\include\player.h(143) : fatal error C1070: mismatched #if/#endif pair in file 'e:\program files\microsoft visual studio 9.0\vc\include\player.h'
1>Build log was saved at "file://c:\Documents and Settings\lenovo\My Documents\Visual Studio 2008\Projects\BLACK JACK\BLACK JACK\Debug\BuildLog.htm"
1>BLACK JACK - 5 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========麻烦知道的,解释下。谢谢!