📄 games_highscore.c
字号:
}
}
/*==================================================================================================
FUNCTION: Games_Highscore_Init
DESCRIPTION:
Description of this specific function.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
static void Games_Highscore_Init(void)
{
RM_RESOURCE_ID_T *ptr=OP_NULL;
RM_RESOURCE_ID_T title_id=OP_NULL;
is_dialog_alive = OP_FALSE;
switch (gamesApp_data.game_id)
{
#ifdef GAMES_FALLBALL
case APP_GAMES_FALLBALL :
title_id=PMPT_LIST_GOPHERS;
ptr=fallball_items;
break;
#endif
#ifdef GAMES_HUARONG
case APP_GAMES_HUARONG_MAP1:
title_id=PMPT_LIST_HUARONG_MAP1;
ptr=huarong_map1_items;
break;
case APP_GAMES_HUARONG_MAP2:
title_id=PMPT_LIST_HUARONG_MAP2;
ptr=huarong_map2_items;
break;
case APP_GAMES_HUARONG_MAP3:
title_id=PMPT_LIST_HUARONG_MAP3;
ptr=huarong_map3_items;
break;
case APP_GAMES_HUARONG_MAP4:
title_id=PMPT_LIST_HUARONG_MAP4;
ptr=huarong_map4_items;
break;
#endif
#ifdef GAMES_LIGHTUP
case APP_GAMES_LIGHTUP_3:
title_id=PMPT_LIST_LIGHTUP_3;
ptr=lightup_3_items;
break;
case APP_GAMES_LIGHTUP_4:
title_id=PMPT_LIST_LIGHTUP_4;
ptr=lightup_4_items;
break;
case APP_GAMES_LIGHTUP_5:
title_id=PMPT_LIST_LIGHTUP_5;
ptr=lightup_5_items;
break;
#endif
#ifdef GAMES_GOPHER
case APP_GAMES_GOPHER:
title_id=PMPT_LIST_STARWAR;
ptr=gopher_items;
break;
#endif
#ifdef GAMES_TETRIS
case APP_GAMES_TETRIS:
title_id=PMPT_LIST_TETRIS;
ptr=tetris_items; /*TO DO**/
break;
#endif
#ifdef GAMES_FRUIT
case APP_GAMES_FRUIT :
title_id=PMPT_LIST_FRUIT;
ptr=fruit_items;
break;
#endif
default:
break;
}
Games_Highscore_List_create(title_id, ptr);
}
static void Games_Highscore_List_create(RM_RESOURCE_ID_T title_id, RM_RESOURCE_ID_T *item_id)
{
OP_UINT16 score;
OP_UINT8 tmpstr[40];
char ss[10];
OP_UINT8 i;
is_list_empty = OP_FALSE;
op_memset((void*)tmpstr, 0, sizeof(tmpstr));
RM_GetResource(title_id,tmpstr,sizeof(tmpstr));
LIST_create(&display_list_buffer,
(char *)tmpstr,
TITLE_NORMAL,
LSA_NUMBER,
0);
for (i=0; i<MAX_HIGH_SCORE_RECORDS; i++)
{
RM_GetFeature(item_id[i], &score);
if (score > 0)
{
op_sprintf(ss,"%d",score);
op_memset((void*)tmpstr, 0, sizeof(tmpstr));
AtoU(tmpstr, (OP_UINT8 *)ss);
}
else
{
//AtoU(tmpstr, (OP_UINT8 *)"Empty");
util_get_text_from_res_w_max_len(PMPT_TEXT_EMPTY,tmpstr,sizeof(tmpstr));
if (i == 0)
{
is_list_empty = OP_TRUE;
}
}
LIST_Add_To(&display_list_buffer,
(char *)tmpstr,
0);
}
if (is_list_empty)
{
LIST_set_softkeys(&display_list_buffer,
PMPT_SKEY_EMPTY,
PMPT_SKEY_EMPTY,
PMPT_SKEY_BACK);
}
else
{
LIST_set_softkeys(&display_list_buffer,
PMPT_SKEY_CLEAR,
PMPT_SKEY_EMPTY,
PMPT_SKEY_BACK);
}
/* To make no item be highlighted */
display_list_buffer.cur_item = MAX(MAX_HIGH_SCORE_RECORDS, DS_SCRN_MAXLINES) + 1;
}
/*==================================================================================================
FUNCTION: highscore_popup_confirm_handler
DESCRIPTION:
Description of this specific function.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
static OP_BOOLEAN highscore_popup_confirm_handler
(
DS_POPUP_STATE_ENUM_T state,
OP_INT32 event
)
{
OP_UINT8 selection;
if((state == PS_STO_S)&&( gamesApp_data.popupwin))
{
selection = ds_get_popup_selection( gamesApp_data.popupwin);
switch (selection)
{
case 0 : /* Select YES */
is_yes = OP_TRUE;
break;
case 1 : /* Select NO */
default:
is_yes = OP_FALSE;
break;
}
}
return (OP_TRUE);
}
/*==================================================================================================
FUNCTION: NVMGR_set_default
DESCRIPTION:
Description of this specific function.
ARGUMENTS PASSED:
You may omit description of parameters whose name is descriptive enough to understand
by reading the code without reading the description of arguments
RETURN VALUE:
You may omit description of return value if the retunr value is generally understandable
by software engineers
IMPORTANT NOTES:
Describe anything that help understanding the function and important aspect of using
the function i.e side effect..etc
==================================================================================================*/
static OP_BOOLEAN highscore_set_default(void)
{
RM_RESOURCE_ID_T *rm_ids;
OP_INT8 i;
RM_RESOURCE_ID_T index;
OP_BOOLEAN result;
OP_UINT16 default_value;
result = OP_SUCCESS;
switch (gamesApp_data.game_id)
{
#ifdef GAMES_FALLBALL
case APP_GAMES_FALLBALL :
rm_ids = fallball_items;
break;
#endif
#ifdef GAMES_HUARONG
case APP_GAMES_HUARONG_MAP1:
rm_ids = huarong_map1_items;
break;
case APP_GAMES_HUARONG_MAP2:
rm_ids = huarong_map2_items;
break;
case APP_GAMES_HUARONG_MAP3:
rm_ids = huarong_map3_items;
break;
case APP_GAMES_HUARONG_MAP4:
rm_ids = huarong_map4_items;
break;
#endif
#ifdef GAMES_LIGHTUP
case APP_GAMES_LIGHTUP_3:
rm_ids = lightup_3_items;
break;
case APP_GAMES_LIGHTUP_4:
rm_ids = lightup_4_items;
break;
case APP_GAMES_LIGHTUP_5:
rm_ids = lightup_5_items;
break;
#endif
#ifdef GAMES_GOPHER
case APP_GAMES_GOPHER:
rm_ids = gopher_items;
break;
#endif
#ifdef GAMES_TETRIS
case APP_GAMES_TETRIS:
rm_ids = tetris_items;
break;
#endif
#ifdef GAMES_FRUIT
case APP_GAMES_FRUIT :
rm_ids = fruit_items;
break;
#endif
default:
break;
}
for (i=MAX_HIGH_SCORE_RECORDS; i>0; i--)
{
index = *(rm_ids + i-1);
if (RM_GetFeatureDefault(index, &default_value) == RM_FAIL)
{
result = OP_FAIL;
break;
}
if(RM_SetFeature(index, &default_value) == RM_FAIL)
{
result = OP_FAIL;
break;
}
}
return (result);
}
/*==================================================================================================
GLOBAL FUNCTIONS
==================================================================================================*/
/*==================================================================================================
FUNCTION: is_new_highscore
DESCRIPTION:
If the score is larger (or sometimes less) than any of the existed high scores of this game, refresh the high score
list and return true, else return false.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
OP_BOOLEAN is_new_highscore(APP_GAMES_ID_ENUM_T game_id, OP_INT16 score)
{
RM_RESOURCE_ID_T *ptr;
OP_INT8 i, j;
OP_UINT16 current_highscore[MAX_HIGH_SCORE_RECORDS];
OP_BOOLEAN ret_result;
/*
* whether the high score list is arranged as degressive list
* In some game, we want to get a highest score, but in some other games,
* we may want to record a least step number.
* So the high score list may be either degressive or increasing.
*/
OP_BOOLEAN is_degressive;
ret_result = OP_FALSE;
if (score == 0)
{
return ret_result;
}
switch (game_id)
{
#ifdef GAMES_FALLBALL
case APP_GAMES_FALLBALL :
ptr = fallball_items;
is_degressive = OP_TRUE;
break;
#endif
#ifdef GAMES_HUARONG
case APP_GAMES_HUARONG_MAP1:
ptr = huarong_map1_items;
is_degressive = OP_FALSE;
break;
case APP_GAMES_HUARONG_MAP2:
ptr = huarong_map2_items;
is_degressive = OP_FALSE;
break;
case APP_GAMES_HUARONG_MAP3:
ptr = huarong_map3_items;
is_degressive = OP_FALSE;
break;
case APP_GAMES_HUARONG_MAP4:
ptr = huarong_map4_items;
is_degressive = OP_FALSE;
break;
#endif
#ifdef GAMES_LIGHTUP
case APP_GAMES_LIGHTUP_3:
ptr = lightup_3_items;
is_degressive = OP_FALSE;
break;
case APP_GAMES_LIGHTUP_4:
ptr = lightup_4_items;
is_degressive = OP_FALSE;
break;
case APP_GAMES_LIGHTUP_5:
ptr = lightup_5_items;
is_degressive = OP_FALSE;
break;
#endif
#ifdef GAMES_GOPHER
case APP_GAMES_GOPHER:
ptr = gopher_items;
is_degressive = OP_TRUE;
break;
#endif
#ifdef GAMES_TETRIS
case APP_GAMES_TETRIS:
ptr = tetris_items;
is_degressive = OP_TRUE;
break;
#endif
#ifdef GAMES_FRUIT
case APP_GAMES_FRUIT :
ptr = fruit_items;
is_degressive = OP_TRUE;
break;
#endif
default:
break;
}
/* according to the value of is_degressive, judge whether the score is a new high score */
for (i=0; i<MAX_HIGH_SCORE_RECORDS; i++)
{
RM_GetFeature(*(ptr+i), &(current_highscore[i]));
}
if (is_degressive)
{
j = MAX_HIGH_SCORE_RECORDS-1;
while ( j>=0 && current_highscore[j] < score)
{
if (j < MAX_HIGH_SCORE_RECORDS - 1)
current_highscore[j+1] = current_highscore[j];
j--;
}
if (j < MAX_HIGH_SCORE_RECORDS - 1)
{
ret_result = OP_TRUE;
current_highscore[j+1] = score;
}
for (i = MAX_HIGH_SCORE_RECORDS-1; i > j; i--)
{
if (current_highscore[i] != 0)
RM_SetFeature(*(ptr+i), &(current_highscore[i]));
}
}
else /* the highscore list is increasing except the 0 records */
{
j = 0;
while (j<MAX_HIGH_SCORE_RECORDS && current_highscore[j] != 0 && current_highscore[j] <= score)
j++;
if (j < MAX_HIGH_SCORE_RECORDS)
{
for (i = MAX_HIGH_SCORE_RECORDS-1; i > j; i--)
{
if (current_highscore[i-1] != 0)
{
current_highscore[i] = current_highscore[i-1];
RM_SetFeature(*(ptr+i), &(current_highscore[i]));
}
}
current_highscore[j] = score;
RM_SetFeature(*(ptr+j), &(current_highscore[j]));
ret_result = OP_TRUE;
}
}
return ret_result;
}
/*================================================================================================*/
#ifdef __cplusplus
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -