mine.c
资源名称:brewmine3.rar [点击查看]
上传用户:yulinhuamu
上传日期:2009-12-26
资源大小:7287k
文件大小:20k
源码类别:
BREW编程
开发平台:
Visual C++
- #include "mine.h"
- ///////////////////////////////////////////////////////////////////////////////////////////////
- // STATIC FUNCTION DECLARE
- ///////////////////////////////////////////////////////////////////////////////////////////////
- #define MSGOFFSET_SUCCESS 212
- #define MSGOFFSET_TIMER 10
- #define MSGOFFSET_FAILURE 365
- #define MARGIN_RECT 3
- #define MINEUI_OUTRECTCOLOR MAKE_RGB(150,150,200)
- #define MINEUI_INRECTCOLOR MAKE_RGB(200,200,255)
- #define MINEUI_GRIDCOLOR MAKE_RGB(200,200,250)
- #define MINEUI_FILLCOLOR MAKE_RGB(211,211,211)
- #define MINEUI_SELIIEMCOLOR MAKE_RGB(180,180,200)
- #define MINEUI_CUROR MAKE_RGB(255,10,10)
- #define MINEUI_FRAME MAKE_RGB(0,0,0)
- #define MINEASSERTNULL(p) {if(NULL==p) return FALSE;}
- static boolean WINMINE_Draw(IWinmine* pMine);
- static boolean WINMINE_DrawElement(IWinmine* pMine,int x,int y,boolean bSel);
- static boolean WINMINE_DrawCuror(IWinmine* pMine,AEERect* rt);
- static boolean WINMINE_DrawMine(IWinmine* pMine,AEERect* rt);
- static boolean WINMINE_DrawBlast(IWinmine* pMine,AEERect* rt);
- static boolean WINMINE_DrawBanner(IWinmine* pMine,AEERect* rt);
- static boolean WINMINE_DrawNumber(IWinmine* pMine,AEERect* rt,char* pText);
- static boolean WINMINE_DrawFrame(IWinmine* pMine,AEERect* rt,int x,int y);
- static boolean WINMINE_SUCCESSHDL(IWinmine* pMine);
- static boolean WINMINE_FAILUREHDL(IWinmine* pMine);
- static boolean WINMINE_BLANKHDL(IWinmine* pMine,int x,int y);
- static boolean WINMINE_ShowMsg(IWinmine* pMine,int nType);
- static void WINMINE_SaveScore(IWinmine* pMine);
- static void WINMINE_BlankElementHDL(IWinmine* pMine,int x,int y);
- static void WINMINE_MsgTimerHDL(IWinmine* pMine);
- ///////////////////////////////////////////////////////////////////////////////////////////////
- // PUBLIC FUNCDEFINE
- ///////////////////////////////////////////////////////////////////////////////////////////////
- IWinmine* IWINMINE_CreateInstance()
- {
- IWinmine* pMine=MALLOCREC(IWinmine);
- if(pMine)
- {
- AEEDeviceInfo di;
- pMine->m_pApp=(AEEApplet*)GETAPPINSTANCE();
- ISHELL_GetDeviceInfo(pMine->m_pApp->m_pIShell, &di);
- pMine->m_GameRect.x=pMine->m_GameRect.y=0;
- pMine->m_GameRect.dx=di.cxScreen;
- pMine->m_GameRect.dy=di.cyScreen;
- pMine->m_PlayRect.x=pMine->m_GameRect.x+MARGIN_RECT;
- pMine->m_PlayRect.dx=pMine->m_GameRect.dx-2*MARGIN_RECT;
- pMine->m_PlayRect.dy=pMine->m_PlayRect.dx;
- pMine->m_PlayRect.y=pMine->m_GameRect.dy+pMine->m_GameRect.y-pMine->m_PlayRect.dy-MARGIN_RECT;
- pMine->m_MenuRect.x=pMine->m_PlayRect.x;
- pMine->m_MenuRect.dx=pMine->m_PlayRect.dx;
- pMine->m_MenuRect.y=pMine->m_GameRect.y+MARGIN_RECT;
- pMine->m_MenuRect.dy=pMine->m_GameRect.dy-pMine->m_PlayRect.dy-3*MARGIN_RECT;
- pMine->m_ElementWide=pMine->m_PlayRect.dx/MINE_LINE_NUM;
- pMine->m_ElementHeight=pMine->m_PlayRect.dy/MINE_COLU_NUM;
- pMine->m_OffsetX=pMine->m_PlayRect.x+(pMine->m_PlayRect.dx-pMine->m_ElementWide*MINE_LINE_NUM)/2;
- pMine->m_OffsetY=pMine->m_PlayRect.y+(pMine->m_PlayRect.dy-pMine->m_ElementHeight*MINE_COLU_NUM)/2;
- pMine->m_pImage=ISHELL_LoadImage(pMine->m_pApp->m_pIShell,"test.bmp");
- if(pMine->m_pImage)
- IIMAGE_SetDrawSize(pMine->m_pImage,pMine->m_MenuRect.dx-4,pMine->m_MenuRect.dy-4);
- pMine->m_pGameImage=ISHELL_LoadImage(pMine->m_pApp->m_pIShell,"x.bmp");
- if(pMine->m_pGameImage)
- IIMAGE_SetDrawSize(pMine->m_pGameImage,pMine->m_ElementWide-4,pMine->m_ElementHeight-4);
- ISHELL_CreateInstance(pMine->m_pApp->m_pIShell,AEECLSID_GRAPHICS,(void**)&pMine->m_pGraphic);
- pMine->m_pMusic=IMINEMUSIC_CreateInstance(pMine->m_pApp->m_pIShell);
- }
- return pMine;
- }
- boolean IWINMINE_Release(IWinmine* pMine)
- {
- MINEASSERTNULL(pMine);
- ISHELL_CancelTimer(pMine->m_pApp->m_pIShell,(PFNNOTIFY) WINMINE_MsgTimerHDL, pMine);
- if(pMine->m_pImage)
- {
- IIMAGE_Release(pMine->m_pImage);
- pMine->m_pImage=NULL;
- }
- if(pMine->m_pGameImage)
- {
- IIMAGE_Release(pMine->m_pGameImage);
- pMine->m_pGameImage=NULL;
- }
- if(pMine->m_pMusic)
- {
- IMINEMUSIC_Release(pMine->m_pMusic);
- pMine->m_pMusic=NULL;
- }
- if(pMine->m_pGraphic)
- {
- IGRAPHICS_Release(pMine->m_pGraphic);
- pMine->m_pGraphic=NULL;
- }
- return TRUE;
- }
- boolean IWINMINE_Start(IWinmine* pMine)
- {
- byte z;
- int x,y;
- TScore score;
- uint16 mineNum=0;
- MINEASSERTNULL(pMine);
- //zero list data
- for(x=0;x<MINE_LINE_NUM;x++)
- for(y=0;y<MINE_COLU_NUM;y++)
- {
- pMine->m_Data[x][y].m_bSel=FALSE;
- pMine->m_Data[x][y].m_Stat=0;
- }
- //generate the mine
- while(mineNum<MINE_NUM)
- {
- //x point
- GETRAND(&z,sizeof(z));
- x=z*MINE_LINE_NUM/256;
- //y point
- GETRAND(&z,sizeof(z));
- y=z*MINE_LINE_NUM/256;
- //check available
- if(MINE_FLAGE==pMine->m_Data[x][y].m_Stat)
- continue;
- pMine->m_Data[x][y].m_Stat=MINE_FLAGE;
- mineNum++;
- //set around grid
- if((x-1>=0)&&(y-1>=0)&&(MINE_FLAGE!=pMine->m_Data[x-1][y-1].m_Stat))
- pMine->m_Data[x-1][y-1].m_Stat++;
- if((x-1>=0)&&(MINE_FLAGE!=pMine->m_Data[x-1][y].m_Stat))
- pMine->m_Data[x-1][y].m_Stat++;
- if((x-1>=0)&&(y+1<MINE_COLU_NUM)&&(MINE_FLAGE!=pMine->m_Data[x-1][y+1].m_Stat))
- pMine->m_Data[x-1][y+1].m_Stat++;
- if((y-1>=0)&&(MINE_FLAGE!=pMine->m_Data[x][y-1].m_Stat))
- pMine->m_Data[x][y-1].m_Stat++;
- if((y+1<MINE_COLU_NUM)&&(MINE_FLAGE!=pMine->m_Data[x][y+1].m_Stat))
- pMine->m_Data[x][y+1].m_Stat++;
- if((x+1<MINE_LINE_NUM)&&(y-1>=0)&&(MINE_FLAGE!=pMine->m_Data[x+1][y-1].m_Stat))
- pMine->m_Data[x+1][y-1].m_Stat++;
- if((x+1<MINE_LINE_NUM)&&(MINE_FLAGE!=pMine->m_Data[x+1][y].m_Stat))
- pMine->m_Data[x+1][y].m_Stat++;
- if((x+1<MINE_LINE_NUM)&&(y+1<MINE_COLU_NUM)&&(MINE_FLAGE!=pMine->m_Data[x+1][y+1].m_Stat))
- pMine->m_Data[x+1][y+1].m_Stat++;
- }
- //other value
- pMine->m_PointX=MINE_LINE_NUM/2;
- pMine->m_PointY=MINE_COLU_NUM/2;
- pMine->m_Count=0;
- pMine->m_TimerCount=MINE_GAMETIMER;
- pMine->m_Result=STAT_START;
- //Score
- if(SUCCESS!=ISHELL_GetAppPrefs(pMine->m_pApp->m_pIShell,1,&score,sizeof(score)))
- pMine->m_MaxScore=0;
- else
- pMine->m_MaxScore=score.m_nScore;
- //draw list
- WINMINE_Draw(pMine);
- WINMINE_ShowMsg(pMine,0);
- IMINEMUSIC_Start(pMine->m_pMusic,MMT_START);
- return TRUE;
- }
- boolean IWINMINE_HandleEvent(IWinmine* pMine, uint16 wParam)
- {
- MINEASSERTNULL(pMine);
- if(STAT_START!=pMine->m_Result)
- return FALSE;
- switch(wParam)
- {
- case AVK_LEFT:
- WINMINE_DrawElement(pMine,pMine->m_PointX,pMine->m_PointY,FALSE);
- pMine->m_PointX--;
- if(pMine->m_PointX<0)
- pMine->m_PointX=MINE_LINE_NUM-1;
- WINMINE_DrawElement(pMine,pMine->m_PointX,pMine->m_PointY,TRUE);
- break;
- case AVK_RIGHT:
- WINMINE_DrawElement(pMine,pMine->m_PointX,pMine->m_PointY,FALSE);
- pMine->m_PointX++;
- if(MINE_LINE_NUM==pMine->m_PointX)
- pMine->m_PointX=0;
- WINMINE_DrawElement(pMine,pMine->m_PointX,pMine->m_PointY,TRUE);
- break;
- case AVK_UP:
- WINMINE_DrawElement(pMine,pMine->m_PointX,pMine->m_PointY,FALSE);
- pMine->m_PointY--;
- if(pMine->m_PointY<0)
- pMine->m_PointY=MINE_COLU_NUM-1;
- WINMINE_DrawElement(pMine,pMine->m_PointX,pMine->m_PointY,TRUE);
- break;
- case AVK_DOWN:
- WINMINE_DrawElement(pMine,pMine->m_PointX,pMine->m_PointY,FALSE);
- pMine->m_PointY++;
- if(MINE_COLU_NUM==pMine->m_PointY)
- pMine->m_PointY=0;
- WINMINE_DrawElement(pMine,pMine->m_PointX,pMine->m_PointY,TRUE);
- break;
- case AVK_SELECT:
- if(pMine->m_Data[pMine->m_PointX][pMine->m_PointY].m_bSel)
- return TRUE;
- pMine->m_Data[pMine->m_PointX][pMine->m_PointY].m_bSel=TRUE;
- switch(pMine->m_Data[pMine->m_PointX][pMine->m_PointY].m_Stat)
- {
- case MINE_FLAGE:
- WINMINE_FAILUREHDL(pMine);
- break;
- case 0:
- WINMINE_BLANKHDL(pMine,pMine->m_PointX,pMine->m_PointY);
- default:
- WINMINE_DrawElement(pMine,pMine->m_PointX,pMine->m_PointY,TRUE);
- }
- break;
- case AVK_CLR:
- if(pMine->m_Data[pMine->m_PointX][pMine->m_PointY].m_bSel)
- return TRUE;
- pMine->m_Data[pMine->m_PointX][pMine->m_PointY].m_bSel=TRUE;
- if(MINE_FLAGE!=pMine->m_Data[pMine->m_PointX][pMine->m_PointY].m_Stat)
- WINMINE_FAILUREHDL(pMine);
- else
- {
- pMine->m_Count++;
- if(MINE_NUM==pMine->m_Count)
- WINMINE_SUCCESSHDL(pMine);
- else
- WINMINE_DrawElement(pMine,pMine->m_PointX,pMine->m_PointY,TRUE);
- }
- break;
- case AVK_1:
- return WINMINE_SUCCESSHDL(pMine);
- case AVK_3:
- return WINMINE_FAILUREHDL(pMine);
- default:
- return FALSE;
- }
- IDISPLAY_Update(pMine->m_pApp->m_pIDisplay);
- return TRUE;
- }
- boolean IWINMINE_Pause(IWinmine* pMine)
- {
- MINEASSERTNULL(pMine);
- ISHELL_CancelTimer(pMine->m_pApp->m_pIShell,(PFNNOTIFY) WINMINE_MsgTimerHDL, pMine);
- return TRUE;
- }
- boolean IWINMINE_GetMaxScore(IWinmine* pMine,TScore* score)
- {
- MINEASSERTNULL(pMine);
- if(SUCCESS==ISHELL_GetAppPrefs(pMine->m_pApp->m_pIShell,1,&score,sizeof(score)))
- return TRUE;
- else
- return FALSE;
- }
- boolean IWINMINE_ResetMaxScore(IWinmine* pMine)
- {
- uint32 sec;
- TScore score;
- MINEASSERTNULL(pMine);
- sec=GETTIMESECONDS();
- GETJULIANDATE(sec,&(score.m_Date));
- score.m_nScore=0;
- ISHELL_SetAppPrefs(pMine->m_pApp->m_pIShell,1,&score,sizeof(score));
- return TRUE;
- }
- boolean IWINMINE_GetPlayRect(IWinmine* pMine,AEERect *rt)
- {
- if(pMine)
- *rt=pMine->m_PlayRect;
- return TRUE;
- }
- boolean IWINMINE_DrawIntroScreen(IWinmine* pMine)
- {
- IBitmap* image;
- uint32 time1;
- MINEASSERTNULL(pMine);
- // Draw the Background
- image = ISHELL_LoadBitmap(pMine->m_pApp->m_pIShell,"flash.bmp");
- if(image)
- {
- IDISPLAY_ClearScreen(pMine->m_pApp->m_pIDisplay);
- IDISPLAY_BitBlt(pMine->m_pApp->m_pIDisplay,
- 0,0,
- pMine->m_GameRect.dx,
- pMine->m_GameRect.dy,
- image,
- 0,0,
- AEE_RO_COPY);
- IBITMAP_Release(image);
- // FALSE parameter forces an immediate screen update
- IDISPLAY_UpdateEx(pMine->m_pApp->m_pIDisplay,FALSE);
- // IMINEMUSIC_Start(pMine->m_pMusic,MMT_FLASH);
- // wait at least 1.5 seconds on intro screen
- time1= GETUPTIMEMS();
- while( (GETUPTIMEMS() - time1) < 500) {}
- }
- return TRUE;
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////
- // STATIC FUNCTION DEFINE
- ///////////////////////////////////////////////////////////////////////////////////////////////
- static boolean WINMINE_Draw(IWinmine* pMine)
- {
- int x,y;
- AEERect gamerect,playrect,menurect;
- MINEASSERTNULL(pMine);
- //draw the frame
- gamerect=pMine->m_GameRect;
- playrect=pMine->m_PlayRect;
- menurect=pMine->m_MenuRect;
- IDISPLAY_DrawFrame(pMine->m_pApp->m_pIDisplay,&gamerect,AEE_FT_RAISED,MINEUI_OUTRECTCOLOR);
- IDISPLAY_DrawFrame(pMine->m_pApp->m_pIDisplay,&playrect,AEE_FT_LOWERED,MINEUI_INRECTCOLOR);
- IDISPLAY_DrawFrame(pMine->m_pApp->m_pIDisplay,&menurect,AEE_FT_LOWERED,MINEUI_FILLCOLOR);
- //draw the playrect
- for(x=0;x<MINE_LINE_NUM;x++)
- for(y=0;y<MINE_COLU_NUM;y++)
- WINMINE_DrawElement(pMine,x,y,FALSE);
- WINMINE_DrawElement(pMine,pMine->m_PointX,pMine->m_PointY,TRUE);
- //Update
- IDISPLAY_Update(pMine->m_pApp->m_pIDisplay);
- return TRUE;
- }
- static boolean WINMINE_SUCCESSHDL(IWinmine* pMine)
- {
- int x,y;
- MINEASSERTNULL(pMine);
- pMine->m_Result=STAT_SUCCESS;
- for(x=0;x<MINE_LINE_NUM;x++)
- for(y=0;y<MINE_COLU_NUM;y++)
- {
- pMine->m_Data[x][y].m_bSel=TRUE;
- WINMINE_DrawElement(pMine,x,y,FALSE);
- }
- WINMINE_SaveScore(pMine);
- WINMINE_ShowMsg(pMine,1);
- IMINEMUSIC_Start(pMine->m_pMusic,MMT_SUCCESS);
- return TRUE;
- }
- static boolean WINMINE_FAILUREHDL(IWinmine* pMine)
- {
- int x,y;
- MINEASSERTNULL(pMine);
- pMine->m_Result=STAT_FAILURE;
- for(x=0;x<MINE_LINE_NUM;x++)
- for(y=0;y<MINE_COLU_NUM;y++)
- {
- pMine->m_Data[x][y].m_bSel=TRUE;
- WINMINE_DrawElement(pMine,x,y,FALSE);
- }
- WINMINE_ShowMsg(pMine,2);
- IMINEMUSIC_Start(pMine->m_pMusic,MMT_FAILURE);
- return TRUE;
- }
- static boolean WINMINE_BLANKHDL(IWinmine* pMine,int x,int y)
- {
- MINEASSERTNULL(pMine);
- if((x-1>=0)&&(y-1>=0))
- WINMINE_BlankElementHDL(pMine,x-1,y-1);
- if(x-1>=0)
- WINMINE_BlankElementHDL(pMine,x-1,y);
- if((x-1>=0)&&(y+1<MINE_COLU_NUM))
- WINMINE_BlankElementHDL(pMine,x-1,y+1);
- if(y-1>=0)
- WINMINE_BlankElementHDL(pMine,x,y-1);
- if(y+1<MINE_COLU_NUM)
- WINMINE_BlankElementHDL(pMine,x,y+1);
- if((x+1<MINE_LINE_NUM)&&(y-1>=0))
- WINMINE_BlankElementHDL(pMine,x+1,y-1);
- if(x+1<MINE_LINE_NUM)
- WINMINE_BlankElementHDL(pMine,x+1,y);
- if((x+1<MINE_LINE_NUM)&&(y+1<MINE_COLU_NUM))
- WINMINE_BlankElementHDL(pMine,x+1,y+1);
- return TRUE;
- }
- static void WINMINE_BlankElementHDL(IWinmine* pMine,int x,int y)
- {
- if(FALSE==pMine->m_Data[x][y].m_bSel)
- {
- pMine->m_Data[x][y].m_bSel=TRUE;
- WINMINE_DrawElement(pMine,x,y,FALSE);
- if(0==pMine->m_Data[x][y].m_Stat)
- WINMINE_BLANKHDL(pMine,x,y);
- }
- }
- static boolean WINMINE_ShowMsg(IWinmine* pMine,int nType)
- {
- AECHAR wBuf[32];
- char cBuf[32];
- AEERect rt;
- RGBVAL col;
- MINEASSERTNULL(pMine);
- rt.x=pMine->m_MenuRect.x+2;
- rt.y=pMine->m_MenuRect.y+2;
- rt.dx=pMine->m_MenuRect.dx-4;
- rt.dy=pMine->m_MenuRect.dy-4;
- ISHELL_CancelTimer(pMine->m_pApp->m_pIShell,(PFNNOTIFY) WINMINE_MsgTimerHDL, pMine);
- switch(nType)
- {
- case 0://time
- //get the timer value
- if(0==pMine->m_TimerCount)
- {
- return WINMINE_FAILUREHDL(pMine);
- }
- else
- {
- SPRINTF(cBuf,"Best:%3d score:%3d",pMine->m_MaxScore,pMine->m_TimerCount);
- STRTOWSTR(cBuf,wBuf,64);
- }
- pMine->m_TimerCount--;
- //show image
- col=IDISPLAY_SetColor(pMine->m_pApp->m_pIDisplay, CLR_USER_TEXT,MAKE_RGB(0,0,205));
- if(pMine->m_pImage)
- {
- IIMAGE_SetOffset(pMine->m_pImage,MSGOFFSET_TIMER,2);
- IIMAGE_Draw(pMine->m_pImage,rt.x,rt.y);
- IDISPLAY_DrawText(pMine->m_pApp->m_pIDisplay,AEE_FONT_NORMAL,wBuf,
- -1,0,0,&rt,IDF_ALIGN_CENTER |IDF_ALIGN_MIDDLE|IDF_RECT_FRAME|IDF_TEXT_TRANSPARENT);
- }
- else
- IDISPLAY_DrawText(pMine->m_pApp->m_pIDisplay,AEE_FONT_NORMAL,wBuf,
- -1,0,0,&rt,IDF_ALIGN_CENTER |IDF_ALIGN_MIDDLE|IDF_RECT_FRAME|IDF_RECT_FILL );
- IDISPLAY_SetColor(pMine->m_pApp->m_pIDisplay, CLR_USER_TEXT,col);
- //set timer
- ISHELL_SetTimer(pMine->m_pApp->m_pIShell,1000,(PFNNOTIFY) WINMINE_MsgTimerHDL, pMine);
- break;
- case 1://sucess
- if(pMine->m_pImage)
- {
- IIMAGE_SetOffset(pMine->m_pImage,MSGOFFSET_SUCCESS,10);
- IIMAGE_Draw(pMine->m_pImage,rt.x,rt.y);
- }
- else
- {
- STRTOWSTR("SUCCESS",wBuf,20);
- IDISPLAY_DrawText(pMine->m_pApp->m_pIDisplay,AEE_FONT_BOLD,wBuf,
- -1,0,0,&rt,IDF_ALIGN_CENTER |IDF_ALIGN_MIDDLE|IDF_RECT_FRAME|IDF_RECT_FILL );
- }
- break;
- case 2://failure
- if(pMine->m_pImage)
- {
- IIMAGE_SetOffset(pMine->m_pImage,MSGOFFSET_FAILURE,10);
- IIMAGE_Draw(pMine->m_pImage,rt.x,rt.y);
- }
- else
- {
- STRTOWSTR("FAILURE",wBuf,20);
- IDISPLAY_DrawText(pMine->m_pApp->m_pIDisplay,AEE_FONT_BOLD,wBuf,
- -1,0,0,&rt,IDF_ALIGN_CENTER |IDF_ALIGN_MIDDLE|IDF_RECT_FRAME|IDF_RECT_FILL );
- }
- break;
- default://error
- return FALSE;
- }
- IDISPLAY_Update(pMine->m_pApp->m_pIDisplay);
- return TRUE;
- }
- static void WINMINE_MsgTimerHDL(IWinmine* pMine)
- {
- WINMINE_ShowMsg(pMine,0);
- }
- static boolean WINMINE_DrawElement(IWinmine* pMine,int x,int y,boolean bSel)
- {
- AEERect rt,rtbak;
- MINEASSERTNULL(pMine);
- rt.dx=pMine->m_ElementWide;
- rt.dy=pMine->m_ElementHeight;
- rt.x=x*rt.dx+pMine->m_OffsetX;
- rt.y=y*rt.dy+pMine->m_OffsetY;
- rtbak=rt;
- if(FALSE==pMine->m_Data[x][y].m_bSel)
- WINMINE_DrawFrame(pMine,&rtbak,x,y);
- else
- {
- char cBuf[2];
- switch(pMine->m_Data[x][y].m_Stat)
- {
- case MINE_FLAGE:
- switch(pMine->m_Result)
- {
- case STAT_START:
- WINMINE_DrawFrame(pMine,&rtbak,x,y);
- WINMINE_DrawBanner(pMine,&rt);
- break;
- case STAT_SUCCESS:
- IDISPLAY_DrawRect(pMine->m_pApp->m_pIDisplay,&rtbak,MINEUI_FRAME,MINEUI_FILLCOLOR,IDF_RECT_FRAME|IDF_RECT_FILL);
- WINMINE_DrawMine(pMine,&rt);
- break;
- default:
- IDISPLAY_DrawRect(pMine->m_pApp->m_pIDisplay,&rtbak,MINEUI_FRAME,MINEUI_FILLCOLOR,IDF_RECT_FRAME|IDF_RECT_FILL);
- WINMINE_DrawBlast(pMine,&rt);
- }
- break;
- case 0:
- WINMINE_DrawNumber(pMine,&rt," ");
- break;
- default:
- SPRINTF(cBuf,"%d",pMine->m_Data[x][y].m_Stat);
- WINMINE_DrawNumber(pMine,&rt,cBuf);
- }
- }
- if(bSel)
- WINMINE_DrawCuror(pMine,&rt);
- return TRUE;
- }
- static boolean WINMINE_DrawCuror(IWinmine* pMine,AEERect* rt)
- {
- AEEEllipse ellipse;
- if(pMine->m_pGraphic)
- {
- ellipse.cx=rt->x+rt->dx/2;
- ellipse.cy=rt->y+rt->dy/2;
- ellipse.wx=rt->dx/2-2;
- ellipse.wy=rt->dy/2-2;
- IGRAPHICS_SetColor(pMine->m_pGraphic,255,0,0,255);
- IGRAPHICS_DrawEllipse(pMine->m_pGraphic,&ellipse);
- IGRAPHICS_SetColor(pMine->m_pGraphic,0,0,0,255);
- }
- return TRUE;
- }
- static boolean WINMINE_DrawMine(IWinmine* pMine,AEERect* rt)
- {
- AEECircle circle;
- if(pMine->m_pGraphic)
- {
- circle.cx=rt->x+rt->dx/2;
- circle.cy=rt->y+rt->dy/2;
- circle.r=(rt->dx>rt->y)?rt->y:rt->dx;
- circle.r=circle.r/2-4;
- IGRAPHICS_SetFillMode(pMine->m_pGraphic,TRUE);
- IGRAPHICS_SetFillColor(pMine->m_pGraphic,0,0,0,255);
- IGRAPHICS_DrawCircle(pMine->m_pGraphic,&circle);
- circle.r/=2;
- circle.cx-=circle.r;
- circle.cy-=circle.r;
- IGRAPHICS_SetFillColor(pMine->m_pGraphic,205,205,205,255);
- IGRAPHICS_DrawCircle(pMine->m_pGraphic,&circle);
- IGRAPHICS_SetFillMode(pMine->m_pGraphic,FALSE);
- }
- return TRUE;
- }
- static boolean WINMINE_DrawBlast(IWinmine* pMine,AEERect* rt)
- {
- AEELine line;
- int x,y,z;
- int16 lineLen=1;
- x=rt->dx/2+rt->x;
- y=rt->dy/2+rt->y;
- z=(rt->dx>rt->dy)?(rt->dy/2):(rt->dx/2);
- //横线
- line.sx=rt->x+2;
- line.sy=y;
- line.ex=rt->x+rt->dx-2;
- line.ey=y;
- IGRAPHICS_DrawLine(pMine->m_pGraphic,&line);
- //竖线
- line.sx=x;
- line.sy=rt->y+2;
- line.ex=x;
- line.ey=rt->y+rt->dy-2;
- IGRAPHICS_DrawLine(pMine->m_pGraphic,&line);
- //Z
- z=z*3/5;
- //左斜线
- line.sx=x-z;
- line.sy=y-z;
- line.ex=x+z;
- line.ey=y+z;
- IGRAPHICS_DrawLine(pMine->m_pGraphic,&line);
- //右斜线
- line.sx=x+z;
- line.sy=y-z;
- line.ex=x-z;
- line.ey=y+z;
- IGRAPHICS_DrawLine(pMine->m_pGraphic,&line);
- //地雷
- WINMINE_DrawMine(pMine,rt);
- return TRUE;
- }
- static boolean WINMINE_DrawBanner(IWinmine* pMine,AEERect* rt)
- {
- AEERect rect;
- AEETriangle triagle;
- AEELine line;
- int nHeight=2;
- int x=rt->x+rt->dx/2;
- int z=rt->dx/3;
- IGRAPHICS_SetFillMode(pMine->m_pGraphic,TRUE);
- IGRAPHICS_SetFillColor(pMine->m_pGraphic,0,0,0,255);
- //mast
- line.sx=line.ex=x;
- line.sy=rt->y+2;
- line.ey=rt->y+rt->dy-4;
- IGRAPHICS_DrawLine(pMine->m_pGraphic,&line);
- //pedestal
- rect.x=x-z;
- rect.y=rt->y+rt->dy-nHeight-2;
- rect.dx=z*2;
- rect.dy=nHeight;
- IGRAPHICS_DrawRect(pMine->m_pGraphic,&rect);
- z/=2;
- rect.x=x-z;
- rect.y-=nHeight-1;
- rect.dx=z*2;
- rect.dy=nHeight;
- IGRAPHICS_DrawRect(pMine->m_pGraphic,&rect);
- //flage
- triagle.x0=line.sx;
- triagle.y0=line.sy;
- triagle.x1=line.sx;
- triagle.y1=line.sy+(line.ey-line.sy)/2;
- triagle.x2=rt->x+2;
- triagle.y2=line.sy+(line.ey-line.sy)/4;
- IGRAPHICS_SetFillColor(pMine->m_pGraphic,255,0,0,255);
- IGRAPHICS_DrawTriangle(pMine->m_pGraphic,&triagle);
- IGRAPHICS_SetFillMode(pMine->m_pGraphic,FALSE);
- return TRUE;
- }
- static boolean WINMINE_DrawNumber(IWinmine* pMine,AEERect* rt,char* pText)
- {
- AECHAR wBuf[4];
- RGBVAL col=IDISPLAY_SetColor(pMine->m_pApp->m_pIDisplay,CLR_USER_BACKGROUND,MINEUI_FILLCOLOR);
- STRTOWSTR(pText,wBuf,4);
- IDISPLAY_DrawText(pMine->m_pApp->m_pIDisplay,AEE_FONT_BOLD,wBuf,
- -1,0,0,rt,IDF_ALIGN_CENTER |IDF_ALIGN_MIDDLE|IDF_RECT_FRAME|IDF_RECT_FILL);
- IDISPLAY_SetColor(pMine->m_pApp->m_pIDisplay,CLR_USER_BACKGROUND,col);
- return TRUE;
- }
- static boolean WINMINE_DrawFrame(IWinmine* pMine,AEERect* rt,int x,int y)
- {
- int cx=rt->x+2;
- int cy=rt->y+2;
- IDISPLAY_DrawFrame(pMine->m_pApp->m_pIDisplay,rt,AEE_FT_RAISED,MINEUI_FILLCOLOR);
- if(pMine->m_pGameImage)
- {
- IIMAGE_SetOffset(pMine->m_pGameImage,x*pMine->m_ElementWide,y*pMine->m_ElementHeight);
- IIMAGE_Draw(pMine->m_pGameImage,cx,cy);
- }
- return TRUE;
- }
- static void WINMINE_SaveScore(IWinmine* pMine)
- {
- TScore score;
- uint32 sec;
- if(pMine->m_TimerCount>pMine->m_MaxScore)
- {
- sec=GETTIMESECONDS();
- GETJULIANDATE(sec,&(score.m_Date));
- score.m_nScore=pMine->m_TimerCount;
- ISHELL_SetAppPrefs(pMine->m_pApp->m_pIShell,1,&score,sizeof(score));
- }
- }