原文在project code上,作者主要是想介绍对memcache的封装,但由于没有公布所有的封装和封装的库,作者贴了一些×××的游戏逻辑作为致歉。没太看懂作者memcache封装的相关代码,感觉用原生接口也并不麻烦,倒是觉得游戏逻辑给了一些启发。所以转过来。不知道作者是粗心还是其他原因,原有代码需要做些修改才能编译通过。

hands用来处理手牌,方便round的时候检查

global用来做全局的管理

由于hands逻辑比较复杂, 各位直接看附件好了


golbal.h


struct POKERCARD

{

union

{

USHORT card;

struct {UCHAR value, color;} split;

}S_un;

};


struct BESTHAND

{

UCHAR nHandType;

POKERCARD m_BestHand[TOTAL_OF_HANDS];

};


static const USHORT GLOBAL_POKER[52] =

{

0x0102, 0x0103, 0x0104, 0x0105, 0x0106, 0x0107, 0x0108, 0x0109, 0x010A, 0x010B, 0x010C, 0x010D, 0x010E,

0x0202, 0x0203, 0x0204, 0x0205, 0x0206, 0x0207, 0x0208, 0x0209, 0x020A, 0x020B, 0x020C, 0x020D, 0x020E,

0x0302, 0x0303, 0x0304, 0x0305, 0x0306, 0x0307, 0x0308, 0x0309, 0x030A, 0x030B, 0x030C, 0x030D, 0x030E,

0x0402, 0x0403, 0x0404, 0x0405, 0x0406, 0x0407, 0x0408, 0x0409, 0x040A, 0x040B, 0x040C, 0x040D, 0x040E

};


#define p_cardS_un.card

#define p_colorS_un.split.color

#define p_valueS_un.split.value

enum

FANG_KUAI = 1, MEI_HUA, HONG_TAO, HEI_TAO

};


enum

{

};

struct SAME_CARDS_COUNT{

UCHAR pos, count;

};


#define COMP_VALUE(a,b)(a == b ? 0 : a



#ifndef __POKER_GLOBAL_STRING__

#define__POKER_GLOBAL_STRING__


#define show_poker_color(n)g_color[n-1]

#define show_hands_type_cn(n)g_handstype_string_cn[n-1]



#define SMALLBLIND 10



#define USERSIT 2

#define USERNOSIT 1

#endif


round.h


#pragma once

#include "global.h"

#include "hands.h"

class CGameRound

{

public:

CGameRound(void)

{

m_nPos = 0;

m_nRoundCount = 0;

}


private:

POKERCARD m_Poker[TOTAL_OF_POKER];

int m_nPos;

int m_nRoundCount;

protected:

Chands m_hands;

public:


USHORT DealCard(void)

{

assert(m_nPos != 0);

return m_Poker[--m_nPos].p_card;

}

void Shuffle(void)

{

int pos;

srand((unsigned)time(NULL)+m_nRoundCount++);

memcpy(m_Poker, GLOBAL_POKER, sizeof(GLOBAL_POKER));

POKERCARD temp ;

for(int i = 0; i

{

pos = rand() % TOTAL_OF_POKER;

temp.p_card = m_Poker[i].p_card;

m_Poker[i].p_card = m_Poker[pos].p_card;

m_Poker[pos].p_card = temp.p_card;

}

m_nPos = TOTAL_OF_POKER;

}

int CompHandsType(UCHAR t1, POKERCARD *p1, UCHAR t2, POKERCARD *p2)

{

if(t1 return -1;


int nRet = COMP_VALUE(p1[0].p_value, p2[0].p_value);

if(nRet != 0)return nRet;


int nPos = 0;

switch(t1)

{

break;

break;

break;

break;

return nRet;

default:

break;

}

for(int i = nPos; i

nRet = COMP_VALUE(p1[i].p_value, p2[i].p_value);

return nRet ;

}

};