Draw_Cards_Engine.cpp
上传用户:may_xy
上传日期:2007-08-09
资源大小:1519k
文件大小:24k
源码类别:

游戏

开发平台:

C/C++

  1. // Draw_Cards_Engine.cpp: implementation of the CDrawCardsEngine class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "斗地主.h"
  6. #include "MainFrm.h"
  7. #include "Game.h"
  8. #include "My_DirectInput.h"
  9. #include "my_directdraw.h"
  10. #include "Draw_Cards_Engine.h"
  11. #include "Playing_Cards.h"
  12. #ifdef _DEBUG
  13. #undef THIS_FILE
  14. static char THIS_FILE[]=__FILE__;
  15. #define new DEBUG_NEW
  16. #endif
  17. //////////////////////////////////////////////////////////////////////
  18. // Construction/Destruction
  19. //////////////////////////////////////////////////////////////////////
  20. //扑克的位置;
  21. CCardPos::CCardPos()
  22. {
  23. m_nX      = -1;       //表示没有;
  24. m_nY      = -1;
  25. m_bVisual = 1;   //表示可见;
  26. }
  27. //扑克牌布局地图结构初始化;
  28. CCardsMap::CCardsMap()
  29. {
  30. for(int i=0;i<20;i++)
  31. {
  32. Center0[i].m_nX = Center_x0 + Card_Distance1 * i;
  33. Center0[i].m_nY = Center_y0;
  34. Center1[i].m_nX = Center_x1 + Card_Distance0 * i;
  35. Center1[i].m_nY = Center_y1;
  36. Center2[i].m_nX = Center_x2 + Card_Distance2 * i;
  37. Center2[i].m_nY = Center_y2;
  38. }
  39. for(int j=0;j<20;j++)
  40. {
  41. Left0[j].m_nX = Left_x0; 
  42. Left0[j].m_nY = Left_y0 + Card_Distance0 * j;
  43. Left1[j].m_nX = Left_x1;
  44. Left1[j].m_nY = Left_y1 + Card_Distance1 * j;
  45. Left2[j].m_nX = Left_x2;
  46. Left2[j].m_nY = Left_y2 + Card_Distance2 * j;
  47. }
  48. for(int k=0;k<20;k++)
  49. {
  50. Right0[k].m_nX = Right_x0;
  51. Right0[k].m_nY = Right_y0 + Card_Distance0 * k;
  52. Right1[k].m_nX = Right_x1;
  53. Right1[k].m_nY = Right_y1 + Card_Distance1 * k;
  54. Right2[k].m_nX = Right_x2;
  55. Right2[k].m_nY = Right_y2 + Card_Distance2 * k;
  56. }
  57. m_cLordCards[0].m_nX = Lord_Card1_x;
  58. m_cLordCards[0].m_nY = Lord_Card1_y;
  59. m_cLordCards[1].m_nX = Lord_Card2_x;
  60. m_cLordCards[1].m_nY = Lord_Card2_y;
  61. m_cLordCards[2].m_nX = Lord_Card3_x;
  62. m_cLordCards[2].m_nY = Lord_Card3_y;
  63. m_cDistributeCard.m_nX = Card_x; 
  64. m_cDistributeCard.m_nY = Card_y; 
  65. m_nLordCards = 0;
  66. m_nUpCounter = 0;
  67. }
  68. //CDrawCardsEngine
  69. CDrawCardsEngine::CDrawCardsEngine():BLUE( _RGB32BIT(0,0,0,255) )
  70. {
  71. m_bVisual = FALSE;
  72. }
  73. CDrawCardsEngine::~CDrawCardsEngine()
  74. {
  75. }
  76. //渲染初始化;
  77. int CDrawCardsEngine::Init()
  78. {
  79. char* file;
  80. //14种牌从小到大的加载;
  81. //3-10
  82. char filename[50];
  83. for(int i=0;i<=7;i++)
  84. {
  85. sprintf(filename,"bmp\Cards\%d.bmp",i+3);
  86. lpddsbg_Cards[i] = pDraw->CreateSurface(Cards_Width*4,Cards_Height,0,BLUE);
  87. pDraw->BitmapToSurface(lpddsbg_Cards[i],0,0,filename,Cards_Width*4,Cards_Height);
  88. }
  89. //J
  90. file = "bmp\Cards\j.bmp";
  91. lpddsbg_Cards[8] = pDraw->CreateSurface(Cards_Width*4,Cards_Height,0,BLUE);
  92. pDraw->BitmapToSurface(lpddsbg_Cards[8],0,0,file,Cards_Width*4,Cards_Height);
  93. //Q
  94. file = "bmp\Cards\Q.bmp";
  95. lpddsbg_Cards[9] = pDraw->CreateSurface(Cards_Width*4,Cards_Height,0,BLUE);
  96. pDraw->BitmapToSurface(lpddsbg_Cards[9],0,0,file,Cards_Width*4,Cards_Height);
  97. //K
  98. file = "bmp\Cards\K.bmp";
  99. lpddsbg_Cards[10] = pDraw->CreateSurface(Cards_Width*4,Cards_Height,0,BLUE);
  100. pDraw->BitmapToSurface(lpddsbg_Cards[10],0,0,file,Cards_Width*4,Cards_Height);
  101. //A
  102. file = "bmp\Cards\A.bmp";
  103. lpddsbg_Cards[11] = pDraw->CreateSurface(Cards_Width*4,Cards_Height,0,BLUE);
  104. pDraw->BitmapToSurface(lpddsbg_Cards[11],0,0,file,Cards_Width*4,Cards_Height);
  105. //2
  106. file = "bmp\Cards\2.bmp";
  107. lpddsbg_Cards[12] = pDraw->CreateSurface(Cards_Width*4,Cards_Height,0,BLUE);
  108. pDraw->BitmapToSurface(lpddsbg_Cards[12],0,0,file,Cards_Width*4,Cards_Height);
  109. //加载百搭;
  110. file = "bmp\Cards\jokers.bmp";
  111. lpddsbg_Cards[13] = pDraw->CreateSurface(Cards_Width*2,Cards_Height,0,BLUE);
  112. pDraw->BitmapToSurface(lpddsbg_Cards[13],0,0,file,Cards_Width*2,Cards_Height);
  113. //加载扑克背面;
  114. file = "bmp\Cards\card_back1.bmp";
  115. lpddsbg_Cards[14] = pDraw->CreateSurface(Cards_Width,Cards_Height,0,BLUE);
  116. pDraw->BitmapToSurface(lpddsbg_Cards[14],0,0,file,Cards_Width,Cards_Height);
  117. return 1;
  118. }
  119. int CDrawCardsEngine::DrawCard(int x,
  120. int y,
  121. int Card_m_nColor,
  122. int Card_Value,
  123. LPDIRECTDRAWSURFACE7 lpdds_Dest ) 
  124. {
  125. lpdds_Dest->Blt(CRect(x,
  126.   y,
  127.   x+Cards_Width,
  128.   y+Cards_Height),
  129.     lpddsbg_Cards[Card_Value - 3],
  130.     CRect(Card_m_nColor*Cards_Width,
  131.   0,
  132.   Card_m_nColor*Cards_Width + Cards_Width,
  133.   Cards_Height),
  134.     DDBLT_WAIT | DDBLT_KEYSRC,
  135.     NULL);
  136. return 1;
  137. }
  138. int CDrawCardsEngine::MoveCard(int Dest_x,
  139.     int Dest_y,
  140. int Source_x,
  141. int Source_y,
  142. int Card_m_nColor,
  143. int Card_Value,
  144. int Speed) //移动速度,以象素为单位;
  145. // LPDIRECTDRAWSURFACE7 lpdds_Dest = lpddsback)
  146. {
  147. int dx,dy,dx2,dy2,x_inc,y_inc,error;
  148. int x = Source_x,y = Source_y;
  149. dx = Dest_x - Source_x;
  150. dy = Dest_y - Source_y;
  151. if(dx>=0)
  152. {
  153. x_inc = 1;
  154. }
  155. else
  156. {
  157. x_inc = -1;
  158. dx = -dx;
  159. }
  160. if(dy >= 0)
  161. {
  162. y_inc = 1;
  163. }
  164. else
  165. {
  166. y_inc = -1;
  167. dy = -dy;
  168. }
  169. dx2 = dx << 1;
  170. dy2 = dy << 1;
  171. if(dx > dy)
  172. {
  173. error = dy2 - dx;
  174. for(int i=0;i<dx;i++)
  175. {
  176. if(i%Speed == 0)
  177. {
  178. ::RedrawGame(NULL);
  179. DrawCard(x,y,Card_m_nColor,Card_Value);
  180. while (FAILED(lpddsprimary->Flip(NULL, DDFLIP_WAIT)));
  181. }
  182. if(error >= 0)
  183. {
  184. error-=dx2;
  185. y+=y_inc;
  186. }
  187. error+=dy2;
  188. x+=x_inc;
  189. }//end for~
  190. }
  191. else
  192. {
  193. error = dx2 - dy;
  194. for(int i=0;i<dy;i++)
  195. {
  196. if(i%Speed == 0)
  197. {
  198. ::RedrawGame(NULL);
  199. DrawCard(x,y,Card_m_nColor,Card_Value);
  200. while (FAILED(lpddsprimary->Flip(NULL, DDFLIP_WAIT)));
  201. }
  202. if(error >= 0)
  203. {
  204. error-=dy2;
  205. x+=x_inc;
  206. }
  207. error+=dx2;
  208. y+=y_inc;
  209. }//end for~
  210. }
  211. ::RedrawGame(NULL);
  212. DrawCard(x,y,Card_m_nColor,Card_Value);
  213. while (FAILED(lpddsprimary->Flip(NULL, DDFLIP_WAIT)));
  214. return 1;
  215. }
  216. //重新整理中间(本机)玩家的牌面;
  217. int CDrawCardsEngine::DrawCleanUp()
  218. {
  219. pCenterCards->CleanUp(); //整理牌;
  220. for(int i=0;i<pCenterCards->m_nCardsCounter;i++)
  221. {
  222. pCardsMap->Center0[i].m_bVisual = 0;
  223. }
  224. for(int j=0;j<pCenterCards->m_nCardsCounter;j++)
  225. {
  226. pCardsMap->Center0[j].m_bVisual = 1;
  227. ::RedrawGame(); //刷新;
  228. }
  229. return 1;
  230. }
  231. //发牌;
  232. int CDrawCardsEngine::Dealing()
  233. {
  234. //分牌给三个玩家;
  235. for(int i=0;i<17;i++)
  236. {
  237. //发牌给左边玩家;
  238. pLeftCards->m_cCards[i]  = g_cAllCards[i*3 + 0];
  239. MoveCard(Left_x0,
  240. pCardsMap->Left0[i].m_nY,
  241. Card_x,
  242. Card_y,
  243. 0,
  244. 17);
  245. pLeftCards->m_nCardsCounter++;
  246. //发牌给中间玩家;
  247. pCenterCards->m_cCards[i] = g_cAllCards[i*3 + 1];
  248. MoveCard(pCardsMap->Center0[i].m_nX,
  249. Center_y0,
  250. Card_x,
  251. Card_y,
  252. pCenterCards->m_cCards[i].m_nColor,
  253. pCenterCards->m_cCards[i].m_nValue,
  254. 100);
  255. pCenterCards->m_nCardsCounter++;
  256. PlaySound(MAKEINTRESOURCE(IDR_GIVE),AfxGetResourceHandle(),
  257. SND_ASYNC|SND_RESOURCE|SND_NODEFAULT );  //
  258. //发牌给右边玩家;
  259. pRightCards->m_cCards[i] = g_cAllCards[i*3 + 2];  
  260. MoveCard(Right_x0,
  261. pCardsMap->Right0[i].m_nY,
  262. Card_x,
  263. Card_y,
  264. 0,
  265. 17);
  266. pRightCards->m_nCardsCounter++;
  267. }
  268. //测试用牌;
  269. // int j;
  270. // for(j=0;j<17;j++)
  271. // {
  272. // pCenterCards->m_cCards[j].m_nValue = 3+j/4;
  273. // }
  274. /*
  275. pCenterCards->m_cCards[0].m_nValue = 4;
  276. pCenterCards->m_cCards[1].m_nValue = 4;
  277. pCenterCards->m_cCards[2].m_nValue = 4;
  278. pCenterCards->m_cCards[3].m_nValue = 4;
  279. pCenterCards->m_cCards[4].m_nValue = 8;
  280. pCenterCards->m_cCards[5].m_nValue = 8;
  281. pCenterCards->m_cCards[6].m_nValue = 8;
  282. pCenterCards->m_cCards[7].m_nValue = 8;
  283. pCenterCards->m_cCards[8].m_nValue = 11;
  284. pCenterCards->m_cCards[9].m_nValue = 11;
  285. pCenterCards->m_cCards[10].m_nValue = 11;
  286. pCenterCards->m_cCards[12].m_nValue = 11;
  287. pCenterCards->m_cCards[13].m_nValue = 3;
  288. pCenterCards->m_cCards[14].m_nValue = 3;
  289. pCenterCards->m_cCards[15].m_nValue = 3;
  290. pCenterCards->m_cCards[16].m_nValue = 3;
  291. // for(j=0;j<17;j++)
  292. // {
  293. // pRightCards->m_cCards[j].m_nValue = 4+j/4;
  294. // }
  295. */
  296. /*
  297. pRightCards->m_cCards[0].m_nValue = 3;
  298. pRightCards->m_cCards[1].m_nValue = 3;
  299. pRightCards->m_cCards[2].m_nValue = 4;
  300. pRightCards->m_cCards[3].m_nValue = 4;
  301. pRightCards->m_cCards[4].m_nValue = 5;
  302. pRightCards->m_cCards[5].m_nValue = 5;
  303. pRightCards->m_cCards[6].m_nValue = 9;
  304. pRightCards->m_cCards[7].m_nValue = 9;
  305. pRightCards->m_cCards[8].m_nValue = 9;
  306. pRightCards->m_cCards[9].m_nValue = 8;
  307. pRightCards->m_cCards[10].m_nValue = 11;
  308. pRightCards->m_cCards[11].m_nValue = 11;
  309. pRightCards->m_cCards[12].m_nValue = 13;
  310. pRightCards->m_cCards[13].m_nValue = 13;
  311. pRightCards->m_cCards[14].m_nValue = 13;
  312. pRightCards->m_cCards[15].m_nValue = 16;
  313. pRightCards->m_cCards[15].m_nColor = 0;
  314. pRightCards->m_cCards[16].m_nValue = 16;
  315. pRightCards->m_cCards[16].m_nColor = 1;
  316. */
  317. // for(j=0;j<17;j++)
  318. // {
  319. // pLeftCards->m_cCards[j].m_nValue = 7+j/4;
  320. // }
  321. // pLeftCards->m_cCards[0].m_nValue = 3;
  322. // pLeftCards->m_cCards[1].m_nValue = 3;
  323. // pLeftCards->m_cCards[12].m_nValue = 4;
  324. // pLeftCards->m_cCards[13].m_nValue = 4;
  325. //开始向上发地主牌;
  326. //第一张地主牌;
  327. PlaySound(MAKEINTRESOURCE(IDR_GIVE),AfxGetResourceHandle(),
  328. SND_ASYNC|SND_RESOURCE|SND_NODEFAULT );  //
  329. MoveCard(Lord_Card1_x,
  330. Lord_Card1_y,
  331. Card_x,
  332. Card_y,
  333. 0,
  334. 17,
  335. 50);
  336. pCardsMap->m_cLordCards[0].m_bVisual = 1;
  337. ::RedrawGame();
  338. //第二张地主牌;
  339. PlaySound(MAKEINTRESOURCE(IDR_GIVE),AfxGetResourceHandle(),
  340. SND_ASYNC|SND_RESOURCE|SND_NODEFAULT );  //
  341. MoveCard(Lord_Card2_x,
  342. Lord_Card2_y,
  343. Card_x,
  344. Card_y,
  345. 0,
  346. 17,
  347. 50);
  348. pCardsMap->m_cLordCards[1].m_bVisual = 1;
  349. ::RedrawGame();
  350. //第三张地主牌;
  351. PlaySound(MAKEINTRESOURCE(IDR_GIVE),AfxGetResourceHandle(),
  352. SND_ASYNC|SND_RESOURCE|SND_NODEFAULT );  //
  353. MoveCard(Lord_Card3_x,
  354. Lord_Card3_y,
  355. Card_x,
  356. Card_y,
  357. 0,
  358. 17,
  359. 50);
  360. pCardsMap->m_cLordCards[2].m_bVisual = 1;
  361. pCardsMap->m_cDistributeCard.m_bVisual = 0;   //让中间发的牌不可见;
  362. ::RedrawGame();
  363. DrawCleanUp();
  364. // Sleep(60000);
  365. return 1;
  366. }
  367. //发地主牌;
  368. int CDrawCardsEngine::DealingLord(int bLord)
  369. {
  370. pCardsMap->m_nLordCards = 2;
  371. ::RedrawGame();
  372. if(bLord == 0)
  373. {
  374. //发地主牌给左边玩家;
  375. //第一张;
  376. pLeftCards->m_cCards[17]  = g_cAllCards[51];  //第十八张牌;
  377. MoveCard(Left_x0,
  378.  pCardsMap->Left0[17].m_nY,
  379.  Lord_Card1_x,
  380.  Lord_Card1_y,
  381.  pLeftCards->m_cCards[17].m_nColor,
  382.  pLeftCards->m_cCards[17].m_nValue,
  383.  80);
  384. pLeftCards->m_nCardsCounter++;  //m_nCardsCounter =18
  385. PlaySound(MAKEINTRESOURCE(IDR_GIVE),AfxGetResourceHandle(),
  386. SND_ASYNC|SND_RESOURCE|SND_NODEFAULT );  //
  387. // ::Redraw_Game();
  388. //第二张;
  389. pLeftCards->m_cCards[18]  = g_cAllCards[52];
  390. MoveCard(Left_x0,
  391.  pCardsMap->Left0[18].m_nY,
  392.  Lord_Card2_x,
  393.  Lord_Card2_y,
  394.  pLeftCards->m_cCards[18].m_nColor,
  395.  pLeftCards->m_cCards[18].m_nValue,
  396.  80);
  397. pLeftCards->m_nCardsCounter++; //m_nCardsCounter =19
  398. PlaySound(MAKEINTRESOURCE(IDR_GIVE),AfxGetResourceHandle(),
  399. SND_ASYNC|SND_RESOURCE|SND_NODEFAULT );  //
  400. // ::Redraw_Game();
  401. //第三张;
  402. pLeftCards->m_cCards[19]  = g_cAllCards[53];
  403. MoveCard(Left_x0,
  404.  pCardsMap->Left0[19].m_nY,
  405.  Lord_Card3_x,
  406.  Lord_Card3_y,
  407.  pLeftCards->m_cCards[19].m_nColor,
  408.  pLeftCards->m_cCards[19].m_nValue,
  409.  80);
  410. pLeftCards->m_nCardsCounter++;  //m_nCardsCounter =20
  411. pLeftCards->m_nCardsTable[pLeftCards->m_cCards[17].m_nValue]++;
  412. pLeftCards->m_nCardsTable[pLeftCards->m_cCards[18].m_nValue]++;
  413. pLeftCards->m_nCardsTable[pLeftCards->m_cCards[19].m_nValue]++;
  414. PlaySound(MAKEINTRESOURCE(IDR_GIVE),AfxGetResourceHandle(),
  415. SND_ASYNC|SND_RESOURCE|SND_NODEFAULT );  //
  416. ::RedrawGame();
  417. }
  418. else if(bLord == 1)
  419. {
  420. //发地主牌给中间玩家;
  421. //第一张;
  422. pCenterCards->m_cCards[17]  = g_cAllCards[51];  //第十八张牌;
  423. MoveCard(pCardsMap->Center0[17].m_nX,
  424.  Center_y0,
  425.  Lord_Card1_x,
  426.  Lord_Card1_y,
  427.  pCenterCards->m_cCards[17].m_nColor,
  428.  pCenterCards->m_cCards[17].m_nValue,
  429.  80);
  430. pCenterCards->m_nCardsCounter++;  //m_nCardsCounter =18
  431. PlaySound(MAKEINTRESOURCE(IDR_GIVE),AfxGetResourceHandle(),
  432. SND_ASYNC|SND_RESOURCE|SND_NODEFAULT );  //
  433. // ::Redraw_Game();
  434. //第二张;
  435. pCenterCards->m_cCards[18]  = g_cAllCards[52];
  436. MoveCard(pCardsMap->Center0[18].m_nX,
  437.  Center_y0,
  438.  Lord_Card2_x,
  439.  Lord_Card2_y,
  440.  pCenterCards->m_cCards[18].m_nColor,
  441.  pCenterCards->m_cCards[18].m_nValue,
  442.  80);
  443. pCenterCards->m_nCardsCounter++; //m_nCardsCounter =19
  444. PlaySound(MAKEINTRESOURCE(IDR_GIVE),AfxGetResourceHandle(),
  445. SND_ASYNC|SND_RESOURCE|SND_NODEFAULT );  //
  446. // ::Redraw_Game();
  447. //第三张;
  448. pCenterCards->m_cCards[19]  = g_cAllCards[53];
  449. MoveCard(pCardsMap->Center0[19].m_nX,
  450.  Center_y0,
  451.  Lord_Card3_x,
  452.  Lord_Card3_y,
  453.  pCenterCards->m_cCards[19].m_nColor,
  454.  pCenterCards->m_cCards[19].m_nValue,
  455.  80);
  456. pCenterCards->m_nCardsCounter++;  //m_nCardsCounter =20
  457. PlaySound(MAKEINTRESOURCE(IDR_GIVE),AfxGetResourceHandle(),
  458. SND_ASYNC|SND_RESOURCE|SND_NODEFAULT );  //
  459. ::RedrawGame();
  460. //拿到地主牌后再整理一次;
  461. DrawCleanUp();
  462. }
  463. else if(bLord == 2)
  464. {
  465. //发地主牌给右边玩家;
  466. //第一张;
  467. pRightCards->m_cCards[17]  = g_cAllCards[51];  //第十八张牌;
  468. MoveCard(Right_x0,
  469.    pCardsMap->Right0[17].m_nY,
  470.  Lord_Card1_x,
  471.  Lord_Card1_y,
  472.  pRightCards->m_cCards[17].m_nColor,
  473.  pRightCards->m_cCards[17].m_nValue,
  474.  80);
  475. pRightCards->m_nCardsCounter++;  //m_nCardsCounter =18
  476. PlaySound(MAKEINTRESOURCE(IDR_GIVE),AfxGetResourceHandle(),
  477. SND_ASYNC|SND_RESOURCE|SND_NODEFAULT );  //
  478. // ::Redraw_Game();
  479. //第二张;
  480. pRightCards->m_cCards[18]  = g_cAllCards[52];
  481. MoveCard(Right_x0,
  482.  pCardsMap->Right0[18].m_nY,
  483.  Lord_Card2_x,
  484.    Lord_Card2_y,
  485.  pRightCards->m_cCards[18].m_nColor,
  486.  pRightCards->m_cCards[18].m_nValue,
  487.  80);
  488. pRightCards->m_nCardsCounter++; //m_nCardsCounter =19
  489. PlaySound(MAKEINTRESOURCE(IDR_GIVE),AfxGetResourceHandle(),
  490. SND_ASYNC|SND_RESOURCE|SND_NODEFAULT );  //
  491. // ::Redraw_Game();
  492. //第三张;
  493. pRightCards->m_cCards[19] = g_cAllCards[53];
  494. MoveCard(Right_x0,
  495.  pCardsMap->Right0[19].m_nY,
  496.  Lord_Card3_x,
  497.  Lord_Card3_y,
  498.  pRightCards->m_cCards[19].m_nColor,
  499.  pRightCards->m_cCards[19].m_nValue,
  500.  80);
  501. pRightCards->m_nCardsCounter++;  //m_nCardsCounter =20
  502. pRightCards->m_nCardsTable[pRightCards->m_cCards[17].m_nValue]++;
  503. pRightCards->m_nCardsTable[pRightCards->m_cCards[18].m_nValue]++;
  504. pRightCards->m_nCardsTable[pRightCards->m_cCards[19].m_nValue]++;
  505. PlaySound(MAKEINTRESOURCE(IDR_GIVE),AfxGetResourceHandle(),
  506. SND_ASYNC|SND_RESOURCE|SND_NODEFAULT );  //
  507. ::RedrawGame();
  508. }
  509. pLeftCards->CleanUp();
  510. pRightCards->CleanUp();
  511. ::RedrawGame();
  512. return 1;
  513. }
  514. //中间(本机)玩家出牌;
  515. int CDrawCardsEngine::CenterDiscarding()
  516. {
  517. ///检查出牌的合法性,调用CPlaying_Cards的方法;
  518. int counter = 0;
  519. pCenterCards->m_nDiscardingCounter = 0;
  520. PlaySound(MAKEINTRESOURCE(IDR_GIVE),AfxGetResourceHandle(),
  521. SND_ASYNC|SND_RESOURCE|SND_NODEFAULT );  //
  522. for(int i=0;i<pCenterCards->m_nCardsCounter;i++)
  523. {
  524. if(pCardsMap->Center0[i].m_nY == Center_y0 - Card_Up)
  525. {
  526. //移动提起的牌到刚出牌区;
  527. pCardsMap->Center0[i].m_bVisual = 0;
  528. MoveCard(pCardsMap->Center2[pCenterCards->m_nDiscardingCounter].m_nX,
  529. pCardsMap->Center2[pCenterCards->m_nDiscardingCounter].m_nY,
  530. pCardsMap->Center0[i].m_nX,
  531. pCardsMap->Center0[i].m_nY,
  532.     pCenterCards->m_cCards[i].m_nColor,
  533. pCenterCards->m_cCards[i].m_nValue,
  534. 80);
  535. pCardsMap->Center0[i].m_nY += Card_Up;
  536. pCenterCards->m_cCards[i].m_nColor = 4;   //花色为4表示已经出过牌;
  537. pCenterCards->m_cCards[i].m_nValue = 17;   //值为17表示已经出过牌;
  538. counter++;
  539. pCenterCards->m_nDiscardingCounter++;
  540. }
  541. }
  542. //将中间(本机)的牌置为可见;
  543. for(int j=0;j<pCenterCards->m_nCardsCounter;j++)
  544. {
  545. pCardsMap->Center0[j].m_bVisual = 1;
  546. }
  547. DrawCleanUp();
  548. pCenterCards->m_nCardsCounter -= counter;
  549. // pCenterCards->m_nDiscardingCounter = 0;
  550. pCardsMap->m_nUpCounter = 0;  //提起牌数为0;
  551. return 1;
  552. }
  553. //本机玩家刚出的牌从刚出牌区移动到已经出牌区;
  554. int CDrawCardsEngine::CenterBacking()
  555. {
  556. int temp_counter = pCenterCards->m_nDiscardingCounter ;
  557. PlaySound(MAKEINTRESOURCE(IDR_GIVE),AfxGetResourceHandle(),
  558. SND_RESOURCE|SND_NODEFAULT );  //
  559. for(int i=0;i<temp_counter;i++)
  560. {
  561. //移动提起的牌到刚出牌区;
  562. MoveCard(pCardsMap->Center1[pCenterCards->m_nDiscardedCounter].m_nX,
  563. pCardsMap->Center1[pCenterCards->m_nDiscardedCounter].m_nY,
  564. pCardsMap->Center2[i].m_nX,
  565. pCardsMap->Center2[i].m_nY,
  566. pCenterCards->m_cDiscarding[i].m_nColor,
  567. pCenterCards->m_cDiscarding[i].m_nValue,
  568. 100);
  569. pCenterCards->m_nDiscardingCounter--;
  570. pCenterCards->m_cDiscarded[pCenterCards->m_nDiscardedCounter] = pCenterCards->m_cDiscarding[i];
  571. pCenterCards->m_nDiscardedCounter++;
  572. }
  573. ::RedrawGame();
  574. return 1;
  575. }
  576. //左边玩家出牌;
  577. int CDrawCardsEngine::LeftDiscarding()  
  578. {
  579. int temp_counter = pLeftCards->m_nDiscardingCounter;
  580. pLeftCards->m_nDiscardingCounter = 0;
  581. PlaySound(MAKEINTRESOURCE(IDR_GIVE),AfxGetResourceHandle(),
  582. SND_ASYNC|SND_RESOURCE|SND_NODEFAULT );  //
  583. for(int i=0;i<temp_counter;i++)
  584. {
  585. //移动提起的牌到刚出牌区;
  586. MoveCard(pCardsMap->Left2[i].m_nX,
  587. pCardsMap->Left2[i].m_nY,
  588. pCardsMap->Left0[pLeftCards->m_nCardsCounter - 1].m_nX,
  589. pCardsMap->Left0[pLeftCards->m_nCardsCounter - 1].m_nY,
  590. pLeftCards->m_cDiscarding[i].m_nColor,
  591. pLeftCards->m_cDiscarding[i].m_nValue,
  592. 100);
  593. pLeftCards->m_nDiscardingCounter++;
  594. pLeftCards->m_nCardsCounter--;
  595. }
  596. // ::Redraw_Game();
  597. return 1;
  598. }
  599. //左边玩家刚出的牌从刚出牌区移动到已经出牌区;
  600. int CDrawCardsEngine::LeftBacking()
  601. {
  602. int temp_counter = pLeftCards->m_nDiscardingCounter ;
  603. PlaySound(MAKEINTRESOURCE(IDR_GIVE),AfxGetResourceHandle(),
  604. SND_ASYNC|SND_RESOURCE|SND_NODEFAULT );  //
  605. for(int i=0;i<temp_counter;i++)
  606. {
  607. //移动提起的牌到刚出牌区;
  608. MoveCard(pCardsMap->Left1[pLeftCards->m_nDiscardedCounter].m_nX,
  609. pCardsMap->Left1[pLeftCards->m_nDiscardedCounter].m_nY,
  610. pCardsMap->Left2[i].m_nX,
  611. pCardsMap->Left2[i].m_nY,
  612. pLeftCards->m_cDiscarding[i].m_nColor,
  613. pLeftCards->m_cDiscarding[i].m_nValue,
  614. 140);
  615. pLeftCards->m_nDiscardingCounter--;
  616. pLeftCards->m_cDiscarded[pLeftCards->m_nDiscardedCounter] = pLeftCards->m_cDiscarding[i];
  617. pLeftCards->m_nDiscardedCounter++;
  618. }
  619. ::RedrawGame();
  620. return 1;
  621. }
  622. //右边玩家出牌;
  623. int CDrawCardsEngine::RightDiscarding()
  624. {
  625. int temp_counter = pRightCards->m_nDiscardingCounter;
  626. pRightCards->m_nDiscardingCounter = 0;
  627. PlaySound(MAKEINTRESOURCE(IDR_GIVE),AfxGetResourceHandle(),
  628. SND_ASYNC|SND_RESOURCE|SND_NODEFAULT );  //
  629. for(int i=0;i<temp_counter;i++)
  630. {
  631. //移动提起的牌到刚出牌区;
  632. MoveCard(pCardsMap->Right2[i].m_nX,
  633. pCardsMap->Right2[i].m_nY,
  634. pCardsMap->Right0[pRightCards->m_nCardsCounter - 1].m_nX,
  635. pCardsMap->Right0[pRightCards->m_nCardsCounter - 1].m_nY,
  636. pRightCards->m_cDiscarding[i].m_nColor,
  637. pRightCards->m_cDiscarding[i].m_nValue,
  638. 100);
  639. pRightCards->m_nDiscardingCounter++;
  640. pRightCards->m_nCardsCounter--;
  641. }
  642. return 1;
  643. }
  644. //右边玩家刚出的牌从刚出牌区移动到已经出牌区;
  645. int CDrawCardsEngine::RightBacking()
  646. {
  647. int temp_counter = pRightCards->m_nDiscardingCounter ;
  648. PlaySound(MAKEINTRESOURCE(IDR_GIVE),AfxGetResourceHandle(),
  649. SND_ASYNC|SND_RESOURCE|SND_NODEFAULT );  //
  650. for(int i=0;i<temp_counter;i++)
  651. {
  652. //移动提起的牌到刚出牌区;
  653. MoveCard(pCardsMap->Right1[pLeftCards->m_nDiscardedCounter].m_nX,
  654. pCardsMap->Right1[pLeftCards->m_nDiscardedCounter].m_nY,
  655. pCardsMap->Right2[i].m_nX,
  656. pCardsMap->Right2[i].m_nY,
  657. pRightCards->m_cDiscarding[i].m_nColor,
  658. pRightCards->m_cDiscarding[i].m_nValue,
  659. 140);
  660. pRightCards->m_nDiscardingCounter--;
  661. pRightCards->m_cDiscarded[pRightCards->m_nDiscardedCounter] = pRightCards->m_cDiscarding[i];
  662. pRightCards->m_nDiscardedCounter++;
  663. }
  664. ::RedrawGame();
  665. return 1;
  666. }
  667. //重画;
  668. void CDrawCardsEngine::Redraw(LPDIRECTDRAWSURFACE7  pSurface)
  669. {
  670. //左边未出的牌;
  671. int i;
  672. if( m_bVisual )
  673. {
  674. for(i=0;i<pLeftCards->m_nCardsCounter;i++)
  675. {
  676. if(pCardsMap->Left0[i].m_bVisual == 1)
  677. {
  678. DrawCard(pCardsMap->Left0[i].m_nX,
  679.  pCardsMap->Left0[i].m_nY,
  680.  pLeftCards->m_cCards[i].m_nColor,
  681.  pLeftCards->m_cCards[i].m_nValue);
  682. }
  683. }
  684. }
  685. else//
  686. {
  687. for(i=0;i<pLeftCards->m_nCardsCounter;i++)
  688. {
  689. if(pCardsMap->Left0[i].m_bVisual == 1)
  690. {
  691. DrawCard(pCardsMap->Left0[i].m_nX,
  692.  pCardsMap->Left0[i].m_nY,
  693.  0,
  694.  17);
  695. }
  696. }
  697. }
  698. //左边已经出的牌;
  699. for(i=0;i<pLeftCards->m_nDiscardedCounter;i++)
  700. {
  701. if(pCardsMap->Left1[i].m_bVisual == 1)
  702. {
  703. DrawCard(pCardsMap->Left1[i].m_nX,
  704.  pCardsMap->Left1[i].m_nY,
  705.  pLeftCards->m_cDiscarded[i].m_nColor,
  706.  pLeftCards->m_cDiscarded[i].m_nValue);
  707. }
  708. }
  709. //左边刚出的牌;
  710. for(i=0;i<pLeftCards->m_nDiscardingCounter;i++)
  711. {
  712. if(pCardsMap->Left2[i].m_bVisual == 1)
  713. {
  714. DrawCard(pCardsMap->Left2[i].m_nX,
  715.  pCardsMap->Left2[i].m_nY,
  716.  pLeftCards->m_cDiscarding[i].m_nColor,
  717.  pLeftCards->m_cDiscarding[i].m_nValue);
  718. }
  719. }
  720. //中间未出的牌;
  721. for(i=0;i<pCenterCards->m_nCardsCounter;i++)
  722. {
  723. if(pCardsMap->Center0[i].m_bVisual == 1)
  724. {
  725. DrawCard(pCardsMap->Center0[i].m_nX,
  726. pCardsMap->Center0[i].m_nY,
  727. pCenterCards->m_cCards[i].m_nColor,
  728. pCenterCards->m_cCards[i].m_nValue);
  729. }
  730. }
  731. //中间已经出的牌;
  732. for(i=0;i<pCenterCards->m_nDiscardedCounter;i++)
  733. {
  734. if(pCardsMap->Center1[i].m_bVisual == 1)
  735. {
  736. DrawCard(pCardsMap->Center1[i].m_nX,
  737.  pCardsMap->Center1[i].m_nY,
  738.  pCenterCards->m_cDiscarded[i].m_nColor,
  739.  pCenterCards->m_cDiscarded[i].m_nValue);
  740. }
  741. }
  742. //中间刚出的牌;
  743. for(i=0;i<pCenterCards->m_nDiscardingCounter;i++)
  744. {
  745. if(pCardsMap->Center2[i].m_bVisual == 1)
  746. {
  747. DrawCard(pCardsMap->Center2[i].m_nX,
  748.  pCardsMap->Center2[i].m_nY,
  749.  pCenterCards->m_cDiscarding[i].m_nColor,
  750.  pCenterCards->m_cDiscarding[i].m_nValue);
  751. }
  752. }
  753. //右边未出的牌;
  754. if( m_bVisual )
  755. {
  756. for(i=0;i<pRightCards->m_nCardsCounter;i++)
  757. {
  758. if(pCardsMap->Right0[i].m_bVisual == 1)
  759. {
  760. DrawCard(pCardsMap->Right0[i].m_nX,
  761.  pCardsMap->Right0[i].m_nY,
  762.  pRightCards->m_cCards[i].m_nColor,
  763.  pRightCards->m_cCards[i].m_nValue);
  764. }
  765. }
  766. }
  767. else
  768. {
  769. for(i=0;i<pRightCards->m_nCardsCounter;i++)
  770. {
  771. if(pCardsMap->Right0[i].m_bVisual == 1)
  772. {
  773. DrawCard(pCardsMap->Right0[i].m_nX,
  774.  pCardsMap->Right0[i].m_nY,
  775.  0,
  776.  17);
  777. }
  778. }
  779. }
  780. //右边已经出的牌;
  781. for(i=0;i<pRightCards->m_nDiscardedCounter;i++)
  782. {
  783. if(pCardsMap->Right1[i].m_bVisual == 1)
  784. {
  785. DrawCard(pCardsMap->Right1[i].m_nX,
  786.  pCardsMap->Right1[i].m_nY,
  787.  pRightCards->m_cDiscarded[i].m_nColor,
  788.  pRightCards->m_cDiscarded[i].m_nValue);
  789. }
  790. }
  791. //右边刚出的牌;
  792. for(i=0;i<pRightCards->m_nDiscardingCounter;i++)
  793. {
  794. if(pCardsMap->Right2[i].m_bVisual == 1)
  795. {
  796. DrawCard(pCardsMap->Right2[i].m_nX,
  797.  pCardsMap->Right2[i].m_nY,
  798.  pRightCards->m_cDiscarding[i].m_nColor,
  799.  pRightCards->m_cDiscarding[i].m_nValue);
  800. }
  801. }
  802. //正在发的牌;
  803. if(pCardsMap->m_cDistributeCard.m_bVisual == 1)
  804. {
  805. DrawCard(pCardsMap->m_cDistributeCard.m_nX,
  806.  pCardsMap->m_cDistributeCard.m_nY,
  807.  0,
  808.  17);
  809. }
  810. //陈列的三张地主牌;
  811. if(pCardsMap->m_nLordCards == 1)
  812. {
  813. for(i=0;i<3;i++)
  814. {
  815. if(pCardsMap->m_cLordCards[i].m_bVisual == 1)
  816. {
  817. DrawCard(pCardsMap->m_cLordCards[i].m_nX,
  818.  pCardsMap->m_cLordCards[i].m_nY,
  819.      0,
  820.  17);
  821. }
  822. }//end for
  823. }
  824. else if(pCardsMap->m_nLordCards == 2)
  825. {
  826. for(i=0;i<3;i++)
  827. {
  828. if(pCardsMap->m_cLordCards[i].m_bVisual == 1)
  829. {
  830. DrawCard(pCardsMap->m_cLordCards[i].m_nX,
  831.  pCardsMap->m_cLordCards[i].m_nY,
  832.  ::g_cAllCards[51+i].m_nColor,
  833.  ::g_cAllCards[51+i].m_nValue);
  834. }
  835. }//end for
  836. }
  837. }