Tzq.cpp
上传用户:hlqcw8
上传日期:2007-01-08
资源大小:438k
文件大小:21k
源码类别:

棋牌游戏

开发平台:

Visual C++

  1. // Tzq.cpp: implementation of the CTzq class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "ttq.h"
  6. #include "Tzq.h"
  7. #include "stdio.h"
  8. #ifdef _DEBUG
  9. #undef THIS_FILE
  10. static char THIS_FILE[]=__FILE__;
  11. #define new DEBUG_NEW
  12. #endif
  13. //////////////////////////////////////////////////////////////////////
  14. // Construction/Destruction
  15. //////////////////////////////////////////////////////////////////////
  16. CTzq::CTzq()
  17. {
  18. nPlaySyst=0;
  19. pPlace=NULL;
  20. BeginGame=FALSE;
  21. // memset(aPlace,0,sizeof(aPlace));
  22. for(int i=0;i<6;i++){
  23. for(int j=0;j<10;j++)
  24. {
  25. aPlace[i][j].pTzq=NULL;
  26. aPlace[i][j].nTestUD=0;
  27. }
  28. nPlayType[i]=0;
  29. // nPlayYN[6]=FALSE;
  30. }
  31. memset(aTzqFull,0,sizeof(aTzqFull));
  32. srand( (unsigned)time( NULL ) );
  33. SetTF_nQz(); //初始化aTzqFull数组 nQz;
  34. SetTF_nxy(); //初始化aTzqFull数组 n_x,n_y;
  35. SetTF_pTzq(); //初始化aTzqFull数组 pTzq
  36. SetTF_nPRI(); //初始化aTzqFull数组 nPRI;
  37. SetPlace();             //初始化aPlace数组;
  38. SetTF_nArea(); //初始化aTzqFull数组 nArea;
  39. SetTF_nColor(); //初始化aTzqFull数组 nColor;
  40. for(qzc=0;qzc<6;qzc++)
  41. ChessFull();
  42. }
  43. CTzq::SetTF_nxy()
  44. {
  45. int temp1[18]={1,2,4,7,11,24,36,47,57,66,76,87,99,112,116,119,121,122};
  46. int temp2[18]={0,220,204,188,172,28,44,60,76,92,76,
  47. 60,44,28,172,188,204,220};
  48. int tab,tae=1;
  49. int tyt=30,txt;
  50. // int ttt1;
  51. for(int tj=1;tj<18;tj++){
  52. tab=tae;
  53. tae=temp1[tj];
  54. txt=temp2[tj];
  55. // ttt1=0;
  56. for(int tj1=tab;tj1<tae;tj1++)
  57. {
  58. // ttt1++;
  59. this->aTzqFull[tj1].n_x=txt;
  60. this->aTzqFull[tj1].n_y=tyt;
  61. txt=txt+32;
  62. }
  63. tyt=(int)(tj*27.5)+30;
  64. }
  65. }
  66. CTzq::SetTF_nArea()
  67. {
  68. for(int i=0;i<6;i++)
  69. {
  70. for(int i1=0;i1<10;i1++)
  71. this->aPlace[i][i1].pTzq->nArea=i+1;
  72. }
  73. }
  74. CTzq::SetTF_nColor()
  75. {
  76. for(int i=0;i<6;i++)
  77. {
  78. if(nPlayType[i]!=0)
  79. for(int i1=0;i1<10;i1++)
  80. this->aPlace[i][i1].pTzq->nColor=i+1;
  81. }
  82. }
  83. CTzq::SetTF_nPRI()
  84. {
  85. TzqDate *pTzqDate;
  86. TzqDate *pTzqTemp;
  87. int ntemp[6]={1,11,99,121,111,23};
  88. for(int i=0;i<3;i++){
  89. pTzqDate=&aTzqFull[ntemp[i]];
  90. for(int ni=1;ni<14;ni++)
  91. {
  92. pTzqTemp=pTzqDate;
  93. pTzqTemp->nPRI[i]=ni;
  94. pTzqTemp->nPRI[i+3]=18-ni;
  95. while(pTzqTemp->pTzq[i+2])
  96. {
  97. pTzqTemp=pTzqTemp->pTzq[i+2];
  98. pTzqTemp->nPRI[i]=ni;
  99. pTzqTemp->nPRI[i+3]=18-ni;
  100. }
  101. pTzqTemp=pTzqDate;
  102. pTzqTemp->nPRI[i]=ni;
  103. pTzqTemp->nPRI[i+3]=18-ni;
  104. while(pTzqTemp->pTzq[(i+5)%6])
  105. {
  106. pTzqTemp=pTzqTemp->pTzq[(i+5)%6];
  107. pTzqTemp->nPRI[i]=ni;
  108. pTzqTemp->nPRI[i+3]=18-ni;
  109. }
  110. pTzqDate=pTzqDate->pTzq[i+3];
  111. }
  112. pTzqDate=&aTzqFull[ntemp[i+3]];
  113. for(ni=1;ni<14;ni++)
  114. {
  115. pTzqTemp=pTzqDate;
  116. pTzqTemp->nPRI[i+3]=ni;
  117. pTzqTemp->nPRI[i]=18-ni;
  118. while(pTzqTemp->pTzq[i+2])
  119. {
  120. pTzqTemp=pTzqTemp->pTzq[i+2];
  121. pTzqTemp->nPRI[i+3]=ni;
  122. pTzqTemp->nPRI[i]=18-ni;
  123. }
  124. pTzqTemp=pTzqDate;
  125. pTzqTemp->nPRI[i+3]=ni;
  126. pTzqTemp->nPRI[i]=18-ni;
  127. while(pTzqTemp->pTzq[(i+5)%6])
  128. {
  129. pTzqTemp=pTzqTemp->pTzq[(i+5)%6];
  130. pTzqTemp->nPRI[i+3]=ni;
  131. pTzqTemp->nPRI[i]=18-ni;
  132. }
  133. pTzqDate=pTzqDate->pTzq[i];
  134. }
  135. }
  136. }
  137. CTzq::SetTF_nQz()
  138. {
  139. for(int i=0;i<122;i++)
  140. aTzqFull[i].nQz=i;
  141. }
  142. CTzq::SetTF_pTzq()
  143. {
  144. int temp[6][121]={                      
  145. 0,                     
  146. 1, 0,                   
  147. 2,  3,  0,                  
  148. 4,  5,  6,  0, 
  149. 0,  0,  0,  0,  7,  8,  9, 10,  0,  0,  0,  0,  0,
  150. 12,13,14,15,16,17,18,19,20,21,22,23,
  151. 25,26,27,28,29,30,31,32,33,34,35,
  152. 37,38,39,40,41,42,43,44,45,46,
  153. 48,49,50,51,52,53,54,55,56,
  154. 57,58,59,60,61,62,63,64,65,0,
  155. 66,67,68,69,70,71,72,73,74,75,0,
  156. 76,77,78,79,80,81,82,83,84,85,86,0,
  157. 87,88,89,90,91,92,93,94,95,96,97,98,0,
  158. 104,105,106,107,
  159. 113,114,115,
  160. 117,118,
  161. 120
  162. ,0,
  163. 0,1,
  164. 0,2,3,
  165. 0,4,5,6,
  166. 0,0,0,0,0,7,8,9,10,0,0,0,0,
  167. 11,12,13,14,15,16,17,18,19,20,21,22,
  168. 24,25,26,27,28,29,30,31,32,33,34,
  169. 36,37,38,39,40,41,42,43,44,45,
  170. 47,48,49,50,51,52,53,54,55,
  171. 0,57,58,59,60,61,62,63,64,65,
  172. 0,66,67,68,69,70,71,72,73,74,75,
  173. 0,76,77,78,79,80,81,82,83,84,85,86,
  174. 0,87,88,89,90,91,92,93,94,95,96,97,98,
  175. 103,104,105,106,
  176. 112,113,114,
  177. 116,117,
  178. 119
  179. ,
  180. 0,
  181. 0,2,
  182. 0,4,5,
  183. 0,7,8,9,
  184. 0,11,12,13,14,15,16,17,18,19,20,21,22,
  185. 0,24,25,26,27,28,29,30,31,32,33,34,
  186. 0,36,37,38,39,40,41,42,43,44,45,
  187. 0,47,48,49,50,51,52,53,54,55,
  188. 0,57,58,59,60,61,62,63,64,
  189. 0,66,67,68,69,70,71,72,73,74,
  190. 0,76,77,78,79,80,81,82,83,84,85,
  191. 0,87,88,89,90,91,92,93,94,95,96,97,
  192. 0,99,100,101,102,103,104,105,106,107,108,109,110,
  193. 0,112,113,114,
  194. 0,116,117,
  195. 0,119,
  196. 0
  197. ,
  198. 2,
  199. 4,5,
  200. 7,8,9,
  201. 15,16,17,18,
  202. 0,24,25,26,27,28,29,30,31,32,33,34,35,
  203. 0,36,37,38,39,40,41,42,43,44,45,46,
  204. 0,47,48,49,50,51,52,53,54,55,56,
  205. 0,57,58,59,60,61,62,63,64,65,
  206. 66,67,68,69,70,71,72,73,74,
  207. 76,77,78,79,80,81,82,83,84,85,
  208. 87,88,89,90,91,92,93,94,95,96,97,
  209. 99,100,101,102,103,104,105,106,107,108,109,110,
  210. 0,0,0,0,0,112,113,114,115,0,0,0,0,
  211. 0,116,117,118,
  212. 0,119,120,
  213. 0,121,
  214. 0
  215. ,
  216. 3,
  217. 5,6,
  218. 8,9,10,
  219. 16,17,18,19,
  220. 24,25,26,27,28,29,30,31,32,33,34,35,0,
  221. 36,37,38,39,40,41,42,43,44,45,46,0,
  222. 47,48,49,50,51,52,53,54,55,56,0,
  223. 57,58,59,60,61,62,63,64,65,0,
  224. 67,68,69,70,71,72,73,74,75,
  225. 77,78,79,80,81,82,83,84,85,86,
  226. 88,89,90,91,92,93,94,95,96,97,98,
  227. 100,101,102,103,104,105,106,107,108,109,110,111,
  228. 0,0,0,0,112,113,114,115,0,0,0,0,0,
  229. 116,117,118,0,
  230. 119,120,0,
  231. 121,0,
  232. 0
  233. ,
  234. 0,
  235. 3,0,
  236. 5,6,0,
  237. 8,9,10,0,
  238. 12,13,14,15,16,17,18,19,20,21,22,23,0,
  239. 25,26,27,28,29,30,31,32,33,34,35,0,
  240. 37,38,39,40,41,42,43,44,45,46,0,
  241. 48,49,50,51,52,53,54,55,56,0,
  242. 58,59,60,61,62,63,64,65,0,
  243. 67,68,69,70,71,72,73,74,75,0,
  244. 77,78,79,80,81,82,83,84,85,86,0,
  245. 88,89,90,91,92,93,94,95,96,97,98,0,
  246. 100,101,102,103,104,105,106,107,108,109,110,111,0,
  247. 113,114,115,0,
  248. 117,118,0,
  249. 120,0,
  250. 0};
  251. for(int tttr=1;tttr<122;tttr++){
  252. for(int zz3=0;zz3<6;zz3++)
  253. { if(temp[zz3][tttr-1])
  254. this->aTzqFull[tttr].pTzq[zz3]=&aTzqFull[temp[zz3][tttr-1]];
  255. }
  256. }
  257. }
  258. CTzq::SetPlace()
  259. {
  260. int aset[6][10]={
  261. 1,2,3,4,5,6,7,8,9,10,
  262. 11,12,13,14,24,25,26,36,37,47,
  263. 66,76,77,87,88,89,99,100,101,102,
  264. 112,113,114,115,116,117,118,119,120,121,
  265. 75,85,86,96,97,98,108,109,110,111,
  266. 20,21,22,23,33,34,35,45,46,56
  267. };
  268. for(int aseti=0;aseti<10;aseti++)
  269. {
  270. for(int aseti1=0;aseti1<6;aseti1++)
  271. aPlace[aseti1][aseti].pTzq=&aTzqFull[aset[aseti1][aseti]];
  272. }
  273. }
  274. CTzq::~CTzq()
  275. {
  276. }
  277. HBITMAP hBmp,hbmmp;
  278. HRGN BitmapToRegion (HBITMAP hBmp, COLORREF cTransparentColor = 0, COLORREF cTolerance = 0x101010)
  279. {
  280. HRGN hRgn = NULL;
  281. if (hBmp)
  282. {
  283. // Create a memory DC inside which we will scan the bitmap content
  284. HDC hMemDC = CreateCompatibleDC(NULL);
  285. if (hMemDC)
  286. {
  287. // Get bitmap size
  288. BITMAP bm;
  289. GetObject(hBmp, sizeof(bm), &bm);
  290. // Create a 32 bits depth bitmap and select it into the memory DC 
  291. BITMAPINFOHEADER RGB32BITSBITMAPINFO = {
  292. sizeof(BITMAPINFOHEADER), // biSize 
  293. bm.bmWidth, // biWidth; 
  294. bm.bmHeight, // biHeight; 
  295. 1, // biPlanes; 
  296. 32, // biBitCount 
  297. BI_RGB, // biCompression; 
  298. 0, // biSizeImage; 
  299. 0, // biXPelsPerMeter; 
  300. 0, // biYPelsPerMeter; 
  301. 0, // biClrUsed; 
  302. 0 // biClrImportant; 
  303. };
  304. VOID * pbits32; 
  305. HBITMAP hbm32 = CreateDIBSection(hMemDC, (BITMAPINFO *)&RGB32BITSBITMAPINFO, DIB_RGB_COLORS, &pbits32, NULL, 0);
  306. if (hbm32)
  307. {
  308. HBITMAP holdBmp = (HBITMAP)SelectObject(hMemDC, hbm32);
  309. // Create a DC just to copy the bitmap into the memory DC
  310. HDC hDC = CreateCompatibleDC(hMemDC);
  311. if (hDC)
  312. {
  313. // Get how many bytes per row we have for the bitmap bits (rounded up to 32 bits)
  314. BITMAP bm32;
  315. GetObject(hbm32, sizeof(bm32), &bm32);
  316. while (bm32.bmWidthBytes % 4)
  317. bm32.bmWidthBytes++;
  318. // Copy the bitmap into the memory DC
  319. HBITMAP holdBmp = (HBITMAP)SelectObject(hDC, hBmp);
  320. BitBlt(hMemDC, 0, 0, bm.bmWidth, bm.bmHeight, hDC, 0, 0, SRCCOPY);
  321. // For better performances, we will use the ExtCreateRegion() function to create the
  322. // region. This function take a RGNDATA structure on entry. We will add rectangles by
  323. // amount of ALLOC_UNIT number in this structure.
  324. #define ALLOC_UNIT 100
  325. DWORD maxRects = ALLOC_UNIT;
  326. HANDLE hData = GlobalAlloc(GMEM_MOVEABLE, sizeof(RGNDATAHEADER) + (sizeof(RECT) * maxRects));
  327. RGNDATA *pData = (RGNDATA *)GlobalLock(hData);
  328. pData->rdh.dwSize = sizeof(RGNDATAHEADER);
  329. pData->rdh.iType = RDH_RECTANGLES;
  330. pData->rdh.nCount = pData->rdh.nRgnSize = 0;
  331. SetRect(&pData->rdh.rcBound, MAXLONG, MAXLONG, 0, 0);
  332. // Keep on hand highest and lowest values for the "transparent" pixels
  333. BYTE lr = GetRValue(cTransparentColor);
  334. BYTE lg = GetGValue(cTransparentColor);
  335. BYTE lb = GetBValue(cTransparentColor);
  336. BYTE hr = min(0xff, lr + GetRValue(cTolerance));
  337. BYTE hg = min(0xff, lg + GetGValue(cTolerance));
  338. BYTE hb = min(0xff, lb + GetBValue(cTolerance));
  339. // Scan each bitmap row from bottom to top (the bitmap is inverted vertically)
  340. BYTE *p32 = (BYTE *)bm32.bmBits + (bm32.bmHeight - 1) * bm32.bmWidthBytes;
  341. for (int y = 0; y < bm.bmHeight; y++)
  342. {
  343. // Scan each bitmap pixel from left to right
  344. for (int x = 0; x < bm.bmWidth; x++)
  345. {
  346. // Search for a continuous range of "non transparent pixels"
  347. int x0 = x;
  348. LONG *p = (LONG *)p32 + x;
  349. while (x < bm.bmWidth)
  350. {
  351. BYTE b = GetRValue(*p);
  352. if (b >= lr && b <= hr)
  353. {
  354. b = GetGValue(*p);
  355. if (b >= lg && b <= hg)
  356. {
  357. b = GetBValue(*p);
  358. if (b >= lb && b <= hb)
  359. // This pixel is "transparent"
  360. break;
  361. }
  362. }
  363. p++;
  364. x++;
  365. }
  366. if (x > x0)
  367. {
  368. // Add the pixels (x0, y) to (x, y+1) as a new rectangle in the region
  369. if (pData->rdh.nCount >= maxRects)
  370. {
  371. GlobalUnlock(hData);
  372. maxRects += ALLOC_UNIT;
  373. hData = GlobalReAlloc(hData, sizeof(RGNDATAHEADER) + (sizeof(RECT) * maxRects), GMEM_MOVEABLE);
  374. pData = (RGNDATA *)GlobalLock(hData);
  375. }
  376. RECT *pr = (RECT *)&pData->Buffer;
  377. SetRect(&pr[pData->rdh.nCount], x0, y, x, y+1);
  378. if (x0 < pData->rdh.rcBound.left)
  379. pData->rdh.rcBound.left = x0;
  380. if (y < pData->rdh.rcBound.top)
  381. pData->rdh.rcBound.top = y;
  382. if (x > pData->rdh.rcBound.right)
  383. pData->rdh.rcBound.right = x;
  384. if (y+1 > pData->rdh.rcBound.bottom)
  385. pData->rdh.rcBound.bottom = y+1;
  386. pData->rdh.nCount++;
  387. // On Windows98, ExtCreateRegion() may fail if the number of rectangles is too
  388. // large (ie: > 4000). Therefore, we have to create the region by multiple steps.
  389. if (pData->rdh.nCount == 2000)
  390. {
  391. HRGN h = ExtCreateRegion(NULL, sizeof(RGNDATAHEADER) + (sizeof(RECT) * maxRects), pData);
  392. if (hRgn)
  393. {
  394. CombineRgn(hRgn, hRgn, h, RGN_OR);
  395. DeleteObject(h);
  396. }
  397. else
  398. hRgn = h;
  399. pData->rdh.nCount = 0;
  400. SetRect(&pData->rdh.rcBound, MAXLONG, MAXLONG, 0, 0);
  401. }
  402. }
  403. }
  404. // Go to next row (remember, the bitmap is inverted vertically)
  405. p32 -= bm32.bmWidthBytes;
  406. }
  407. // Create or extend the region with the remaining rectangles
  408. HRGN h = ExtCreateRegion(NULL, sizeof(RGNDATAHEADER) + (sizeof(RECT) * maxRects), pData);
  409. if (hRgn)
  410. {
  411. CombineRgn(hRgn, hRgn, h, RGN_OR);
  412. DeleteObject(h);
  413. }
  414. else
  415. hRgn = h;
  416. // Clean up
  417. SelectObject(hDC, holdBmp);
  418. DeleteDC(hDC);
  419. }
  420. DeleteObject(SelectObject(hMemDC, holdBmp));
  421. }
  422. DeleteDC(hMemDC);
  423. }
  424. }
  425. return hRgn;
  426. }
  427. CTzq::Chess(TzqDate *pTF)
  428. {
  429. for(int i1=0;i1<6;i1++)
  430. ChessOdd(pTF,i1);
  431. }
  432. void CTzq::ChessOdd(TzqDate *pTF, int i1)
  433. {
  434. int it,ht,ii;
  435. TzqDate *pb;
  436. pb=pTF;
  437. ii=0;
  438. it=0;
  439. ht=0;
  440. while(pb->pTzq[i1])
  441. {
  442. pb=pb->pTzq[i1];
  443. if(it==0)
  444. {
  445. if(pb->nColor==0)
  446. ii++;
  447. else 
  448. it=1;
  449. }
  450. else
  451. {
  452. if(ii==0)
  453. {
  454. if(pb->nColor==0)
  455. {
  456. Addpa(pb);
  457. return ;
  458. }
  459. else
  460. return ;
  461. }
  462. else
  463. {
  464. if(pb->nColor==0)
  465. ii--;
  466. else
  467. return ;
  468. }
  469. }
  470. }
  471. }
  472. void CTzq::Addpa(TzqDate *pTF)
  473. {
  474. TzqDate *pb=pTF;
  475. int z=aPlace[qzc][qz].nPlaceArray.GetSize();
  476. for(int i=0;i<z;i++)
  477. {
  478. if(pb->nQz==aPlace[qzc][qz].nPlaceArray[i])
  479. return ;
  480. }
  481. aPlace[qzc][qz].nPlaceArray.Add(pb->nQz);
  482. Chess(pb);
  483. }
  484. CTzq::ChessFull()
  485. {
  486. int j;
  487. for (qz=0;qz<10;qz++)
  488. {
  489. aPlace[qzc][qz].nPlaceArray.RemoveAll();
  490. j=aPlace[qzc][qz].pTzq->nColor;
  491. aPlace[qzc][qz].pTzq->nColor=0;
  492. aPlace[qzc][qz].nPlaceArray.Add(aPlace[qzc][qz].pTzq->nQz);
  493. this->Chess(aPlace[qzc][qz].pTzq);
  494. this->BsetSide(aPlace[qzc][qz].pTzq);
  495. CArray<int,int> yjj;
  496. for(int iz=1;iz<aPlace[qzc][qz].nPlaceArray.GetSize();iz++)
  497. yjj.Add(aPlace[qzc][qz].nPlaceArray[iz]);
  498. aPlace[qzc][qz].nPlaceArray.RemoveAll();
  499. for( iz=0;iz<yjj.GetSize();iz++)
  500. aPlace[qzc][qz].nPlaceArray.Add(yjj[iz]);
  501. aPlace[qzc][qz].pTzq->nColor=j;
  502. }
  503. }
  504. void CTzq::BsetSide(TzqDate *dp)
  505. {
  506. for (int i=0;i<6;i++)
  507. {
  508. if(dp->pTzq[i]!=NULL)
  509. if(dp->pTzq[i]->nColor==0)
  510. aPlace[qzc][qz].nPlaceArray.Add(dp->pTzq[i]->nQz);
  511. }
  512. }
  513. void CTzq::NewGame()
  514. {
  515. pPlace=NULL;
  516. BeginGame=FALSE;
  517. pPlace=NULL;
  518. for(int i=0;i<6;i++){
  519. for(int j=0;j<10;j++)
  520. {
  521. aPlace[i][j].pTzq=NULL;
  522. aPlace[i][j].nTestUD=0;
  523. }
  524. nPlayType[i]=0;
  525. // nPlayYN[6]=FALSE;
  526. }
  527. memset(aTzqFull,0,sizeof(aTzqFull));
  528. srand( (unsigned)time( NULL ) );
  529. SetTF_nQz(); //初始化aTzqFull数组 nQz;
  530. SetTF_nxy(); //初始化aTzqFull数组 n_x,n_y;
  531. SetTF_pTzq(); //初始化aTzqFull数组 pTzq
  532. SetTF_nPRI(); //初始化aTzqFull数组 nPRI;
  533. SetPlace();             //初始化aPlace数组;
  534. SetTF_nArea(); //初始化aTzqFull数组 nArea;
  535. SetTF_nColor(); //初始化aTzqFull数组 nColor;
  536. for(qzc=0;qzc<6;qzc++)
  537. ChessFull();
  538. }
  539. CTzq::GameStep()
  540. {
  541. m_cwnd->InvalidateRect(CRect(375,40,405,70),FALSE);
  542. if(nPlayType[nPlaySyst]!=0)
  543. switch(nPlayType[nPlaySyst])
  544. {
  545. case 1:
  546. break;
  547. case 2:
  548. this->pcstep();
  549. break;
  550. case 3:
  551. this->NetStep();
  552. break;
  553. default:
  554. break;
  555. }
  556. }
  557. CTzq::pcstep()
  558. {
  559. /* int nfff=0;
  560. int ntend,ntt1,ntt2,ntt3,ntt4;
  561. int tempqzz;
  562. ntend=nPlaySyst+3;
  563. if(ntend>5)
  564. ntend=nPlaySyst-3;
  565. for(int nabqq=0;nabqq<10;nabqq++)
  566. {
  567. if(aPlace[nPlaySyst][nabqq].pTzq->nArea==ntend+1)
  568. nfff++;
  569. else
  570. tempqzz=nabqq;
  571. }
  572. if(nfff==9){
  573. CString yj;
  574. yj+="下完!!!";
  575. m_cwnd->MessageBox(yj,"跳子棋");
  576. // if(aPlace[nPlaySyst][tempqzz].pTzq->pTzq[ntend]
  577. ntt1=nPlaySyst+2;
  578. ntt2=nPlaySyst+3;
  579. ntt3=nPlaySyst+4;
  580. ntt4=nPlaySyst+5;
  581. ntt1%=6;
  582. ntt2%=6;
  583. ntt3%=6;
  584. ntt4%=6;
  585. TzqDate * tzqdatetemp=aPlace[nPlaySyst][tempqzz].pTzq;
  586. if(tzqdatetemp->pTzq[ntt2]!=NULL)
  587. {
  588. if((tzqdatetemp->pTzq[ntt2]->nArea==ntend+1)&&
  589. (tzqdatetemp->pTzq[ntt2]->nColor==0))
  590. {
  591. TzqDate *temp;
  592. temp=aPlace[nPlaySyst][tempqzz].pTzq;
  593. aPlace[nPlaySyst][tempqzz].pTzq->nColor=0;
  594. aPlace[nPlaySyst][tempqzz].pTzq=tzqdatetemp->pTzq[ntt2];
  595. aPlace[nPlaySyst][tempqzz].pTzq->nColor=nPlaySyst+1;
  596. this->renovate(temp,aPlace[nPlaySyst][tempqzz].pTzq);
  597. return 0;
  598. }
  599. }
  600. if(tzqdatetemp->pTzq[ntt3]!=NULL)
  601. {
  602. if((tzqdatetemp->pTzq[ntt3]->nArea==ntend+1)&&
  603. (tzqdatetemp->pTzq[ntt3]->nColor==0))
  604. {
  605. TzqDate *temp;
  606. temp=aPlace[nPlaySyst][tempqzz].pTzq;
  607. aPlace[nPlaySyst][tempqzz].pTzq->nColor=0;
  608. aPlace[nPlaySyst][tempqzz].pTzq=tzqdatetemp->pTzq[ntt3];
  609. aPlace[nPlaySyst][tempqzz].pTzq->nColor=nPlaySyst+1;
  610. this->renovate(temp,aPlace[nPlaySyst][tempqzz].pTzq);
  611. return 0;
  612. }
  613. }
  614. while(tzqdatetemp->pTzq[ntt1]!=NULL)
  615. {
  616. tzqdatetemp=tzqdatetemp->pTzq[ntt1];
  617. // if(tzqdatetemp->pTzq[ntt2]
  618. }
  619. tzqdatetemp=aPlace[nPlaySyst][tempqzz].pTzq;
  620. while(tzqdatetemp->pTzq[ntt1]!=NULL)
  621. {
  622. tzqdatetemp=tzqdatetemp->pTzq[ntt1];
  623. // if(tzqdatetemp->pTzq[ntt2]
  624. }
  625. }
  626. */
  627. int zzr,ttt,tt2,tt3;
  628. zzr=-10;
  629. ttt=0;
  630. tt2=0;
  631. tt3=0;
  632. int x,asd1;
  633. int zze;
  634. for(zze=0;zze<10;zze++)
  635. {
  636. for(asd1=0;asd1<aPlace[nPlaySyst][zze].nPlaceArray.GetSize();asd1++)
  637. {
  638. x=aPlace[nPlaySyst][zze].nPlaceArray[asd1];
  639. if(this->aTzqFull[x].nPRI[nPlaySyst]-aPlace[nPlaySyst][zze].pTzq->nPRI[nPlaySyst] >zzr)
  640. {
  641. // if(ab[x].b[0]-abz[1][zze].a->b[0]==zzr
  642. // &&ab[x].a
  643. if((aTzqFull[x].nArea==nPlaySyst+1)
  644. ||(aTzqFull[x].nArea==0)
  645. ||(aTzqFull[x].nArea==((nPlaySyst+3>=6)?(nPlaySyst-3):(nPlaySyst+3))+1))
  646. {
  647. ttt=zze;
  648. tt3=asd1;
  649. tt2=aPlace[nPlaySyst][zze].nPlaceArray[asd1];
  650. zzr=aTzqFull[aPlace[nPlaySyst][zze].nPlaceArray[asd1]].nPRI[nPlaySyst]-aPlace[nPlaySyst][zze].pTzq->nPRI[nPlaySyst];
  651. }
  652. }
  653. else
  654. if(aTzqFull[x].nPRI[nPlaySyst]-aPlace[nPlaySyst][zze].pTzq->nPRI[nPlaySyst]==zzr)
  655. {
  656. char crand=(char)rand();
  657. // if(crand<0)
  658. // MessageBox("fdslafk");
  659. if(crand>0)
  660. {
  661. // if(abz[1][zze].a->a!=1)
  662. {
  663. if((aTzqFull[x].nArea==nPlaySyst+1)
  664. ||(aTzqFull[x].nArea==0)
  665. ||(aTzqFull[x].nArea==(((nPlaySyst+3>=6)?(nPlaySyst-3):(nPlaySyst+3))+1)))
  666. {
  667. ttt=zze;
  668. tt3=asd1;
  669. tt2=aPlace[nPlaySyst][zze].nPlaceArray[asd1];
  670. zzr=aTzqFull[aPlace[nPlaySyst][zze].nPlaceArray[asd1]].nPRI[nPlaySyst]-aPlace[nPlaySyst][zze].pTzq->nPRI[nPlaySyst];
  671. }
  672. }
  673. }
  674. }
  675. }
  676. }
  677. this->aTzqFull[this->aPlace[nPlaySyst][ttt].nPlaceArray[tt3]].nColor=aPlace[nPlaySyst][ttt].pTzq->nColor;
  678. aPlace[nPlaySyst][ttt].pTzq->nColor=0;
  679. m_cwnd->InvalidateRect(
  680. CRect(
  681. aTzqFull[this->aPlace[nPlaySyst][ttt].nPlaceArray[tt3]].n_x-15,
  682. aTzqFull[this->aPlace[nPlaySyst][ttt].nPlaceArray[tt3]].n_y-15,
  683. aTzqFull[this->aPlace[nPlaySyst][ttt].nPlaceArray[tt3]].n_x+17,
  684. aTzqFull[this->aPlace[nPlaySyst][ttt].nPlaceArray[tt3]].n_y+17),0);
  685. m_cwnd->InvalidateRect(
  686. CRect(
  687. aPlace[nPlaySyst][ttt].pTzq->n_x-15,
  688. aPlace[nPlaySyst][ttt].pTzq->n_y-15,
  689. aPlace[nPlaySyst][ttt].pTzq->n_x+17,
  690. aPlace[nPlaySyst][ttt].pTzq->n_y+17),0);
  691. aPlace[nPlaySyst][ttt].pTzq=&aTzqFull[this->aPlace[nPlaySyst][ttt].nPlaceArray[tt3]];
  692. int ffff=1,fff1=1;
  693. int tend;
  694. tend=nPlaySyst+3;
  695. if(tend>5)
  696. tend=nPlaySyst-3;
  697. for(int abqq=0;abqq<10;abqq++)
  698. {
  699. if(aPlace[nPlaySyst][abqq].pTzq->nArea!=tend+1)
  700. ffff=0;
  701. }
  702. if(ffff==1){
  703. CString yj;
  704. yj.Format("!!!玩家%d",this->nPlaySyst+1);
  705. yj+="下完!!!";
  706. m_cwnd->MessageBox(yj,"跳子棋");
  707. // newgame();
  708. // this->Invalidate(0);
  709. this->nPlayType[nPlaySyst]=0;
  710. }
  711. int nti=0;
  712. for(int t=0;t<6;t++)
  713. {
  714. nti+=nPlayType[t];
  715. }
  716. if(nti==0)
  717. return 0;
  718. for(qzc=0;qzc<6;qzc++)
  719. this->ChessFull();
  720. nPlaySyst++;
  721. nPlaySyst%=6;
  722. while(nPlayType[nPlaySyst]==0)
  723. {
  724. nPlaySyst++;
  725. nPlaySyst%=6;
  726. }
  727. GameStep();
  728. return 0;
  729. }
  730. CTzq::NetStep()
  731. {
  732. }
  733. int CTzq::qzsetel(CPoint point)
  734. {
  735. CRect rgn;
  736. for(int i=0;i<122;i++)
  737. {
  738. rgn=CRect(
  739. aTzqFull[i].n_x-9,
  740. aTzqFull[i].n_y-9,
  741. aTzqFull[i].n_x+9,
  742. aTzqFull[i].n_y+9);
  743. if(rgn.PtInRect(point))
  744. return i;
  745. }
  746. }
  747. return 0;
  748. }
  749. BOOL CTzq::StepPath(CPlace *pplace, TzqDate *ptzq,int i1)
  750. {
  751. int it,ht,ii;
  752. TzqDate *pb;
  753. pb=pplace->pTzq;
  754. ii=0;
  755. it=0;
  756. ht=0;
  757. while(pb->pTzq[i1])
  758. {
  759. pb=pb->pTzq[i1];
  760. if(it==0)
  761. {
  762. if(pb->nColor==0)
  763. ii++;
  764. else 
  765. it=1;
  766. }
  767. else
  768. {
  769. if(ii==0)
  770. {
  771. if(pb->nColor==0)
  772. {
  773. // Addpa(pb);
  774. if(pb->nQz==ptzq->nQz)
  775. return TRUE;
  776. else 
  777. return FALSE;
  778. }
  779. else
  780. return FALSE;
  781. }
  782. else
  783. {
  784. if(pb->nColor==0)
  785. ii--;
  786. else
  787. return FALSE;
  788. }
  789. }
  790. }
  791. return FALSE;
  792. }
  793. CTzq::renovate(TzqDate * t1, TzqDate * t2)
  794. {
  795. m_cwnd->InvalidateRect(
  796. CRect(
  797. t1->n_x-15,
  798. t1->n_y-15,
  799. t1->n_x+17,
  800. t1->n_y+17),0);
  801. m_cwnd->InvalidateRect(
  802. CRect(
  803. t2->n_x-15,
  804. t2->n_y-15,
  805. t2->n_x+17,
  806. t2->n_y+17),0);
  807. int ffff=1,fff1=1;
  808. int tend;
  809. tend=nPlaySyst+3;
  810. if(tend>5)
  811. tend=nPlaySyst-3;
  812. for(int abqq=0;abqq<10;abqq++)
  813. {
  814. if(aPlace[nPlaySyst][abqq].pTzq->nArea!=tend+1)
  815. ffff=0;
  816. }
  817. if(ffff==1){
  818. CString yj;
  819. yj.Format("!!!玩家%d",this->nPlaySyst+1);
  820. yj+="下完!!!";
  821. m_cwnd->MessageBox(yj,"跳子棋");
  822. // newgame();
  823. // this->Invalidate(0);
  824. this->nPlayType[nPlaySyst]=0;
  825. }
  826. for(qzc=0;qzc<6;qzc++)
  827. this->ChessFull();
  828. nPlaySyst++;
  829. nPlaySyst%=6;
  830. while(nPlayType[nPlaySyst]==0)
  831. {
  832. nPlaySyst++;
  833. nPlaySyst%=6;
  834. }
  835. GameStep();
  836. }