📄 mmigame.c
字号:
/*******************************************************************************
CONDAT (UK)
********************************************************************************
This software product is the property of Condat (UK) Ltd and may not be
disclosed to any third party without the express permission of the owner.
********************************************************************************
$Project name: Basic MMI
$Project code: BMI (6349)
$Module: Game
$File: Mmigame.c
$Revision: 1.0
$Author: Condat(UK)
$Date: 03/07/01
********************************************************************************
Description
This provides the main game (four in a row) functionality
********************************************************************************/
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "mfw_sys.h"
//#include "typedef.h"
//#include "stddefs.h"
#include "custom.h"
#include "gsm.h"
#include "vsi.h"
#include "p_sim.h"
#include "cus_aci.h"
#include "mfw_mfw.h"
#include "mfw_win.h"
#include "mfw_kbd.h"
#include "mfw_edt.h"
#include "mfw_tim.h"
#include "mfw_icn.h"
#include "mfw_mnu.h"
#include "mfw_sat.h"
#include "dspl.h"
#include "MmiMmi.h"
#include "MmiDummy.h"
#include "MmiDialogs.h"
#include "MmiSoftkeys.h"
#include "MmiIcons.h"
#include "MmiMenu.h"
#include "gdi.h"
#include "Audio.h"
#include "MmiSounds.h"
#include "MmiBookShared.h"
//#include "bmieastapi.h"
#include "Gamedisplay.h"
#include "mmi3dframe.h"
#include "mmiblklangdb.h"
//#include "mmigameicons.h"
#include "mmigame.h"
//2004/05/24 yhf add
//#include "mmiicndialogs.h"
//#define MAXNUM_SCORE 4
#define MAXNUM_SCORE 5 //2004/07/05 yhf modify
#define MAXLEN_GAMEHELP 300
//char GameHelp_Buffer[MAXLEN_GAMEHELP];/*2004/5/26, wy modify*/
extern const MfwIcnAttr titleicons[ ];
void game_editor_init(MfwEdtAttr *edt_attr);
//T_MFW_HND game_display_help(MfwEdtAttr *edt_attr, int TxtId, char *strHelp);/*2004/5/26, wy modify*/
//void game_display_help(T_MFW_HND edt);/*2004/5/26, wy modify*/
void drawGameNumber(unsigned short posX,unsigned short posY,unsigned int num)
{
char szNum[8];
char *p;
unsigned short len;
sprintf(szNum,"%d",num);
len = strlen(szNum);
if(len == 0)
{
szNum[len++] = '0';
}
posX += (len - 1) * 6;
while(len)
{
len --;
p = (char*)GET_ICONATTR(ICON_GAME_NUMBER,0)->icons + (szNum[len]-'0') * 5*8*2;
posX -= 5;
dspl_BitBlt(posX,posY,5,8,0,(void*)p,0);
posX -= 1;
}
}//end drawGameNumber
int Game_addScore(GameScore *pffsScore,int totalscore)
{
int i,j;
for(i = 0; i < MAXNUM_SCORE; i++)
{
if(totalscore>pffsScore->score[i])
{
for(j=4;j>i;j--)
{
pffsScore->score[j]=pffsScore->score[j-1];
}
pffsScore->score[i]=totalscore;
break;
}
else if(totalscore==pffsScore->score[i])
break; //2004/07/05 yhf add
}
return i;
}
int Game_resetScore(GameScore *pffsScore)
{
int i = 0;
for(i = 0; i < MAXNUM_SCORE; i++)
{
pffsScore->score[i] = 0;
}
}
/***********************************************************************
$Arguments:
focusline:
flag: 0-init
1-game over
************************************************************************/
//2004/05/25 yhf modify
int Game_Scoreshow(GameScore *pffsScore,int totalscore,UBYTE gametype,UBYTE flag)
{
int ret=-1;
U8 i = 0xff,j;
char scoretemp[7],temp[2];
// U32 color ;
/* 2004/06 sunsj modify for picture manage */
DRAW_ICON(ICON_SPECIAL_BG);
//drawIconByIcnAttr((MfwIcnAttr*)&icnSpBkgAttr,0);
if(totalscore >0)
{
i = Game_addScore(pffsScore,totalscore);
}
// dspl_BitBlt(0,0,120,18,0,(void*)gameTitle,0);
drawcolorclarity(36, 1, (char *)MmiRsrcGetText(TxtGameScore),0x000000);
for(j=0;j<5;j++)
{
U32 color = 0x00;
memset(scoretemp,0,7*sizeof(char));
memset(temp,0,2*sizeof(char));
temp[0]=j+49;
set_font_type(UNI12X12_FONT);
if(i == j)
color = 0xff0000;
drawcolorclarity(15,j*20+22,(char *)temp,color);
Print_Number((char *)scoretemp,7,(U32)pffsScore->score[j]);
set_font_type(UNI12X12_FONT);
drawcolorclarity(67,j*20+22,(char *)scoretemp,color);
}
if(flag == 1)
{
memset(scoretemp,0,7*sizeof(char));
Print_Number((char *)scoretemp,7,(U32)totalscore);
set_font_type(UNI12X12_FONT);
//drawcolorclarity(15,122,(char *)MmiRsrcGetText(TxtGameTotalScore),0xff00000);
set_font_type(UNI12X12_FONT);
drawcolorclarity(67,122,(char *)scoretemp,0xff0000);
dsplsoftkey(TxtGameRestart, TxtGameExit);
}
else
dsplsoftkey(TxtSoftClearall, TxtSoftBack);
return ret;
}//end Game_Scoreshow
/*****************************************************************************************
$Name: Game_StageSelect
$History: 2004-04-08 Sunny modify
*****************************************************************************************/
//2004/05/24 yhf modify
#if (MAIN_LCD_SIZE==4)
void Game_StageSelect(U16 nTotal,U16 nCurrent,char* szInput)
{
U32 oldcolor;
MfwRect rect;
game_Line lineData;
U16 len,posX;
static char temp[7];
/* 2004/06 sunsj modify for picture manage */
DRAW_ICON(ICON_SPECIAL_BG);
//drawIconByIcnAttr((MfwIcnAttr*)&icnSpBkgAttr,0); /* display title */
//title
drawcolorclarity(30, 1, (char *)MmiRsrcGetText(TxtGameselect) ,0x000000);
//当前/总数
dspl_TextOut(26,30,DSPL_TXTATTR_TRANSPARENT,(void *)MmiRsrcGetText(TxtGameStageCruTtl)); /* display game select last */
oldcolor = dspl_SetBkgColor(0xF2CFEA);
rect.px = 30;
rect.py = 48;
rect.sx = 60;
rect.sy = 19;
dspl_fill_rectangle(rect.px, rect.py, rect.px + rect.sx, rect.py + rect.sy);
dspl_SetBkgColor(oldcolor);
draw3drect(rect, 0xF2CFEA, 0x95668A );
sprintf(temp,"%03d/%03d",nCurrent,nTotal);
len = 8*strlen(temp);
posX = 32+(55-len)/2;
dspl_TextOut(posX,51,DSPL_TXTATTR_TRANSPARENT,(void *)temp);
lineData.x1=7;
lineData.x2=113;
lineData.y1=79;
lineData.y2=79;
lineData.color=0xB9D9EA;
DrawLine(lineData);
lineData.x1=6;
lineData.x2=114;
lineData.y1=80;
lineData.y2=80;
lineData.color=0x5474A7;
DrawLine(lineData);
lineData.x1=7;
lineData.x2=113;
lineData.y1=81;
lineData.y2=81;
lineData.color=0xB9D9EA;
DrawLine(lineData);
dspl_TextOut(30,94,DSPL_TXTATTR_TRANSPARENT,(void *)MmiRsrcGetText(TxtGameStageInput)); /* display the game you want to select */
oldcolor = dspl_SetBkgColor(0xDBFFFF);
dspl_fill_rectangle(32, 112, 87, 131);
dspl_SetBkgColor(oldcolor);
rect.px = 32;
rect.py = 112;
rect.sx = 55;
rect.sy = 19;
draw3drect(rect, 0x5474A7, 0xB9D9EA );
len = 8*strlen(szInput);
posX = 32+(55-len)/2;
set_font_type(UNI12X12_FONT);
dspl_TextOut(posX,115,DSPL_TXTATTR_TRANSPARENT,(void *)szInput);
if(strlen(szInput)) /* display softkey */
dsplsoftkey(TxtSoftOK, TxtDelete);
else
dsplsoftkey(TxtSoftOK, TxtSoftBack);
}
#endif
#if (MAIN_LCD_SIZE==3)
void Game_StageSelect(U16 nTotal,U16 nCurrent,char* szInput)
{
U32 oldcolor;
MfwRect rect;
game_Line lineData;
U16 posX;
static char temp[7];
char *text;
int nWidth = 0;
extern const unsigned char specialbackground[];
extern const MfwIcnAttr titleicons[];
//background
dspl_BitBlt(0, 0, 128, 113, 0, (void * )specialbackground, 0); //shiheng 288 /* display title */
//titleicon
drawIconByIcnAttr((MfwIcnAttr *)&titleicons[0], (MfwIcnAttr *)0);
//title
text = MmiRsrcGetText(TxtGameselect);
posX = (SCREEN_WIDTH - get_StringWidth(text)) / 2;
drawcolorclarity(posX, 0, text ,0x000000);
//当前/总数
text = MmiRsrcGetText(TxtGameStageCruTtl);
posX = (SCREEN_WIDTH - get_StringWidth(text)) / 2;
dspl_TextOut(posX,SECOND_LINE,DSPL_TXTATTR_TRANSPARENT,text); //shiheng 288 modify
/* display game select last */
sprintf(temp,"%03d/%03d",nCurrent,nTotal);
nWidth = get_StringWidth(temp);
oldcolor = dspl_SetBkgColor(0xF2CFEA);
rect.px = (SCREEN_WIDTH - nWidth - 20) /2;
rect.py = THIRD_LINE;//SECOND_LINE;
rect.sx = nWidth + 20;
rect.sy = LINE_HEIGHT;
dspl_fill_rectangle(rect.px, rect.py, rect.px + rect.sx, rect.py + rect.sy);
dspl_SetBkgColor(oldcolor);
draw3drect(rect, 0xF2CFEA, 0x95668A );
posX = (SCREEN_WIDTH - nWidth) / 2;
dspl_TextOut(posX,THIRD_LINE + 1,DSPL_TXTATTR_TRANSPARENT,(void *)temp);
/* display the game you want to select */
text = MmiRsrcGetText(TxtGameStageInput);
posX = (SCREEN_WIDTH - get_StringWidth(text)) / 2;
dspl_TextOut(posX,FOURTH_LINE + 1,DSPL_TXTATTR_TRANSPARENT,text);
oldcolor = dspl_SetBkgColor(0xDBFFFF);
rect.px = (SCREEN_WIDTH - 60) /2;
rect.py = FIFTH_LINE + 2;
rect.sx = 60;
rect.sy = LINE_HEIGHT;
dspl_fill_rectangle(rect.px, rect.py, rect.px + rect.sx, rect.py + rect.sy);
dspl_SetBkgColor(oldcolor);
draw3drect(rect, 0x5474A7, 0xB9D9EA );
nWidth = get_StringWidth(szInput);
posX = (SCREEN_WIDTH - nWidth) / 2;
//set_font_type(UNI12X12_FONT);
dspl_TextOut(posX,FIFTH_LINE + 3,DSPL_TXTATTR_TRANSPARENT,(void *)szInput);
if(strlen(szInput))
dsplsoftkey(TxtSoftOK, TxtDelete);
else
dsplsoftkey(TxtSoftOK, TxtSoftBack);
}
#endif
#if(MAIN_LCD_SIZE==3)
void game_display_help(T_MFW_HND edt)
{
MfwIcnAttr *icon = 0;
U8 startPos = 0;
char *text;
icon = (MfwIcnAttr *)&titleicons[0];
dspl_BitBlt(icon->area.px, icon->area.py, icon->area.sx, icon->area.sy, 0, (void*)icon->icons, 0);
text = (char *)MmiRsrcGetText(TxtGamehelp);
startPos = (SCREEN_SIZE_X - get_StringWidth(text)) /2 ;
drawcolorclarity(startPos, 0, text, 0);
edtShow(edt);
displaySoftKeys(TxtSoftOK, TxtSoftBack);
}
#endif
/*2004/5/26, wy modify begin*/
/*******************************************************************************************
$Function: game_editor_init
$Description:
$Author: Sunny
$Date: 2004-04-23
*******************************************************************************************/
void game_editor_init(MfwEdtAttr *edt_attr)
{
edt_attr->win.px = 0;
edt_attr->win.py = 14;
edt_attr->win.sx = SCREEN_SIZE_X - edt_attr->win.px;
edt_attr->win.sy = SCREEN_SIZE_Y - edt_attr->win.py -dspl_GetFontHeight()-2;
edt_attr->size = MAXLEN_GAMEHELP + 3;
edt_attr->title_id = 0;
edt_attr->titleMode = 0;
edt_attr->mode = edtCurNone; //read only
edt_attr->fgColor = 0xF6F2CD;
edt_attr->font = 0;
}
//2004/05/24 yhf add
void Game_RestScore(GameScore *pffsScore)
{
memset(pffsScore->score,0,sizeof(pffsScore->score[0])*5);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -