📄 games_huarong.c
字号:
break;
default:
break;
}
break;
default :
*handle = OP_FALSE;
break;
}
}
/*==================================================================================================
FUNCTION: APP_Huarong_Init
DESCRIPTION:
Description of this specific function.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
static void APP_Huarong_Init(void)
{
OP_UINT8 i,j;
OP_INT8 redundance;
OP_INT8 skey_high;
//if (current_map != gamesApp_data.select_item || hasPass()) /* to restore previous environment */
{
current_map = gamesApp_data.select_item;
for (i=0;i<12;i++)
{
pieces[i].x=-1;
pieces[i].y=-1;
}
for(i=0;i<rowNum;i++)
for(j=0;j<colNum;j++)
{
switch(current_map)
{
case 0:
map[i][j]=map0[i][j];
break;
case 1:
map[i][j]=map1[i][j];
break;
case 2:
map[i][j]=map2[i][j];
break;
case 3:
map[i][j]=map3[i][j];
break;
default:
map[i][j]=map0[i][j];
break;
}
if(pieces[map[i][j]].x<0)
{
pieces[map[i][j]].x=j;
pieces[map[i][j]].y=i;
}
}
initRoadblocks();
cursorX = 0;
cursorY = 0;
step=0;
state= MOVECURSOR;
state1=0;
}
#ifdef PACIFIC_VERSION
xoffset=0;
yoffset=0;
#else
xoffset=6;
yoffset=0;
#endif
gamePause=OP_FALSE;
TPO_SetCurrent_RPU(TPO_RUI_GAMES); /* Game pen process.*/
inGame=OP_TRUE;
if (gamesApp_data.audio_on == OP_TRUE)
{
SP_Audio_play_request(sound_list[0], gamesApp_data.volume, OP_FALSE);
}
clear_full_screen(HUARONG_BG_COLOR);
DrawBoard();
ds_set_softkeys_rm( PMPT_SKEY_RESTART,PMPT_SKEY_EMPTY, PMPT_SKEY_BACK);
/* draw soft keys */
ds_draw_text_rm( 5,204, PMPT_SKEY_RESTART, FONT_SIZE_SMALL|FONT_OVERLAP,
COLOR_RED,
COLOR_FONTBG);
ds_draw_text_rm(140,204, PMPT_SKEY_BACK, FONT_SIZE_SMALL|FONT_OVERLAP,
COLOR_RED,
COLOR_FONTBG);
if(ds_get_extend_softkey())
{
skey_high = LCD_EXT_SKEY_HIGH;
}
else
{
skey_high = LCD_SKEY_HIGH;
}
redundance=LCD_MAX_Y-LCD_ANNUN_HIGH-skey_high-RECTHEIGHT*rowNum-yoffset;/*If the game is added in dolphin,the blank is filled with COLOR_BLUE*/
if (redundance!=0)
{
ds_fill_rect(0,(OP_INT16)(RECTHEIGHT*rowNum+yoffset), RECTWIDTH+xoffset-1, (OP_INT16)(RECTHEIGHT*rowNum+yoffset+redundance-1), COLOR_BLUE);
ds_fill_rect(RECTWIDTH*3+xoffset,(OP_INT16)(RECTHEIGHT*rowNum+yoffset), LCD_MAX_X-1, (OP_INT16)(RECTHEIGHT*rowNum+yoffset+redundance-1), COLOR_BLUE);
}
Paint();
if (state==MOVEPIECE)
{
HuarongRun();
}
}
/*==================================================================================================
FUNCTION: initRoadblocks
DESCRIPTION:
Description of this specific function.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
static void initRoadblocks(void)
{
OP_UINT8 i;
OP_UINT8 tempx,tempy;
OP_UINT8 pieceWidth, pieceHeight;
/* initialize the roadblocks data of the chessmans */
for (i=0;i<12;i++)
{
pieceWidth = pieces[i].width;
pieceHeight = pieces[i].height;
pieces[i].roadblocks[UP]=pieceWidth;
pieces[i].roadblocks[LEFT]=pieceHeight;
pieces[i].roadblocks[DOWN]=pieceWidth;
pieces[i].roadblocks[RIGHT]=pieceHeight;
}
/* minus 1 from the roadblocks data if there is a blank contiguously */
for (i=10;i<12;i++)
{
tempx = pieces[i].x;
tempy = pieces[i].y;
if (tempx>0)
pieces[map[tempy][tempx-1]].roadblocks[RIGHT]--;
if (tempx<colNum-1)
pieces[map[tempy][tempx+1]].roadblocks[LEFT]--;
if (tempy>0)
pieces[map[tempy-1][tempx]].roadblocks[DOWN]--;
if (tempy<rowNum-1)
pieces[map[tempy+1][tempx]].roadblocks[UP]--;
}
if ( (pieces[10].roadblocks[LEFT] == 0 ||
pieces[10].roadblocks[RIGHT] == 0 ||
pieces[10].roadblocks[UP] == 0 ||
pieces[10].roadblocks[DOWN] == 0 ))
{
blanksContiguous=OP_TRUE;
}
else
{
blanksContiguous=OP_FALSE;
}
}
/*==================================================================================================
FUNCTION: onKeyPress
DESCRIPTION:
Description of this specific function.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
static void on_KeyPress(void *pMess)
{
KEYEVENT_STRUCT *pKey;
OP_UINT16 code;
SP_Audio_stop();
pKey=(KEYEVENT_STRUCT *)pMess;
code=pKey->code;
switch(code)
{
case KEY_SIDE_UP:
if (gamesApp_data.volume < VOLUME_LEVEL_SIZE-1)
{
gamesApp_data.volume++;
}
break;
case KEY_SIDE_DOWN:
if (gamesApp_data.volume > 0)
{
gamesApp_data.volume--;
}
break;
case KEY_8:
case KEY_DOWN:
if (inGame)
{
if (state==MOVEPIECE && pieces[map[cursorY][cursorX]].roadblocks[DOWN] == 0)
{
movePiece(DOWN);
}
else
{
state=MOVECURSOR;
moveCursor(DOWN);
}
}
break;
case KEY_2:
case KEY_UP:
if (inGame)
{
if (state==MOVEPIECE && pieces[map[cursorY][cursorX]].roadblocks[UP] == 0)
{
movePiece(UP);
}
else
{
state=MOVECURSOR;
moveCursor(UP);
}
}
break;
case KEY_LEFT:
case KEY_4:
if (inGame)
{
if (state==MOVEPIECE && pieces[map[cursorY][cursorX]].roadblocks[LEFT] == 0)
{
movePiece(LEFT);
}
else
{
state=MOVECURSOR;
moveCursor(LEFT);
}
}
break;
case KEY_RIGHT:
case KEY_6:
if (inGame)
{
if (state==MOVEPIECE && pieces[map[cursorY][cursorX]].roadblocks[RIGHT] == 0)
{
movePiece(RIGHT);
}
else
{
state=MOVECURSOR;
moveCursor(RIGHT);
}
}
break;
case KEY_5:
case KEY_OK:
if (inGame)
{
if (state==MOVECURSOR)
{
if (map[cursorY][cursorX]<10 &&
(pieces[map[cursorY][cursorX]].roadblocks[LEFT] == 0 ||
pieces[map[cursorY][cursorX]].roadblocks[RIGHT] == 0 ||
pieces[map[cursorY][cursorX]].roadblocks[UP] == 0 ||
pieces[map[cursorY][cursorX]].roadblocks[DOWN] == 0 ))
{
state=MOVEPIECE;
HuarongRun();
MoveIfCan();
HighlightSquare(map[cursorY][cursorX]);
ds_refresh();
}
}
else
{
state=MOVECURSOR;
Paint();
}
}
break;
case KEY_SOFT_LEFT:
if(gamesApp_data.popupwin != OP_NULL)
{
close_old_popup();
}
current_map = -1; /* set current_map to -1, so the status will be reset in function APP_Huarong_Init() */
OPUS_Stop_Timer(OPUS_TIMER_GAME_TIMING);
APP_Huarong_Init();
break;
case KEY_SOFT_RIGHT:
case KEY_CLEAR:
if(gamesApp_data.popupwin != OP_NULL)
{
close_old_popup();
}
inGame=OP_FALSE;
OPUS_Stop_Timer(OPUS_TIMER_GAME_TIMING);
Games_change_state((OP_UINT8) APP_GAMES_STATE_MENU);
break;
case KEY_END:
inGame=OP_FALSE;
OPUS_Stop_Timer(OPUS_TIMER_GAME_TIMING);
break;
default:
break;
}
}
/*==================================================================================================
FUNCTION: movePiece
DESCRIPTION:
Description of this specific function.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
static void movePiece(DIRECTION direct)
{
OP_UINT8 i;
OP_UINT8 temp,currentPiece;
OP_UINT8 pieceWidth, pieceHeight;
if (gamesApp_data.audio_on == OP_TRUE)
{
SP_Audio_play_request(sound_list[1], gamesApp_data.volume, OP_FALSE);
}
currentPiece=map[cursorY][cursorX];
pieceWidth = pieces[currentPiece].width;
pieceHeight = pieces[currentPiece].height;
switch(direct)
{
case DOWN:
for(i=0;i<pieceWidth;i++) /* colum */
{
temp = map[cursorY+pieceHeight][cursorX+i]; /*temp is a blank piece*/
map[cursorY+pieceHeight][cursorX+i] = currentPiece;
map[cursorY][cursorX+i]=temp;
pieces[temp].y=cursorY;
DrawSquare(temp);
};
cursorY++;
pieces[currentPiece].y++;
break;
case UP:
for(i=0;i<pieceWidth;i++) /*colum */
{
temp = map[cursorY-1][cursorX+i]; /* temp is a blank piece */
map[cursorY-1][cursorX+i] = currentPiece;
map[cursorY+pieceHeight-1][cursorX+i]=temp;
pieces[temp].y=cursorY+pieceHeight-1;
DrawSquare(temp);
};
cursorY--;
pieces[currentPiece].y--;
break;
case LEFT:
for(i=0;i<pieceHeight;i++) /* row*/
{
temp = map[cursorY+i][cursorX-1]; /*temp is a blank piece*/
map[cursorY+i][cursorX-1] = currentPiece;
map[cursorY+i][cursorX+pieceWidth-1]=temp;
pieces[temp].x=cursorX+pieceWidth-1;
DrawSquare(temp);
};
cursorX--;
pieces[currentPiece].x--;
break;
case RIGHT:
for(i=0;i<pieceHeight;i++) /*row*/
{
temp = map[cursorY+i][cursorX+pieceWidth]; /* temp is a blank piece */
map[cursorY+i][cursorX+pieceWidth] = currentPiece;
map[cursorY+i][cursorX]=temp;
pieces[temp].x=cursorX;
DrawSquare(temp);
};
cursorX++;
pieces[currentPiece].x++;
break;
default:
break;
}
step++;
DrawSquare(map[cursorY][cursorX]);
Paint();
ds_refresh();
if (hasPass())
{
ShowGameOver(step);
}
else
{
initRoadblocks();
}
}
/*==================================================================================================
FUNCTION: moveCursor
DESCRIPTION:
Description of this specific function.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -