诸暨麻将添加redis
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

448 lines
10 KiB

  1. #ifndef CARD_CONTROL_HEAD_FILE
  2. #define CARD_CONTROL_HEAD_FILE
  3. #pragma once
  4. #include "Stdafx.h"
  5. #include "Resource.h"
  6. #include "GameLogic.h"
  7. #include "cassert"
  8. //////////////////////////////////////////////////////////////////////////
  9. // 扑克定义
  10. // 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09, //万子
  11. // 0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19, //索子
  12. // 0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29, //同子
  13. // 0x31,0x32,0x33,0x34,0x35,0x36,0x37, //番子
  14. // 0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F, //花子
  15. //////////////////////////////////////////////////////////////////////////
  16. //////////////////////////////////////////////////////////////////////////
  17. //X 排列方式
  18. enum enXCollocateMode
  19. {
  20. enXLeft, //左对齐
  21. enXCenter, //中对齐
  22. enXRight, //右对齐
  23. };
  24. //Y 排列方式
  25. enum enYCollocateMode
  26. {
  27. enYTop, //上对齐
  28. enYCenter, //中对齐
  29. enYBottom, //下对齐
  30. };
  31. //方向枚举
  32. enum enDirection
  33. {
  34. Direction_East, //东向 右
  35. Direction_South, //南向
  36. Direction_West, //西向
  37. Direction_North, //北向
  38. };
  39. //////////////////////////////////////////////////////////////////////////
  40. //扑克图片
  41. class CCardListImage
  42. {
  43. //位置变量
  44. protected:
  45. int m_nItemWidth; //子项高度
  46. int m_nItemHeight; //子项宽度
  47. int m_nViewWidth; //子项高度
  48. int m_nViewHeight; //子项宽度
  49. //资源变量
  50. protected:
  51. CPngImage m_CardListImage; //图片资源
  52. //函数定义
  53. public:
  54. //构造函数
  55. CCardListImage();
  56. //析构函数
  57. virtual ~CCardListImage();
  58. //信息函数
  59. public:
  60. //获取宽度
  61. int GetViewWidth() { return m_nViewWidth; }
  62. //获取高度
  63. int GetViewHeight() { return m_nViewHeight; }
  64. //资源管理
  65. public:
  66. //加载资源
  67. bool LoadResource(LPCTSTR uResourceID, int nViewWidth, int nViewHeight);
  68. //释放资源
  69. bool DestroyResource();
  70. //功能函数
  71. public:
  72. //获取位置
  73. inline int GetImageIndex(BYTE cbCardData);
  74. //绘画扑克
  75. inline bool DrawCardItem(CDC * pDestDC, BYTE cbCardData, int xDest, int yDest);
  76. };
  77. //////////////////////////////////////////////////////////////////////////
  78. //扑克资源
  79. class CCardResource
  80. {
  81. //用户扑克
  82. public:
  83. CPngImage m_ImageUserTop; //图片资源
  84. CCardListImage m_ImageUserBottom; //图片资源
  85. CPngImage m_ImageUserLeft; //图片资源
  86. CPngImage m_ImageUserRight; //图片资源
  87. //桌子扑克
  88. public:
  89. CCardListImage m_ImageTableTop; //图片资源
  90. CCardListImage m_ImageTableLeft; //图片资源
  91. CCardListImage m_ImageTableRight; //图片资源
  92. CCardListImage m_ImageTableBottom; //图片资源
  93. //牌堆扑克
  94. public:
  95. CPngImage m_ImageHeapDoubleLV; //左边的堆牌
  96. CPngImage m_ImageHeapSingleLV; //左边的堆牌
  97. CPngImage m_ImageHeapDoubleRV; //右边的堆牌
  98. CPngImage m_ImageHeapSingleRV; //右边的堆牌
  99. CPngImage m_ImageHeapDoubleTV; //上边的堆牌
  100. CPngImage m_ImageHeapSingleTV; //上边的堆牌
  101. CPngImage m_ImageHeapDoubleBV; //下边的堆牌
  102. CPngImage m_ImageHeapSingleBV; //下边的堆牌
  103. //函数定义
  104. public:
  105. //构造函数
  106. CCardResource();
  107. //析构函数
  108. virtual ~CCardResource();
  109. //功能函数
  110. public:
  111. //加载资源
  112. bool LoadResource();
  113. //消耗资源
  114. bool DestroyResource();
  115. };
  116. //////////////////////////////////////////////////////////////////////////
  117. //堆立扑克
  118. class CHeapCard
  119. {
  120. //控制变量
  121. protected:
  122. CPoint m_ControlPoint; //基准位置
  123. enDirection m_CardDirection; //扑克方向
  124. //扑克变量
  125. protected:
  126. WORD m_wFullCount; //全满数目
  127. WORD m_wMinusHeadCount; //头部空缺
  128. WORD m_wMinusLastCount; //尾部空缺
  129. //函数定义
  130. public:
  131. //构造函数
  132. CHeapCard();
  133. //析构函数
  134. virtual ~CHeapCard();
  135. //功能函数
  136. public:
  137. //绘画扑克
  138. void DrawCardControl(CDC * pDC);
  139. //设置扑克
  140. bool SetCardData(WORD wMinusHeadCount, WORD wMinusLastCount, WORD wFullCount);
  141. //控件控制
  142. public:
  143. //设置方向
  144. void SetDirection(enDirection Direction) { m_CardDirection=Direction; }
  145. //基准位置
  146. void SetControlPoint(int nXPos, int nYPos) { m_ControlPoint.SetPoint(nXPos,nYPos); }
  147. };
  148. //////////////////////////////////////////////////////////////////////////
  149. //组合扑克
  150. class CWeaveCard
  151. {
  152. //控制变量
  153. protected:
  154. bool m_bDisplayItem; //显示标志
  155. CPoint m_ControlPoint; //基准位置
  156. enDirection m_CardDirection; //扑克方向
  157. BYTE m_cbDirectionCardPos; //方向扑克
  158. bool m_bGameEnd; //
  159. //扑克数据
  160. protected:
  161. WORD m_wCardCount; //扑克数目
  162. BYTE m_cbCardData[4]; //扑克数据
  163. //函数定义
  164. public:
  165. //构造函数
  166. CWeaveCard();
  167. //析构函数
  168. virtual ~CWeaveCard();
  169. //功能函数
  170. public:
  171. //绘画扑克
  172. void DrawCardControl(CDC * pDC);
  173. //绘画扑克
  174. void DrawCardControl(CDC * pDC, int nXPos, int nYPos);
  175. //设置扑克
  176. bool SetCardData(const BYTE cbCardData[], WORD wCardCount);
  177. //控件控制
  178. public:
  179. //设置显示
  180. void SetDisplayItem(bool bDisplayItem) { m_bDisplayItem=bDisplayItem; }
  181. //设置方向
  182. void SetDirection(enDirection Direction) { m_CardDirection=Direction; }
  183. //基准位置
  184. void SetControlPoint(int nXPos, int nYPos) { m_ControlPoint.SetPoint(nXPos,nYPos); }
  185. //方向牌
  186. void SetDirectionCardPos(BYTE cbPos) { assert(cbPos <= 3); m_cbDirectionCardPos = cbPos;}
  187. //
  188. void SetGameEnd( bool bGameEnd ) { m_bGameEnd = bGameEnd; }
  189. //内部函数
  190. private:
  191. //获取扑克
  192. inline BYTE GetCardData(WORD wIndex);
  193. };
  194. //////////////////////////////////////////////////////////////////////////
  195. //用户扑克
  196. class CUserCard
  197. {
  198. //扑克数据
  199. protected:
  200. WORD m_wCardCount; //扑克数目
  201. bool m_bCurrentCard; //当前标志
  202. //控制变量
  203. protected:
  204. CPoint m_ControlPoint; //基准位置
  205. enDirection m_CardDirection; //扑克方向
  206. //函数定义
  207. public:
  208. //构造函数
  209. CUserCard();
  210. //析构函数
  211. virtual ~CUserCard();
  212. //功能函数
  213. public:
  214. //绘画扑克
  215. void DrawCardControl(CDC * pDC);
  216. //设置扑克
  217. bool SetCurrentCard(bool bCurrentCard);
  218. //设置扑克
  219. bool SetCardData(WORD wCardCount, bool bCurrentCard);
  220. //控件控制
  221. public:
  222. //设置方向
  223. void SetDirection(enDirection Direction) { m_CardDirection=Direction; }
  224. //基准位置
  225. void SetControlPoint(int nXPos, int nYPos) { m_ControlPoint.SetPoint(nXPos,nYPos); }
  226. };
  227. //////////////////////////////////////////////////////////////////////////
  228. //丢弃扑克
  229. class CDiscardCard
  230. {
  231. //扑克数据
  232. protected:
  233. WORD m_wCardCount; //扑克数目
  234. BYTE m_cbCardData[24]; //扑克数据
  235. //控制变量
  236. protected:
  237. CPoint m_ControlPoint; //基准位置
  238. enDirection m_CardDirection; //扑克方向
  239. //函数定义
  240. public:
  241. //构造函数
  242. CDiscardCard();
  243. //析构函数
  244. virtual ~CDiscardCard();
  245. //功能函数
  246. public:
  247. //绘画扑克
  248. void DrawCardControl(CDC * pDC);
  249. //增加扑克
  250. bool AddCardItem(BYTE cbCardData);
  251. //设置扑克
  252. bool SetCardData(const BYTE cbCardData[], WORD wCardCount);
  253. //获取位置
  254. CPoint GetLastCardPosition();
  255. //控件控制
  256. public:
  257. //设置方向
  258. void SetDirection(enDirection Direction) { m_CardDirection=Direction; }
  259. //基准位置
  260. void SetControlPoint(int nXPos, int nYPos) { m_ControlPoint.SetPoint(nXPos,nYPos); }
  261. };
  262. //////////////////////////////////////////////////////////////////////////
  263. //桌面扑克
  264. class CTableCard
  265. {
  266. //扑克数据
  267. protected:
  268. WORD m_wCardCount; //扑克数目
  269. BYTE m_cbCardData[14]; //扑克数据
  270. //控制变量
  271. protected:
  272. CPoint m_ControlPoint; //基准位置
  273. enDirection m_CardDirection; //扑克方向
  274. //函数定义
  275. public:
  276. //构造函数
  277. CTableCard();
  278. //析构函数
  279. virtual ~CTableCard();
  280. //功能函数
  281. public:
  282. //绘画扑克
  283. void DrawCardControl(CDC * pDC);
  284. //设置扑克
  285. bool SetCardData(const BYTE cbCardData[], WORD wCardCount);
  286. //控件控制
  287. public:
  288. //设置方向
  289. void SetDirection(enDirection Direction) { m_CardDirection=Direction; }
  290. //基准位置
  291. void SetControlPoint(int nXPos, int nYPos) { m_ControlPoint.SetPoint(nXPos,nYPos); }
  292. };
  293. //////////////////////////////////////////////////////////////////////////
  294. //扑克结构
  295. struct tagCardItem
  296. {
  297. bool bShoot; //弹起标志
  298. BYTE cbCardData; //扑克数据
  299. };
  300. //扑克控件
  301. class CCardControl
  302. {
  303. //状态变量
  304. protected:
  305. bool m_bPositively; //响应标志
  306. bool m_bDisplayItem; //显示标志
  307. //位置变量
  308. protected:
  309. CPoint m_BenchmarkPos; //基准位置
  310. enXCollocateMode m_XCollocateMode; //显示模式
  311. enYCollocateMode m_YCollocateMode; //显示模式
  312. //扑克数据
  313. protected:
  314. WORD m_wCardCount; //扑克数目
  315. WORD m_wHoverItem; //盘旋子项
  316. tagCardItem m_CurrentCard; //当前扑克
  317. tagCardItem m_CardItemArray[13]; //扑克数据
  318. //资源变量
  319. protected:
  320. CSize m_ControlSize; //控件大小
  321. CPoint m_ControlPoint; //控件位置
  322. //函数定义
  323. public:
  324. //构造函数
  325. CCardControl();
  326. //析构函数
  327. virtual ~CCardControl();
  328. //查询函数
  329. public:
  330. //获取扑克
  331. BYTE GetHoverCard();
  332. //获取扑克
  333. BYTE GetCurrentCard() { return m_CurrentCard.cbCardData; }
  334. //扑克控制
  335. public:
  336. //设置扑克
  337. bool SetCurrentCard(BYTE cbCardData);
  338. //设置扑克
  339. bool SetCurrentCard(tagCardItem CardItem);
  340. //设置扑克
  341. bool SetCardData(const BYTE cbCardData[], WORD wCardCount, BYTE cbCurrentCard);
  342. //设置扑克
  343. bool SetCardItem(const tagCardItem CardItemArray[], WORD wCardCount);
  344. //控件控制
  345. public:
  346. //设置响应
  347. void SetPositively(bool bPositively) { m_bPositively=bPositively; }
  348. //设置显示
  349. void SetDisplayItem(bool bDisplayItem) { m_bDisplayItem=bDisplayItem; }
  350. //基准位置
  351. void SetBenchmarkPos(int nXPos, int nYPos, enXCollocateMode XCollocateMode, enYCollocateMode YCollocateMode);
  352. //基准位置
  353. void SetBenchmarkPos(const CPoint & BenchmarkPos, enXCollocateMode XCollocateMode, enYCollocateMode YCollocateMode);
  354. //事件控制
  355. public:
  356. //绘画扑克
  357. void DrawCardControl(CDC * pDC);
  358. //光标消息
  359. bool OnEventSetCursor(CPoint Point, bool & bRePaint);
  360. //内部函数
  361. private:
  362. //索引切换
  363. WORD SwitchCardPoint(CPoint & MousePoint);
  364. };
  365. //////////////////////////////////////////////////////////////////////////
  366. //////////////////////////////////////////////////////////////////////////
  367. //变量声明
  368. //导出变量
  369. extern CCardResource g_CardResource; //扑克资源
  370. //////////////////////////////////////////////////////////////////////////
  371. #endif