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

游戏

开发平台:

C/C++

  1. // Draw_Item_Engine.cpp: implementation of the CDrawItemEngine class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "斗地主.h"
  6. #include "MainFrm.h"
  7. #include "My_DirectInput.h"
  8. #include "My_directdraw.h"
  9. #include "Game.h"
  10. #include "Draw_Cards_Engine.h"
  11. #include "Draw_Item_Engine.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. CDrawItemEngine::CDrawItemEngine()
  21. {
  22. //精灵颜色键;
  23. blue = _RGB32BIT(0,0,0,255);
  24. }
  25. CDrawItemEngine::~CDrawItemEngine()
  26. {
  27. }
  28. //
  29. //相关初始化;
  30. int CDrawItemEngine::Init()
  31. {
  32. char* file;
  33. //游戏界面离屏表面的建立;
  34. file = "bmp\Game_Back.bmp" ;
  35. lpddsbg_Game = pDraw->CreateSurface(Screen_Width, Screen_Height,0,-1);
  36. pDraw->BitmapToSurface(lpddsbg_Game,0,0,file,Screen_Width,Screen_Height);
  37. //face;
  38. file = "bmp\faces\face0.bmp";
  39. lpddsbg_Person[0] = pDraw->CreateSurface(70,70,0,-1);
  40. pDraw->BitmapToSurface(lpddsbg_Person[0],0,0,file,70,70);
  41. file = "bmp\faces\face1.bmp";
  42. lpddsbg_Person[1] = pDraw->CreateSurface(70,70,0,-1);
  43. pDraw->BitmapToSurface(lpddsbg_Person[1],0,0,file,70,70);
  44. file = "bmp\faces\face2.bmp";
  45. lpddsbg_Person[2] = pDraw->CreateSurface(70,70,0,-1);
  46. pDraw->BitmapToSurface(lpddsbg_Person[2],0,0,file,70,70);
  47. file = "bmp\faces\face3.bmp";
  48. lpddsbg_Person[3] = pDraw->CreateSurface(70,70,0,-1);
  49. pDraw->BitmapToSurface(lpddsbg_Person[3],0,0,file,70,70);
  50. //左边玩家头像;
  51. pDraw->DrawSurface(lpddsbg_Person[pLeftPlayer->m_nFaceID], 
  52. 40, 30,
  53. 70,70,
  54. lpddsbg_Game,0);
  55. //中间玩家头像;
  56. pDraw->DrawSurface(lpddsbg_Person[pCenterPlayer->m_nFaceID], 
  57. 40, 620,
  58. 70,70,
  59. lpddsbg_Game,0);
  60. //右边玩家头像;
  61. pDraw->DrawSurface(lpddsbg_Person[pRightPlayer->m_nFaceID], 
  62. 910, 30,
  63. 70,70,
  64. lpddsbg_Game,0);
  65. //玩家名字;
  66. pDraw->TextGDI(pLeftPlayer->m_szName,45,110,RGB(0,0,225),160,"华文新魏",lpddsbg_Game);
  67. pDraw->TextGDI(pCenterPlayer->m_szName,45,700,RGB(0,0,225),160,"华文新魏",lpddsbg_Game);
  68. pDraw->TextGDI(pRightPlayer->m_szName,915,110,RGB(0,0,225),160,"华文新魏",lpddsbg_Game);
  69. pDraw->TextGDI(pLeftPlayer->m_szName,144,658,RGB(255,0,0),130,"华文新魏",lpddsbg_Game);
  70. pDraw->TextGDI(pCenterPlayer->m_szName,144,685,RGB(255,0,0),130,"华文新魏",lpddsbg_Game);
  71. pDraw->TextGDI(pRightPlayer->m_szName,144,710,RGB(255,0,0),130,"华文新魏",lpddsbg_Game);
  72. //载入其他界面相关项;
  73. //产生随机地主的动画框;
  74. file = "bmp\item\bring_lord.bmp";
  75. lpddsbg_Menu[0] = pDraw->CreateSurface(300,150,0,-1);
  76. pDraw->BitmapToSurface(lpddsbg_Menu[0],0,0,file,300,150);
  77.     //头像外框;
  78. file = "bmp\item\lord_frame.bmp";
  79. lpddsbg_Menu[1] = pDraw->CreateSurface(76,76,0,blue);
  80. pDraw->BitmapToSurface(lpddsbg_Menu[1],0,0,file,76,76);
  81. //选择地主的菜单框;
  82. file = "bmp\item\choose_lord.bmp";
  83. lpddsbg_Menu[2] = pDraw->CreateSurface(200,80,0,blue);
  84. pDraw->BitmapToSurface(lpddsbg_Menu[2],0,0,file,200,80);
  85. //出牌按钮;
  86. file = "bmp\item\Ok_Button.bmp";
  87. lpddsbg_Menu[3] = pDraw->CreateSurface(80,30,0,-1);
  88. pDraw->BitmapToSurface(lpddsbg_Menu[3],0,0,file,80,30);
  89. file = "bmp\item\Pass_Button.bmp";
  90. lpddsbg_Menu[4] = pDraw->CreateSurface(80,30,0,-1);
  91. pDraw->BitmapToSurface(lpddsbg_Menu[4],0,0,file,80,30);
  92. //得分表框;
  93. file = "bmp\item\show_score.bmp";
  94. lpddsbg_Menu[5] = pDraw->CreateSurface(300,250,0,-1);
  95. pDraw->BitmapToSurface(lpddsbg_Menu[5],0,0,file,300,250);
  96. pDraw->DrawSurface(lpddsbg_Game,0,0, Screen_Width,Screen_Height,lpddsback,0); 
  97. while (FAILED(lpddsprimary->Flip(NULL, DDFLIP_WAIT)));
  98. return 1;
  99. }
  100. //显示第几局的函数;
  101. int CDrawItemEngine::GameCounter(int nGameCounter)
  102. {
  103. pDraw->DrawSurface(lpddsbg_Game,0,0, Screen_Width,Screen_Height,lpddsback,0);
  104. //刷新屏幕;
  105. char info[30];
  106. sprintf(info,"第%d局开始",nGameCounter);
  107. pDraw->TextGDI(info,360,200,RGB(255,0,0),500,"隶书",lpddsback);
  108. while (FAILED(lpddsprimary->Flip(NULL, DDFLIP_WAIT)));
  109. PlaySound(MAKEINTRESOURCE(IDR_START),AfxGetResourceHandle(),
  110. SND_ASYNC|SND_RESOURCE|SND_NODEFAULT );  //
  111. Sleep(1000);
  112. return 1;
  113. }
  114. //
  115. int CDrawItemEngine::BringRandLord(int nDefaultLord)
  116. {
  117. // pDraw->DrawSurface(lpddsbg_Game,0,0, Screen_Width,Screen_Height,lpddsback,0); 
  118. int counter = 0;
  119. while( counter < 10 )
  120. {
  121. PlaySound(MAKEINTRESOURCE(IDR_DING),AfxGetResourceHandle(),
  122. SND_ASYNC|SND_RESOURCE|SND_NODEFAULT );  //
  123. ::RedrawGame(NULL);
  124. pDraw->DrawSurface(lpddsbg_Menu[0], 
  125. 365, 300,
  126. 300,150,
  127. lpddsback,0);
  128. //左边玩家;
  129. pDraw->DrawSurface(lpddsbg_Person[pLeftPlayer->m_nFaceID], 
  130. 390, 320,
  131. 70,70,
  132. lpddsback,0);
  133. pDraw->TextGDI(pLeftPlayer->m_szName,400,400,RGB(0,0,0),200,"隶书",lpddsback);
  134. //中间玩家;
  135. pDraw->DrawSurface(lpddsbg_Person[pCenterPlayer->m_nFaceID], 
  136. 480, 320,
  137. 70,70,
  138. lpddsback,0);
  139. pDraw->TextGDI(pCenterPlayer->m_szName,490,400,RGB(0,0,0),200,"隶书",lpddsback);
  140. //右边玩家;
  141. pDraw->DrawSurface(lpddsbg_Person[pRightPlayer->m_nFaceID], 
  142. 570, 320,
  143. 70,70,
  144. lpddsback,0);
  145. pDraw->TextGDI(pRightPlayer->m_szName,580,400,RGB(0,0,0),200,"隶书",lpddsback);
  146. //显示字:
  147. pDraw->TextGDI("正在产生随机地主...",330,230,RGB(0,0,0),300,"隶书",lpddsback);
  148. switch( rand()%3 )
  149. {
  150. case 0:
  151. pDraw->DrawSurface(lpddsbg_Menu[1], 
  152. 390-3, 320-3,
  153. 76,76,
  154. lpddsback,1);
  155. break;
  156. case 1:
  157. pDraw->DrawSurface(lpddsbg_Menu[1], 
  158. 480-3, 320-3,
  159. 76,76,
  160. lpddsback,1);
  161. break;
  162. case 2:
  163. pDraw->DrawSurface(lpddsbg_Menu[1], 
  164. 570-3, 320-3,
  165. 76,76,
  166. lpddsback,1);
  167. }
  168. while (FAILED(lpddsprimary->Flip(NULL, DDFLIP_WAIT)));
  169. counter++;
  170. Sleep(150);
  171. }
  172. //生产地主后的信息提示:
  173. ::RedrawGame(NULL);
  174. pDraw->DrawSurface(lpddsbg_Menu[0], 
  175. 365, 300,
  176. 300,150,
  177. lpddsback,0);
  178. //左边玩家;
  179. pDraw->DrawSurface(lpddsbg_Person[pLeftPlayer->m_nFaceID], 
  180. 390, 320,
  181. 70,70,
  182. lpddsback,0);
  183. pDraw->TextGDI(pLeftPlayer->m_szName,400,400,RGB(0,0,0),200,"隶书",lpddsback);
  184. //中间玩家;
  185. pDraw->DrawSurface(lpddsbg_Person[pCenterPlayer->m_nFaceID], 
  186. 480, 320,
  187. 70,70,
  188. lpddsback,0);
  189. pDraw->TextGDI(pCenterPlayer->m_szName,490,400,RGB(0,0,0),200,"隶书",lpddsback);
  190. //右边玩家;
  191. pDraw->DrawSurface(lpddsbg_Person[pRightPlayer->m_nFaceID], 
  192. 570, 320,
  193. 70,70,
  194. lpddsback,0);
  195. pDraw->TextGDI(pRightPlayer->m_szName,580,400,RGB(0,0,0),200,"隶书",lpddsback);
  196. //选出地主提示:
  197. char lord_info[50];
  198. switch( nDefaultLord )
  199. {
  200. case 0:
  201. sprintf(lord_info,"本局的随机地主是:%s",pLeftPlayer->m_szName);
  202. pDraw->DrawSurface(lpddsbg_Menu[1], 
  203. 390-3, 320-3,
  204. 76,76,
  205. lpddsback,1);
  206. break;
  207. case 1:
  208. sprintf(lord_info,"本局的随机地主是:%s",pCenterPlayer->m_szName);
  209. pDraw->DrawSurface(lpddsbg_Menu[1], 
  210. 480-3, 320-3,
  211. 76,76,
  212. lpddsback,1);
  213. break;
  214. case 2:
  215. sprintf(lord_info,"本局的随机地主是:%s",pRightPlayer->m_szName);
  216. pDraw->DrawSurface(lpddsbg_Menu[1], 
  217. 570-3, 320-3,
  218. 76,76,
  219. lpddsback,1);
  220. break;
  221. }
  222. // AfxMessageBox(lord_info);
  223. pDraw->TextGDI(lord_info,330,230,RGB(0,0,0),300,"隶书",lpddsback);
  224. while (FAILED(lpddsprimary->Flip(NULL, DDFLIP_WAIT)));
  225. Sleep(1500);
  226. return 1;
  227. }
  228. //产生随机地主的动画;
  229. int CDrawItemEngine::ChooseLord()
  230. {
  231. //选择地主效果;
  232. ::RedrawGame(NULL);
  233. pDraw->DrawSurface(lpddsbg_Menu[2], 
  234. 320, 500,
  235. 200,80,
  236. lpddsback,0);
  237. while (FAILED(lpddsprimary->Flip(NULL, DDFLIP_WAIT)));
  238. // Sleep(5000);
  239. return 1;
  240. }
  241. //显示游戏过程中选地主的信息;
  242. int CDrawItemEngine::GameInfo(int nPlayer,int nInfoType)
  243. {
  244. //info_type = 0: "%s要当地主,本局地主是:%s"
  245. //info_type = 1: "%s不当地主,等待%s选择..."
  246. //info_type = 2: "按规则,本局地主是:%s"
  247. //
  248. ::RedrawGame(NULL);
  249. char lord_info[50];
  250. switch( nInfoType )
  251. {
  252. case 0:
  253. switch( nPlayer )  //当前地主当;
  254. {
  255. case 0:
  256. sprintf(lord_info,"%s要当地主,本局地主是:%s",
  257. pLeftPlayer->m_szName,pLeftPlayer->m_szName);
  258. break;
  259. case 1:
  260. sprintf(lord_info,"%s要当地主,本局地主是:%s",
  261. pCenterPlayer->m_szName,pCenterPlayer->m_szName);
  262. break;
  263. case 2:
  264. sprintf(lord_info,"%s要当地主,本局地主是:%s",
  265. pRightPlayer->m_szName,pRightPlayer->m_szName);
  266. break;
  267. }
  268. break;
  269. case 1:
  270. switch( nPlayer )
  271. {
  272. case 0:
  273. sprintf(lord_info,"%s不当地主,等待%s选择...",
  274. pLeftPlayer->m_szName,pCenterPlayer->m_szName);
  275. break;
  276. case 1:
  277. sprintf(lord_info,"%s不当地主,等待%s选择...",
  278. pCenterPlayer->m_szName,pRightPlayer->m_szName);
  279. break;
  280. case 2:
  281. sprintf(lord_info,"%s不当地主,等待%s选择...",
  282. pRightPlayer->m_szName,pLeftPlayer->m_szName);
  283. break;
  284. }
  285. break;
  286. case 2:
  287. switch( nPlayer )
  288. {
  289. case 0:
  290. sprintf(lord_info,"按规则,本局地主是:%s",
  291. pLeftPlayer->m_szName);
  292. break;
  293. case 1:
  294. sprintf(lord_info,"按规则,本局地主是:%s",
  295. pCenterPlayer->m_szName);
  296. break;
  297. case 2:
  298. sprintf(lord_info,"按规则,本局地主是:%s",
  299. pRightPlayer->m_szName);
  300. break;
  301. }
  302. break;
  303. }
  304. pDraw->TextGDI(lord_info,280,300,RGB(0,0,255),250,"隶书",lpddsback);
  305. while (FAILED(lpddsprimary->Flip(NULL, DDFLIP_WAIT)));
  306. Sleep(1000);
  307. return 1;
  308. }
  309. //显示得分情况;
  310. int CDrawItemEngine::GameScore(int nCurrentLord,int nLeft,int nCenter,int nRight)
  311. {
  312. char score_info[10];
  313. ::RedrawGame(NULL);
  314. pDraw->DrawSurface(lpddsbg_Menu[5], 
  315. 365, 200,
  316. 300,250,
  317. lpddsback,0);
  318. //左边玩家;
  319. pDraw->DrawSurface(lpddsbg_Person[pLeftPlayer->m_nFaceID], 
  320. 390, 270,
  321. 70,70,
  322. lpddsback,0);
  323. pDraw->TextGDI(pLeftPlayer->m_szName,400,350,RGB(0,0,0),200,"隶书",lpddsback);
  324. //显示得分;
  325. sprintf(score_info,"%d",nLeft);
  326. pDraw->TextGDI(score_info,410,380,RGB(255,0,0),300,"华文新魏",lpddsback);
  327. //中间玩家;
  328. pDraw->DrawSurface(lpddsbg_Person[pCenterPlayer->m_nFaceID], 
  329. 480, 270,
  330. 70,70,
  331. lpddsback,0);
  332. pDraw->TextGDI(pCenterPlayer->m_szName,490,350,RGB(0,0,0),200,"隶书",lpddsback);
  333. //显示得分;
  334. sprintf(score_info,"%d",nCenter);
  335. pDraw->TextGDI(score_info,500,380,RGB(255,0,0),300,"华文新魏",lpddsback);
  336. //右边玩家;
  337. pDraw->DrawSurface(lpddsbg_Person[pRightPlayer->m_nFaceID], 
  338. 570, 270,
  339. 70,70,
  340. lpddsback,0);
  341. pDraw->TextGDI(pRightPlayer->m_szName,580,350,RGB(0,0,0),200,"隶书",lpddsback);
  342. //显示得分;
  343. sprintf(score_info,"%d",nRight);
  344. pDraw->TextGDI(score_info,590,380,RGB(255,0,0),300,"华文新魏",lpddsback);
  345. switch( nCurrentLord )
  346. {
  347. case 0:
  348. pDraw->DrawSurface(lpddsbg_Menu[1], 
  349. 390-3, 270-3,
  350. 76,76,
  351. lpddsback,1);
  352. break;
  353. case 1:
  354. pDraw->DrawSurface(lpddsbg_Menu[1], 
  355. 480-3, 270-3,
  356. 76,76,
  357. lpddsback,1);
  358. break;
  359. case 2:
  360. pDraw->DrawSurface(lpddsbg_Menu[1], 
  361. 570-3, 270-3,
  362. 76,76,
  363. lpddsback,1);
  364. }
  365. while (FAILED(lpddsprimary->Flip(NULL, DDFLIP_WAIT)));
  366. Sleep(3000);
  367. return 1;
  368. }
  369. void CDrawItemEngine::Redraw(LPDIRECTDRAWSURFACE7  pSurface)
  370. {
  371. if( pCardsMap->m_nUpCounter == 0 )
  372. {
  373. pDraw->DrawSurface(lpddsbg_Menu[4], 
  374. 660, 550,
  375. 80,30,
  376. lpddsback,0);
  377. }
  378. else
  379. {
  380. pDraw->DrawSurface(lpddsbg_Menu[3], 
  381. 660, 550,
  382. 80,30,
  383. lpddsback,0);
  384. }
  385. switch( pGame->m_nCurrentLord )
  386. {
  387. case 0:
  388. pDraw->DrawSurface(lpddsbg_Menu[1], 
  389. 40-3, 30-3,
  390. 76,76,
  391. lpddsback,1);
  392. break;
  393. case 1:
  394. pDraw->DrawSurface(lpddsbg_Menu[1], 
  395. 40-3, 620-3,
  396. 76,76,
  397. lpddsback,1);
  398. break;
  399. case 2:
  400. pDraw->DrawSurface(lpddsbg_Menu[1], 
  401. 910-3, 30-3,
  402. 76,76,
  403. lpddsback,1);
  404. break;
  405. }
  406. char table_info[100];
  407. //左边玩家得分信息;
  408. sprintf(table_info,"%d        %d         %d",pLeftPlayer->m_nScore,pLeftPlayer->m_nWin,pLeftPlayer->m_nLose);
  409. pDraw->TextGDI(table_info,210,658,RGB(255,0,0),130,"华文新魏",lpddsback);
  410. //中间玩家得分信息;
  411. sprintf(table_info,"%d        %d         %d",pCenterPlayer->m_nScore,pCenterPlayer->m_nWin,pCenterPlayer->m_nLose);
  412. pDraw->TextGDI(table_info,210,685,RGB(255,0,0),130,"华文新魏",lpddsback);
  413. //右边玩家得分信息;
  414. sprintf(table_info,"%d        %d         %d",pRightPlayer->m_nScore,pRightPlayer->m_nWin,pRightPlayer->m_nLose);
  415. pDraw->TextGDI(table_info,210,710,RGB(255,0,0),130,"华文新魏",lpddsback);
  416. }