mine.c
上传用户:yulinhuamu
上传日期:2009-12-26
资源大小:7287k
文件大小:20k
源码类别:

BREW编程

开发平台:

Visual C++

  1. #include "mine.h"
  2. ///////////////////////////////////////////////////////////////////////////////////////////////
  3. // STATIC FUNCTION DECLARE
  4. ///////////////////////////////////////////////////////////////////////////////////////////////
  5. #define MSGOFFSET_SUCCESS   212
  6. #define MSGOFFSET_TIMER     10
  7. #define MSGOFFSET_FAILURE   365
  8. #define MARGIN_RECT 3
  9. #define MINEUI_OUTRECTCOLOR MAKE_RGB(150,150,200)
  10. #define MINEUI_INRECTCOLOR MAKE_RGB(200,200,255)
  11. #define MINEUI_GRIDCOLOR MAKE_RGB(200,200,250)
  12. #define MINEUI_FILLCOLOR MAKE_RGB(211,211,211)
  13. #define MINEUI_SELIIEMCOLOR MAKE_RGB(180,180,200)
  14. #define MINEUI_CUROR MAKE_RGB(255,10,10)
  15. #define MINEUI_FRAME MAKE_RGB(0,0,0)
  16. #define MINEASSERTNULL(p) {if(NULL==p) return FALSE;}
  17. static boolean WINMINE_Draw(IWinmine* pMine);
  18. static boolean WINMINE_DrawElement(IWinmine* pMine,int x,int y,boolean bSel);
  19. static boolean WINMINE_DrawCuror(IWinmine* pMine,AEERect* rt);
  20. static boolean WINMINE_DrawMine(IWinmine* pMine,AEERect* rt);
  21. static boolean WINMINE_DrawBlast(IWinmine* pMine,AEERect* rt);
  22. static boolean WINMINE_DrawBanner(IWinmine* pMine,AEERect* rt);
  23. static boolean WINMINE_DrawNumber(IWinmine* pMine,AEERect* rt,char* pText);
  24. static boolean WINMINE_DrawFrame(IWinmine* pMine,AEERect* rt,int x,int y);
  25. static boolean WINMINE_SUCCESSHDL(IWinmine* pMine);
  26. static boolean WINMINE_FAILUREHDL(IWinmine* pMine);
  27. static boolean WINMINE_BLANKHDL(IWinmine* pMine,int x,int y);
  28. static boolean WINMINE_ShowMsg(IWinmine* pMine,int nType);
  29. static void WINMINE_SaveScore(IWinmine* pMine);
  30. static void WINMINE_BlankElementHDL(IWinmine* pMine,int x,int y);
  31. static void WINMINE_MsgTimerHDL(IWinmine* pMine);
  32. ///////////////////////////////////////////////////////////////////////////////////////////////
  33. // PUBLIC FUNCDEFINE
  34. ///////////////////////////////////////////////////////////////////////////////////////////////
  35. IWinmine* IWINMINE_CreateInstance()
  36. {
  37. IWinmine* pMine=MALLOCREC(IWinmine);
  38. if(pMine)
  39. {
  40. AEEDeviceInfo di;
  41. pMine->m_pApp=(AEEApplet*)GETAPPINSTANCE();
  42. ISHELL_GetDeviceInfo(pMine->m_pApp->m_pIShell, &di);
  43. pMine->m_GameRect.x=pMine->m_GameRect.y=0;
  44. pMine->m_GameRect.dx=di.cxScreen;
  45. pMine->m_GameRect.dy=di.cyScreen;
  46. pMine->m_PlayRect.x=pMine->m_GameRect.x+MARGIN_RECT;
  47. pMine->m_PlayRect.dx=pMine->m_GameRect.dx-2*MARGIN_RECT;
  48. pMine->m_PlayRect.dy=pMine->m_PlayRect.dx;
  49. pMine->m_PlayRect.y=pMine->m_GameRect.dy+pMine->m_GameRect.y-pMine->m_PlayRect.dy-MARGIN_RECT;
  50. pMine->m_MenuRect.x=pMine->m_PlayRect.x;
  51. pMine->m_MenuRect.dx=pMine->m_PlayRect.dx;
  52. pMine->m_MenuRect.y=pMine->m_GameRect.y+MARGIN_RECT;
  53. pMine->m_MenuRect.dy=pMine->m_GameRect.dy-pMine->m_PlayRect.dy-3*MARGIN_RECT;
  54. pMine->m_ElementWide=pMine->m_PlayRect.dx/MINE_LINE_NUM;
  55. pMine->m_ElementHeight=pMine->m_PlayRect.dy/MINE_COLU_NUM;
  56. pMine->m_OffsetX=pMine->m_PlayRect.x+(pMine->m_PlayRect.dx-pMine->m_ElementWide*MINE_LINE_NUM)/2;
  57. pMine->m_OffsetY=pMine->m_PlayRect.y+(pMine->m_PlayRect.dy-pMine->m_ElementHeight*MINE_COLU_NUM)/2;
  58. pMine->m_pImage=ISHELL_LoadImage(pMine->m_pApp->m_pIShell,"test.bmp");
  59. if(pMine->m_pImage)
  60. IIMAGE_SetDrawSize(pMine->m_pImage,pMine->m_MenuRect.dx-4,pMine->m_MenuRect.dy-4);
  61. pMine->m_pGameImage=ISHELL_LoadImage(pMine->m_pApp->m_pIShell,"x.bmp");
  62. if(pMine->m_pGameImage)
  63. IIMAGE_SetDrawSize(pMine->m_pGameImage,pMine->m_ElementWide-4,pMine->m_ElementHeight-4);
  64. ISHELL_CreateInstance(pMine->m_pApp->m_pIShell,AEECLSID_GRAPHICS,(void**)&pMine->m_pGraphic);
  65. pMine->m_pMusic=IMINEMUSIC_CreateInstance(pMine->m_pApp->m_pIShell);
  66. }
  67. return pMine;
  68. }
  69. boolean IWINMINE_Release(IWinmine* pMine)
  70. {
  71. MINEASSERTNULL(pMine);
  72. ISHELL_CancelTimer(pMine->m_pApp->m_pIShell,(PFNNOTIFY) WINMINE_MsgTimerHDL, pMine);
  73. if(pMine->m_pImage)
  74. {
  75. IIMAGE_Release(pMine->m_pImage);
  76. pMine->m_pImage=NULL;
  77. }
  78. if(pMine->m_pGameImage)
  79. {
  80. IIMAGE_Release(pMine->m_pGameImage);
  81. pMine->m_pGameImage=NULL;
  82. }
  83. if(pMine->m_pMusic)
  84. {
  85. IMINEMUSIC_Release(pMine->m_pMusic);
  86. pMine->m_pMusic=NULL;
  87. }
  88. if(pMine->m_pGraphic)
  89. {
  90. IGRAPHICS_Release(pMine->m_pGraphic);
  91. pMine->m_pGraphic=NULL;
  92. }
  93. return TRUE;
  94. }
  95. boolean IWINMINE_Start(IWinmine* pMine)
  96. {
  97. byte   z;
  98. int x,y;
  99. TScore score;
  100. uint16 mineNum=0;
  101. MINEASSERTNULL(pMine);
  102. //zero list data
  103. for(x=0;x<MINE_LINE_NUM;x++)
  104. for(y=0;y<MINE_COLU_NUM;y++)
  105. {
  106. pMine->m_Data[x][y].m_bSel=FALSE;
  107. pMine->m_Data[x][y].m_Stat=0;
  108. }
  109. //generate the mine
  110. while(mineNum<MINE_NUM)
  111. {
  112. //x point
  113. GETRAND(&z,sizeof(z));
  114. x=z*MINE_LINE_NUM/256;
  115. //y point
  116. GETRAND(&z,sizeof(z));
  117. y=z*MINE_LINE_NUM/256;
  118. //check available
  119. if(MINE_FLAGE==pMine->m_Data[x][y].m_Stat)
  120. continue;
  121. pMine->m_Data[x][y].m_Stat=MINE_FLAGE;
  122. mineNum++;
  123. //set around grid
  124. if((x-1>=0)&&(y-1>=0)&&(MINE_FLAGE!=pMine->m_Data[x-1][y-1].m_Stat))
  125. pMine->m_Data[x-1][y-1].m_Stat++;
  126. if((x-1>=0)&&(MINE_FLAGE!=pMine->m_Data[x-1][y].m_Stat))
  127. pMine->m_Data[x-1][y].m_Stat++;
  128. if((x-1>=0)&&(y+1<MINE_COLU_NUM)&&(MINE_FLAGE!=pMine->m_Data[x-1][y+1].m_Stat))
  129. pMine->m_Data[x-1][y+1].m_Stat++;
  130. if((y-1>=0)&&(MINE_FLAGE!=pMine->m_Data[x][y-1].m_Stat))
  131. pMine->m_Data[x][y-1].m_Stat++;
  132. if((y+1<MINE_COLU_NUM)&&(MINE_FLAGE!=pMine->m_Data[x][y+1].m_Stat))
  133. pMine->m_Data[x][y+1].m_Stat++;
  134. if((x+1<MINE_LINE_NUM)&&(y-1>=0)&&(MINE_FLAGE!=pMine->m_Data[x+1][y-1].m_Stat))
  135. pMine->m_Data[x+1][y-1].m_Stat++;
  136. if((x+1<MINE_LINE_NUM)&&(MINE_FLAGE!=pMine->m_Data[x+1][y].m_Stat))
  137. pMine->m_Data[x+1][y].m_Stat++;
  138. if((x+1<MINE_LINE_NUM)&&(y+1<MINE_COLU_NUM)&&(MINE_FLAGE!=pMine->m_Data[x+1][y+1].m_Stat))
  139. pMine->m_Data[x+1][y+1].m_Stat++;
  140. }
  141. //other value
  142. pMine->m_PointX=MINE_LINE_NUM/2;
  143. pMine->m_PointY=MINE_COLU_NUM/2;
  144. pMine->m_Count=0;
  145. pMine->m_TimerCount=MINE_GAMETIMER;
  146. pMine->m_Result=STAT_START;
  147. //Score
  148. if(SUCCESS!=ISHELL_GetAppPrefs(pMine->m_pApp->m_pIShell,1,&score,sizeof(score)))
  149. pMine->m_MaxScore=0;
  150. else
  151. pMine->m_MaxScore=score.m_nScore;
  152. //draw list
  153. WINMINE_Draw(pMine);
  154. WINMINE_ShowMsg(pMine,0);
  155. IMINEMUSIC_Start(pMine->m_pMusic,MMT_START);
  156. return TRUE;
  157. }
  158. boolean IWINMINE_HandleEvent(IWinmine* pMine, uint16 wParam)
  159. {
  160. MINEASSERTNULL(pMine);
  161. if(STAT_START!=pMine->m_Result)
  162. return FALSE;
  163. switch(wParam)
  164. {
  165. case AVK_LEFT:
  166. WINMINE_DrawElement(pMine,pMine->m_PointX,pMine->m_PointY,FALSE);
  167. pMine->m_PointX--;
  168. if(pMine->m_PointX<0) 
  169. pMine->m_PointX=MINE_LINE_NUM-1;
  170. WINMINE_DrawElement(pMine,pMine->m_PointX,pMine->m_PointY,TRUE);
  171. break;
  172. case AVK_RIGHT:
  173. WINMINE_DrawElement(pMine,pMine->m_PointX,pMine->m_PointY,FALSE);
  174. pMine->m_PointX++;
  175. if(MINE_LINE_NUM==pMine->m_PointX) 
  176. pMine->m_PointX=0;
  177. WINMINE_DrawElement(pMine,pMine->m_PointX,pMine->m_PointY,TRUE);
  178. break;
  179. case AVK_UP:
  180. WINMINE_DrawElement(pMine,pMine->m_PointX,pMine->m_PointY,FALSE);
  181. pMine->m_PointY--;
  182. if(pMine->m_PointY<0) 
  183. pMine->m_PointY=MINE_COLU_NUM-1;
  184. WINMINE_DrawElement(pMine,pMine->m_PointX,pMine->m_PointY,TRUE);
  185. break;
  186. case AVK_DOWN:
  187. WINMINE_DrawElement(pMine,pMine->m_PointX,pMine->m_PointY,FALSE);
  188. pMine->m_PointY++;
  189. if(MINE_COLU_NUM==pMine->m_PointY) 
  190. pMine->m_PointY=0;
  191. WINMINE_DrawElement(pMine,pMine->m_PointX,pMine->m_PointY,TRUE);
  192. break;
  193. case AVK_SELECT:
  194. if(pMine->m_Data[pMine->m_PointX][pMine->m_PointY].m_bSel)
  195. return TRUE;
  196. pMine->m_Data[pMine->m_PointX][pMine->m_PointY].m_bSel=TRUE;
  197. switch(pMine->m_Data[pMine->m_PointX][pMine->m_PointY].m_Stat)
  198. {
  199. case MINE_FLAGE:
  200. WINMINE_FAILUREHDL(pMine);
  201. break;
  202. case 0:
  203. WINMINE_BLANKHDL(pMine,pMine->m_PointX,pMine->m_PointY);
  204. default:
  205. WINMINE_DrawElement(pMine,pMine->m_PointX,pMine->m_PointY,TRUE);
  206. }
  207. break;
  208. case AVK_CLR:
  209. if(pMine->m_Data[pMine->m_PointX][pMine->m_PointY].m_bSel)
  210. return TRUE;
  211. pMine->m_Data[pMine->m_PointX][pMine->m_PointY].m_bSel=TRUE;
  212. if(MINE_FLAGE!=pMine->m_Data[pMine->m_PointX][pMine->m_PointY].m_Stat)
  213. WINMINE_FAILUREHDL(pMine);
  214. else
  215. {
  216. pMine->m_Count++;
  217. if(MINE_NUM==pMine->m_Count)
  218. WINMINE_SUCCESSHDL(pMine);
  219. else
  220. WINMINE_DrawElement(pMine,pMine->m_PointX,pMine->m_PointY,TRUE);
  221. }
  222. break;
  223. case AVK_1:
  224. return WINMINE_SUCCESSHDL(pMine);
  225. case AVK_3:
  226. return WINMINE_FAILUREHDL(pMine);
  227. default:
  228. return FALSE;
  229. }
  230. IDISPLAY_Update(pMine->m_pApp->m_pIDisplay); 
  231. return TRUE;
  232. }
  233. boolean IWINMINE_Pause(IWinmine* pMine)
  234. {
  235. MINEASSERTNULL(pMine);
  236. ISHELL_CancelTimer(pMine->m_pApp->m_pIShell,(PFNNOTIFY) WINMINE_MsgTimerHDL, pMine);
  237. return TRUE;
  238. }
  239. boolean IWINMINE_GetMaxScore(IWinmine* pMine,TScore* score)
  240. {
  241. MINEASSERTNULL(pMine);
  242. if(SUCCESS==ISHELL_GetAppPrefs(pMine->m_pApp->m_pIShell,1,&score,sizeof(score)))
  243. return TRUE;
  244. else
  245. return FALSE;
  246. }
  247. boolean IWINMINE_ResetMaxScore(IWinmine* pMine)
  248. {
  249. uint32 sec;
  250. TScore score;
  251. MINEASSERTNULL(pMine);
  252. sec=GETTIMESECONDS();
  253. GETJULIANDATE(sec,&(score.m_Date));
  254. score.m_nScore=0;
  255. ISHELL_SetAppPrefs(pMine->m_pApp->m_pIShell,1,&score,sizeof(score));
  256. return TRUE;
  257. }
  258. boolean IWINMINE_GetPlayRect(IWinmine* pMine,AEERect *rt)
  259. {
  260. if(pMine)
  261. *rt=pMine->m_PlayRect;
  262. return TRUE;
  263. }
  264. boolean IWINMINE_DrawIntroScreen(IWinmine* pMine)
  265. {
  266. IBitmap* image;
  267. uint32 time1;
  268. MINEASSERTNULL(pMine);
  269. // Draw the Background 
  270. image = ISHELL_LoadBitmap(pMine->m_pApp->m_pIShell,"flash.bmp");
  271. if(image)
  272. {
  273. IDISPLAY_ClearScreen(pMine->m_pApp->m_pIDisplay);
  274. IDISPLAY_BitBlt(pMine->m_pApp->m_pIDisplay, 
  275. 0,0,
  276. pMine->m_GameRect.dx,
  277. pMine->m_GameRect.dy,
  278. image, 
  279. 0,0,
  280. AEE_RO_COPY);
  281. IBITMAP_Release(image);
  282. // FALSE parameter forces an immediate screen update
  283. IDISPLAY_UpdateEx(pMine->m_pApp->m_pIDisplay,FALSE);
  284. // IMINEMUSIC_Start(pMine->m_pMusic,MMT_FLASH);
  285. // wait at least 1.5 seconds on intro screen
  286. time1= GETUPTIMEMS();
  287. while( (GETUPTIMEMS() - time1) < 500) {}
  288. }
  289. return TRUE;
  290. }
  291. ///////////////////////////////////////////////////////////////////////////////////////////////
  292. // STATIC FUNCTION DEFINE
  293. ///////////////////////////////////////////////////////////////////////////////////////////////
  294. static boolean WINMINE_Draw(IWinmine* pMine)
  295. {
  296. int x,y;
  297. AEERect gamerect,playrect,menurect;
  298. MINEASSERTNULL(pMine);
  299. //draw the frame
  300. gamerect=pMine->m_GameRect;
  301. playrect=pMine->m_PlayRect;
  302. menurect=pMine->m_MenuRect;
  303. IDISPLAY_DrawFrame(pMine->m_pApp->m_pIDisplay,&gamerect,AEE_FT_RAISED,MINEUI_OUTRECTCOLOR);
  304. IDISPLAY_DrawFrame(pMine->m_pApp->m_pIDisplay,&playrect,AEE_FT_LOWERED,MINEUI_INRECTCOLOR);
  305. IDISPLAY_DrawFrame(pMine->m_pApp->m_pIDisplay,&menurect,AEE_FT_LOWERED,MINEUI_FILLCOLOR);
  306. //draw the playrect
  307. for(x=0;x<MINE_LINE_NUM;x++)
  308. for(y=0;y<MINE_COLU_NUM;y++)
  309. WINMINE_DrawElement(pMine,x,y,FALSE);
  310. WINMINE_DrawElement(pMine,pMine->m_PointX,pMine->m_PointY,TRUE);
  311. //Update
  312. IDISPLAY_Update(pMine->m_pApp->m_pIDisplay); 
  313. return TRUE;
  314. }
  315. static boolean WINMINE_SUCCESSHDL(IWinmine* pMine)
  316. {
  317. int x,y;
  318. MINEASSERTNULL(pMine);
  319. pMine->m_Result=STAT_SUCCESS;
  320. for(x=0;x<MINE_LINE_NUM;x++)
  321. for(y=0;y<MINE_COLU_NUM;y++)
  322. {
  323. pMine->m_Data[x][y].m_bSel=TRUE;
  324. WINMINE_DrawElement(pMine,x,y,FALSE);
  325. }
  326. WINMINE_SaveScore(pMine);
  327. WINMINE_ShowMsg(pMine,1);
  328. IMINEMUSIC_Start(pMine->m_pMusic,MMT_SUCCESS);
  329. return TRUE;
  330. }
  331. static boolean WINMINE_FAILUREHDL(IWinmine* pMine)
  332. {
  333. int x,y;
  334. MINEASSERTNULL(pMine);
  335. pMine->m_Result=STAT_FAILURE;
  336. for(x=0;x<MINE_LINE_NUM;x++)
  337. for(y=0;y<MINE_COLU_NUM;y++)
  338. {
  339. pMine->m_Data[x][y].m_bSel=TRUE;
  340. WINMINE_DrawElement(pMine,x,y,FALSE);
  341. }
  342. WINMINE_ShowMsg(pMine,2);
  343. IMINEMUSIC_Start(pMine->m_pMusic,MMT_FAILURE);
  344. return TRUE;
  345. }
  346. static boolean WINMINE_BLANKHDL(IWinmine* pMine,int x,int y)
  347. {
  348. MINEASSERTNULL(pMine);
  349. if((x-1>=0)&&(y-1>=0))
  350. WINMINE_BlankElementHDL(pMine,x-1,y-1);
  351. if(x-1>=0)
  352. WINMINE_BlankElementHDL(pMine,x-1,y);
  353. if((x-1>=0)&&(y+1<MINE_COLU_NUM))
  354. WINMINE_BlankElementHDL(pMine,x-1,y+1);
  355. if(y-1>=0)
  356. WINMINE_BlankElementHDL(pMine,x,y-1);
  357. if(y+1<MINE_COLU_NUM)
  358. WINMINE_BlankElementHDL(pMine,x,y+1);
  359. if((x+1<MINE_LINE_NUM)&&(y-1>=0))
  360. WINMINE_BlankElementHDL(pMine,x+1,y-1);
  361. if(x+1<MINE_LINE_NUM)
  362. WINMINE_BlankElementHDL(pMine,x+1,y);
  363. if((x+1<MINE_LINE_NUM)&&(y+1<MINE_COLU_NUM))
  364. WINMINE_BlankElementHDL(pMine,x+1,y+1);
  365. return TRUE;
  366. }
  367. static void WINMINE_BlankElementHDL(IWinmine* pMine,int x,int y)
  368. {
  369. if(FALSE==pMine->m_Data[x][y].m_bSel)
  370. {
  371. pMine->m_Data[x][y].m_bSel=TRUE;
  372. WINMINE_DrawElement(pMine,x,y,FALSE);
  373. if(0==pMine->m_Data[x][y].m_Stat)
  374. WINMINE_BLANKHDL(pMine,x,y);
  375. }
  376. }
  377. static boolean WINMINE_ShowMsg(IWinmine* pMine,int nType)
  378. {
  379. AECHAR wBuf[32];
  380. char       cBuf[32];
  381. AEERect rt;
  382. RGBVAL col;
  383. MINEASSERTNULL(pMine);
  384. rt.x=pMine->m_MenuRect.x+2;
  385. rt.y=pMine->m_MenuRect.y+2;
  386. rt.dx=pMine->m_MenuRect.dx-4;
  387. rt.dy=pMine->m_MenuRect.dy-4;
  388. ISHELL_CancelTimer(pMine->m_pApp->m_pIShell,(PFNNOTIFY) WINMINE_MsgTimerHDL, pMine);
  389. switch(nType)
  390. {
  391. case 0://time
  392. //get the timer value
  393. if(0==pMine->m_TimerCount)
  394. {
  395. return WINMINE_FAILUREHDL(pMine);
  396. }
  397. else
  398. {
  399. SPRINTF(cBuf,"Best:%3d   score:%3d",pMine->m_MaxScore,pMine->m_TimerCount);
  400. STRTOWSTR(cBuf,wBuf,64);
  401. }
  402. pMine->m_TimerCount--;
  403. //show image
  404. col=IDISPLAY_SetColor(pMine->m_pApp->m_pIDisplay, CLR_USER_TEXT,MAKE_RGB(0,0,205));
  405. if(pMine->m_pImage)
  406. {
  407. IIMAGE_SetOffset(pMine->m_pImage,MSGOFFSET_TIMER,2);
  408. IIMAGE_Draw(pMine->m_pImage,rt.x,rt.y);
  409. IDISPLAY_DrawText(pMine->m_pApp->m_pIDisplay,AEE_FONT_NORMAL,wBuf,
  410. -1,0,0,&rt,IDF_ALIGN_CENTER |IDF_ALIGN_MIDDLE|IDF_RECT_FRAME|IDF_TEXT_TRANSPARENT);
  411. }
  412. else
  413. IDISPLAY_DrawText(pMine->m_pApp->m_pIDisplay,AEE_FONT_NORMAL,wBuf,
  414. -1,0,0,&rt,IDF_ALIGN_CENTER |IDF_ALIGN_MIDDLE|IDF_RECT_FRAME|IDF_RECT_FILL );
  415. IDISPLAY_SetColor(pMine->m_pApp->m_pIDisplay, CLR_USER_TEXT,col);
  416. //set timer
  417. ISHELL_SetTimer(pMine->m_pApp->m_pIShell,1000,(PFNNOTIFY) WINMINE_MsgTimerHDL, pMine);
  418. break;
  419. case 1://sucess
  420. if(pMine->m_pImage)
  421. {
  422. IIMAGE_SetOffset(pMine->m_pImage,MSGOFFSET_SUCCESS,10);
  423. IIMAGE_Draw(pMine->m_pImage,rt.x,rt.y);
  424. }
  425. else
  426. {
  427. STRTOWSTR("SUCCESS",wBuf,20);
  428. IDISPLAY_DrawText(pMine->m_pApp->m_pIDisplay,AEE_FONT_BOLD,wBuf,
  429. -1,0,0,&rt,IDF_ALIGN_CENTER |IDF_ALIGN_MIDDLE|IDF_RECT_FRAME|IDF_RECT_FILL );
  430. }
  431. break;
  432. case 2://failure
  433. if(pMine->m_pImage)
  434. {
  435. IIMAGE_SetOffset(pMine->m_pImage,MSGOFFSET_FAILURE,10);
  436. IIMAGE_Draw(pMine->m_pImage,rt.x,rt.y);
  437. }
  438. else
  439. {
  440. STRTOWSTR("FAILURE",wBuf,20);
  441. IDISPLAY_DrawText(pMine->m_pApp->m_pIDisplay,AEE_FONT_BOLD,wBuf,
  442. -1,0,0,&rt,IDF_ALIGN_CENTER |IDF_ALIGN_MIDDLE|IDF_RECT_FRAME|IDF_RECT_FILL );
  443. }
  444. break;
  445. default://error
  446. return FALSE;
  447. }
  448. IDISPLAY_Update(pMine->m_pApp->m_pIDisplay);
  449. return TRUE;
  450. }
  451. static void WINMINE_MsgTimerHDL(IWinmine* pMine)
  452. {
  453. WINMINE_ShowMsg(pMine,0);
  454. }
  455. static boolean WINMINE_DrawElement(IWinmine* pMine,int x,int y,boolean bSel)
  456. {
  457. AEERect rt,rtbak;
  458. MINEASSERTNULL(pMine);
  459. rt.dx=pMine->m_ElementWide;
  460. rt.dy=pMine->m_ElementHeight;
  461. rt.x=x*rt.dx+pMine->m_OffsetX;
  462. rt.y=y*rt.dy+pMine->m_OffsetY;
  463. rtbak=rt;
  464. if(FALSE==pMine->m_Data[x][y].m_bSel)
  465. WINMINE_DrawFrame(pMine,&rtbak,x,y);
  466. else
  467. {
  468. char cBuf[2];
  469. switch(pMine->m_Data[x][y].m_Stat)
  470. {
  471. case MINE_FLAGE:
  472. switch(pMine->m_Result)
  473. {
  474. case STAT_START:
  475. WINMINE_DrawFrame(pMine,&rtbak,x,y);
  476. WINMINE_DrawBanner(pMine,&rt);
  477. break;
  478. case STAT_SUCCESS:
  479. IDISPLAY_DrawRect(pMine->m_pApp->m_pIDisplay,&rtbak,MINEUI_FRAME,MINEUI_FILLCOLOR,IDF_RECT_FRAME|IDF_RECT_FILL);
  480. WINMINE_DrawMine(pMine,&rt);
  481. break;
  482. default:
  483. IDISPLAY_DrawRect(pMine->m_pApp->m_pIDisplay,&rtbak,MINEUI_FRAME,MINEUI_FILLCOLOR,IDF_RECT_FRAME|IDF_RECT_FILL);
  484. WINMINE_DrawBlast(pMine,&rt);
  485. }
  486. break;
  487. case 0:
  488. WINMINE_DrawNumber(pMine,&rt," ");
  489. break;
  490. default:
  491. SPRINTF(cBuf,"%d",pMine->m_Data[x][y].m_Stat);
  492. WINMINE_DrawNumber(pMine,&rt,cBuf);
  493. }
  494. }
  495. if(bSel)
  496. WINMINE_DrawCuror(pMine,&rt);
  497. return TRUE;
  498. }
  499. static boolean WINMINE_DrawCuror(IWinmine* pMine,AEERect* rt)
  500. {
  501. AEEEllipse ellipse;
  502. if(pMine->m_pGraphic)
  503. {
  504. ellipse.cx=rt->x+rt->dx/2;
  505. ellipse.cy=rt->y+rt->dy/2;
  506. ellipse.wx=rt->dx/2-2;
  507. ellipse.wy=rt->dy/2-2;
  508. IGRAPHICS_SetColor(pMine->m_pGraphic,255,0,0,255);
  509. IGRAPHICS_DrawEllipse(pMine->m_pGraphic,&ellipse);
  510. IGRAPHICS_SetColor(pMine->m_pGraphic,0,0,0,255);
  511. }
  512. return TRUE;
  513. }
  514. static boolean WINMINE_DrawMine(IWinmine* pMine,AEERect* rt)
  515. {
  516. AEECircle circle;
  517. if(pMine->m_pGraphic)
  518. {
  519. circle.cx=rt->x+rt->dx/2;
  520. circle.cy=rt->y+rt->dy/2;
  521. circle.r=(rt->dx>rt->y)?rt->y:rt->dx;
  522. circle.r=circle.r/2-4;
  523. IGRAPHICS_SetFillMode(pMine->m_pGraphic,TRUE);
  524. IGRAPHICS_SetFillColor(pMine->m_pGraphic,0,0,0,255);
  525. IGRAPHICS_DrawCircle(pMine->m_pGraphic,&circle);
  526. circle.r/=2;
  527. circle.cx-=circle.r;
  528. circle.cy-=circle.r;
  529. IGRAPHICS_SetFillColor(pMine->m_pGraphic,205,205,205,255);
  530. IGRAPHICS_DrawCircle(pMine->m_pGraphic,&circle);
  531. IGRAPHICS_SetFillMode(pMine->m_pGraphic,FALSE);
  532. }
  533. return TRUE;
  534. }
  535. static boolean WINMINE_DrawBlast(IWinmine* pMine,AEERect* rt)
  536. {
  537. AEELine line;
  538. int x,y,z;
  539. int16    lineLen=1; 
  540. x=rt->dx/2+rt->x;
  541. y=rt->dy/2+rt->y;
  542. z=(rt->dx>rt->dy)?(rt->dy/2):(rt->dx/2);
  543. //横线
  544. line.sx=rt->x+2;
  545. line.sy=y;
  546. line.ex=rt->x+rt->dx-2;
  547. line.ey=y;
  548. IGRAPHICS_DrawLine(pMine->m_pGraphic,&line);
  549. //竖线
  550. line.sx=x;
  551. line.sy=rt->y+2;
  552. line.ex=x;
  553. line.ey=rt->y+rt->dy-2;
  554. IGRAPHICS_DrawLine(pMine->m_pGraphic,&line);
  555. //Z
  556. z=z*3/5;
  557. //左斜线
  558. line.sx=x-z;
  559. line.sy=y-z;
  560. line.ex=x+z;
  561. line.ey=y+z;
  562. IGRAPHICS_DrawLine(pMine->m_pGraphic,&line);
  563. //右斜线
  564. line.sx=x+z;
  565. line.sy=y-z;
  566. line.ex=x-z;
  567. line.ey=y+z;
  568. IGRAPHICS_DrawLine(pMine->m_pGraphic,&line);
  569. //地雷
  570. WINMINE_DrawMine(pMine,rt);
  571. return TRUE;
  572. }
  573. static boolean WINMINE_DrawBanner(IWinmine* pMine,AEERect* rt)
  574. {
  575. AEERect rect;
  576. AEETriangle triagle;
  577. AEELine line;
  578. int nHeight=2;
  579. int x=rt->x+rt->dx/2;
  580. int z=rt->dx/3;
  581. IGRAPHICS_SetFillMode(pMine->m_pGraphic,TRUE);
  582. IGRAPHICS_SetFillColor(pMine->m_pGraphic,0,0,0,255);
  583. //mast
  584. line.sx=line.ex=x;
  585. line.sy=rt->y+2;
  586. line.ey=rt->y+rt->dy-4;
  587. IGRAPHICS_DrawLine(pMine->m_pGraphic,&line);
  588. //pedestal
  589. rect.x=x-z;
  590. rect.y=rt->y+rt->dy-nHeight-2;
  591. rect.dx=z*2;
  592. rect.dy=nHeight;
  593. IGRAPHICS_DrawRect(pMine->m_pGraphic,&rect);
  594. z/=2;
  595. rect.x=x-z;
  596. rect.y-=nHeight-1;
  597. rect.dx=z*2;
  598. rect.dy=nHeight;
  599. IGRAPHICS_DrawRect(pMine->m_pGraphic,&rect);
  600. //flage 
  601. triagle.x0=line.sx;
  602. triagle.y0=line.sy;
  603. triagle.x1=line.sx;
  604. triagle.y1=line.sy+(line.ey-line.sy)/2;
  605. triagle.x2=rt->x+2;
  606. triagle.y2=line.sy+(line.ey-line.sy)/4;
  607. IGRAPHICS_SetFillColor(pMine->m_pGraphic,255,0,0,255);
  608. IGRAPHICS_DrawTriangle(pMine->m_pGraphic,&triagle);
  609. IGRAPHICS_SetFillMode(pMine->m_pGraphic,FALSE);
  610. return TRUE;
  611. }
  612. static boolean WINMINE_DrawNumber(IWinmine* pMine,AEERect* rt,char* pText)
  613. {
  614. AECHAR wBuf[4];
  615. RGBVAL col=IDISPLAY_SetColor(pMine->m_pApp->m_pIDisplay,CLR_USER_BACKGROUND,MINEUI_FILLCOLOR);
  616. STRTOWSTR(pText,wBuf,4);
  617. IDISPLAY_DrawText(pMine->m_pApp->m_pIDisplay,AEE_FONT_BOLD,wBuf,
  618. -1,0,0,rt,IDF_ALIGN_CENTER |IDF_ALIGN_MIDDLE|IDF_RECT_FRAME|IDF_RECT_FILL);
  619. IDISPLAY_SetColor(pMine->m_pApp->m_pIDisplay,CLR_USER_BACKGROUND,col);
  620. return TRUE;
  621. }
  622. static boolean WINMINE_DrawFrame(IWinmine* pMine,AEERect* rt,int x,int y)
  623. {
  624. int cx=rt->x+2;
  625. int cy=rt->y+2;
  626. IDISPLAY_DrawFrame(pMine->m_pApp->m_pIDisplay,rt,AEE_FT_RAISED,MINEUI_FILLCOLOR);
  627. if(pMine->m_pGameImage)
  628. {
  629. IIMAGE_SetOffset(pMine->m_pGameImage,x*pMine->m_ElementWide,y*pMine->m_ElementHeight);
  630. IIMAGE_Draw(pMine->m_pGameImage,cx,cy);
  631. }
  632. return TRUE;
  633. }
  634. static void WINMINE_SaveScore(IWinmine* pMine)
  635. {
  636. TScore score;
  637. uint32 sec;
  638. if(pMine->m_TimerCount>pMine->m_MaxScore)
  639. {
  640. sec=GETTIMESECONDS();
  641. GETJULIANDATE(sec,&(score.m_Date));
  642. score.m_nScore=pMine->m_TimerCount;
  643. ISHELL_SetAppPrefs(pMine->m_pApp->m_pIShell,1,&score,sizeof(score));
  644. }
  645. }