//DDBLTFAST_SRCCOLORKEY和DDBLTFAST_WAIT,第一个标志用来激活源表面的色彩键码;第二个标志表示只有结束blt操作,BltFast()函数才返回。
}
else
{
dd->pBackSurf->BltFast(x,y,this->pic,&rt,DDBLTFAST_WAIT);
}
2.4.2麻将函数的实现
麻将网络游戏项目分为服务器端和客户端两大模块
服务器端功能:提供游戏玩家注册、登录、
为游戏提供桌号、发牌.
对于服务器就简单说明一下。
if(WSAGETSELECTEVENT(lp)==FD_ACCEPT)
{
SOCKET acceptSock;
SOCKADDR_IN addr_from;
char uName[50],
password[30];
int len = sizeof(addr_from);
acceptSock = accept(ListenSocket,(SOCKADDR*)&addr_from,&len);
if(acceptSock==NULL)
{
PostMessage(hwnd,WM_QUIT,0,0);
return 0;
}
//接收注册名和密码
if( RecvMsgDurTime(acceptSock,recvbuff)==-1)
return 0;
char *p=strstr(recvbuff,"login:");
if( p==NULL )
return 0;
p+=strlen("login:");
char *p1 = strchr(p,',');
strcpy(password,p1+1);
*p1='\0';
strcpy(uName,p);
if( FindPlayer(uName) )
{
memset(sendbuff,0,1024);
sprintf(sendbuff,"error:Login Error,你用的用户名、密码已经登录了");
send( acceptSock,sendbuff,1024,0);
return 0;
}
if( !IsLogin(uName, password) )
{
memset(sendbuff,0,1024);
sprintf(sendbuff,"error:Login Error,请输入正确的用户名、密码");
send( acceptSock,sendbuff,1024,0);
return 0;
}
else if(wp==FD_CLOSE)
{
//closesocket();
}
//发牌的实现 的过程
void CMjTable::Fapai(int s1,int s2)
{
int faplayer = (zhuang+s1+s2+1)%4;
startdun = 136/4*faplayer + (s1+s2+2)*2 + 1;
int oneplayer=zhuang;
fapai_pos = startdun;
for(int i=0; i<48; i++)
{
if(i!=0 && i%4==0)
{
oneplayer = NextPlayer(oneplayer);
}
player[oneplayer]->Zhuapai( realpai[fapai_pos] );
fapai_pos = (fapai_pos+1)%136;
}
}
然后再发送客户端send()函数来实现 .
客户端:游戏界面,判断是否吃、碰、杠、听牌及胡牌
先定义以下:
const WORD
ANSWER_PENG = 0x10,
ANSWER_MING_GANG = 0x20,
ANSWER_AN_GANG = 0x40,
ANSWER_GANG = ANSWER_MING_GANG | ANSWER_AN_GANG,
ANSWER_HU = 0x80,
ANSWER_CHI = 0x0F,
ANSWER_LEFT_CHI = 0x01,
ANSWER_RIGHT_CHI = 0x02,
ANSWER_MIDDLE_CHI = 0x04;
const WORD
PLAYER_STATE_DAPAI = 1,
PLAYER_STATE_CPGH = 2,
PLAYER_STATE_ZIMOGH = 5,
PLAYER_STATE_SELECT_CHI = 3,
PLAYER_STATE_IDLE = 4;
//画玩家的状态
void DrawPlayerState(CDDraw *dd);
//根据MouseMove选择玩家的状态
void SelectStateByMouse(int xPos,int yPos);
int select_pai; //mouse选中的牌
int select_cpgh;
int select_chipai;
WORD PaiState;//牌的吃碰杠和状态
//确认Mouse选择的状态
void DecideStateByLMouse(int xPos,int yPos);
//取消Mouse选择的状态
void CancleStateByRMouse();
//解析服务器传来的消息,客户端玩家的状态也由此函数决定
int ParseServerMSG(char *buff);
//判断牌的吃碰杠胡
WORD DecernCPGH(int pai,WORD cpgh_flag);
//判断自摸牌的杠胡
WORD DecernZIMOGH(int pai);
以下是玩家根据方向作出吃牌判断
WORD CClientPlayer::IsChi(int pai)
{ int result[4];
for(int i=0;i<4;i++)
result[i]=-1;
for(i=0;i<StandNum;i++)
{
if(StandPai[i]>=108
|| StandPai[i]/36!=duan)
continue;
int lp = StandPai[i]%36/4;
if(lp-dp==-2) //LEFT 2
result[0]=lp;
if(lp-dp==-1) //LEFT 1
result[1]=lp;
if(lp-dp== 1) //RIGHT 1
result[2]=lp;
if(lp-dp==2) //RIGHT 2
result[3]=lp;
}
}
是否碰杠牌
int CClientPlayer::IsPengGang(int pai)
{
int num=0;
for(int i=0;i<StandNum;i++)
{
if(StandPai[i]/4==pai/4)
{
num++;
}
上一页 [1] [2] [3] [4] [5] [6] [7] [8] 下一页