📄 games_huarong.c
字号:
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
static void moveCursor(DIRECTION direct)
{
OP_UINT8 currentPiece;
OP_UINT8 pieceWidth, pieceHeight;
OP_UINT8 tempx,tempy;
currentPiece=map[cursorY][cursorX];
pieceWidth = pieces[currentPiece].width;
pieceHeight = pieces[currentPiece].height;
if (blanksContiguous && currentPiece>9)
{
DrawSquare(10);
DrawSquare(11);
}
else
{
DrawSquare(currentPiece);
}
switch(direct)
{
case DOWN:
/* if the blanks are contiguous, move cursor to the lower one*/
if (blanksContiguous && map[cursorY][cursorX]>9)
{
cursorY=MAX(pieces[10].y, pieces[11].y);
}
if (cursorY + pieceHeight < rowNum)
{
tempx = pieces[map[cursorY + pieceHeight][cursorX]].x;
tempy = pieces[map[cursorY + pieceHeight][cursorX]].y;
cursorX = tempx;
cursorY = tempy;
}
break;
case UP:
if (cursorY >0)
{
tempx = pieces[map[cursorY-1][cursorX]].x;
tempy = pieces[map[cursorY-1][cursorX]].y;
cursorX = tempx;
cursorY = tempy;
}
break;
case LEFT:
if ( cursorX > 0)
{
tempx = pieces[map[cursorY][cursorX-1]].x;
tempy = pieces[map[cursorY][cursorX-1]].y;
cursorX = tempx;
cursorY = tempy;
}
break;
case RIGHT:
/* if the blanks are contiguous, move cursor to the right one*/
if (blanksContiguous && map[cursorY][cursorX]>9)
{
cursorX=MAX(pieces[10].x, pieces[11].x);
}
if (cursorX + pieceWidth < colNum)
{
tempx = pieces[map[cursorY][cursorX+pieceWidth]].x;
tempy = pieces[map[cursorY][cursorX+pieceWidth]].y;
cursorX = tempx;
cursorY = tempy;
}
break;
default:
break;
}
if (blanksContiguous && map[cursorY][cursorX]>9)
{
cursorX=MIN(pieces[10].x, pieces[11].x);
cursorY=MIN(pieces[10].y, pieces[11].y);
HighlightSquare(21); /* highlight the two contiguous blanks */
}
else
{
HighlightSquare(map[cursorY][cursorX]);
}
Paint();
ds_refresh();
}
/*==================================================================================================
FUNCTION: Paint
DESCRIPTION:
Description of this specific function.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
static void Paint(void)
{
OP_UINT8 i;
for (i=0;i<12;i++)
{
DrawSquare(i);
}
if (state==MOVECURSOR)
{
if (map[cursorY][cursorX]>9 && blanksContiguous)
{
HighlightSquare(21); /* highlight the two contiguous blanks */
}
else
{
HighlightSquare(map[cursorY][cursorX]);
}
}
ds_refresh();
}
/*==================================================================================================
FUNCTION: DrawSquare
DESCRIPTION:
Description of this specific function.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
static void DrawSquare(OP_INT8 index)
{
OP_INT16 x,y;
OP_INT8 col,row;
col=pieces[index].x;
row=pieces[index].y;
x = (OP_INT16) xoffset+FRAMEWIDTH+col*RECTWIDTH;
y = (OP_INT16) yoffset+FRAMEWIDTH+row*RECTHEIGHT;
if (pieces[index].bitmapid == Blank)
{
ds_fill_rect(x, y, (OP_INT16)(x + RECTWIDTH-1), (OP_INT16)(y + RECTHEIGHT-1), BLANK_COLOR);
}
else
{
ds_draw_bitmap_image_rm(x, y, pieces[index].bitmapid);
}
}
/*==================================================================================================
FUNCTION: HighlightSquare
DESCRIPTION:
Description of this specific function.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
static void HighlightSquare(OP_INT8 index)
{
OP_UINT16 x,y;
OP_UINT16 x1,y1;
if (index<12) /* to highlight a normal chessman */
{
x = (OP_UINT16) xoffset+FRAMEWIDTH+pieces[index].x*RECTWIDTH;
x1=x+pieces[index].width*RECTWIDTH-1;
y = (OP_UINT16) yoffset+FRAMEWIDTH+pieces[index].y*RECTHEIGHT;
y1=y+pieces[index].height*RECTHEIGHT-1;
}
else /* to highlight the two contiguous blanks */
{
x= (OP_UINT16) xoffset+FRAMEWIDTH+MIN(pieces[10].x, pieces[11].x)*RECTWIDTH;
x1= (OP_UINT16) xoffset+FRAMEWIDTH+(MAX(pieces[10].x, pieces[11].x)+1)*RECTWIDTH-1;
y= (OP_UINT16) yoffset+FRAMEWIDTH+MIN(pieces[10].y, pieces[11].y)*RECTHEIGHT;
y1= (OP_UINT16) yoffset+FRAMEWIDTH+(MAX(pieces[10].y, pieces[11].y)+1)*RECTHEIGHT-1;
}
ds_draw_rect((OP_INT16)(x), (OP_INT16)(y), (OP_INT16)(x1), (OP_INT16)(y1), COLOR_GREEN);
}
/*==================================================================================================
FUNCTION: DrawBoard
DESCRIPTION:
Description of this specific function.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
static void DrawBoard(void)
{
OP_INT16 x,y;
OP_INT16 x1,y1;
x = (OP_INT16) xoffset;
y = (OP_INT16) yoffset;
x1 = x+4*RECTWIDTH+2*FRAMEWIDTH-1;
y1 = y+FRAMEWIDTH-1;
ds_draw_button_rect(x, y, x1, y1, FRAME_TOPLEFT_COLOR, FRAME_RIGHTBOTTOM_COLOR);
ds_fill_rect((OP_INT16)(x+1), (OP_INT16)(y+1), (OP_INT16)(x1-1), (OP_INT16)(y1-1), FRAME_FILL_COLOR);
x = (OP_INT16) xoffset;
y = (OP_INT16) yoffset+FRAMEWIDTH+5*RECTHEIGHT;
x1 = x+FRAMEWIDTH+RECTWIDTH-1;
y1 = y+FRAMEWIDTH-1;
ds_draw_button_rect(x, y, x1, y1, FRAME_TOPLEFT_COLOR, FRAME_RIGHTBOTTOM_COLOR);
ds_fill_rect((OP_INT16)(x+1), (OP_INT16)(y+1), (OP_INT16)(x1-1), (OP_INT16)(y1-1), FRAME_FILL_COLOR);
x = (OP_INT16) xoffset+FRAMEWIDTH+3*RECTWIDTH;
y = (OP_INT16) yoffset+FRAMEWIDTH+5*RECTHEIGHT;
x1 = x+FRAMEWIDTH+RECTWIDTH-1;
y1 = y+FRAMEWIDTH-1;
ds_draw_button_rect(x, y, x1, y1, FRAME_TOPLEFT_COLOR, FRAME_RIGHTBOTTOM_COLOR);
ds_fill_rect((OP_INT16)(x+1), (OP_INT16)(y+1), (OP_INT16)(x1-1), (OP_INT16)(y1-1), FRAME_FILL_COLOR);
x = (OP_INT16) xoffset;
y = (OP_INT16) yoffset+FRAMEWIDTH;
x1 = x+FRAMEWIDTH-1;
y1 = y+5*RECTHEIGHT-1;
ds_draw_button_rect(x, y, x1, y1, FRAME_TOPLEFT_COLOR, FRAME_RIGHTBOTTOM_COLOR);
ds_fill_rect((OP_INT16)(x+1), (OP_INT16)(y-1), (OP_INT16)(x1-1), (OP_INT16)(y1+1), FRAME_FILL_COLOR);
x = (OP_INT16) xoffset+FRAMEWIDTH+4*RECTWIDTH;
y = (OP_INT16) yoffset+FRAMEWIDTH;
x1 = x+FRAMEWIDTH-1;
y1 = y+5*RECTHEIGHT-1;
ds_draw_button_rect(x, y, x1, y1, FRAME_TOPLEFT_COLOR, FRAME_RIGHTBOTTOM_COLOR);
ds_fill_rect((OP_INT16)(x+1), (OP_INT16)(y-1), (OP_INT16)(x1-1), (OP_INT16)(y1+1), FRAME_FILL_COLOR);
ds_draw_line(x1, (OP_INT16)(y-1), x1, (OP_INT16)(y1+1), FRAME_RIGHTBOTTOM_COLOR);
}
/*==================================================================================================
FUNCTION: HuarongRun
DESCRIPTION:
Description of this specific function.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
static void HuarongRun(void )
{
/*OPUS_Stop_Timer(OPUS_TIMER_GAME_TIMING);*/
state1= 1-state1;
if (state1)
{
HighlightSquare(map[cursorY][cursorX]);
}
else
{
DrawSquare(map[cursorY][cursorX]);
}
ds_refresh();
OPUS_Start_Timer(OPUS_TIMER_GAME_TIMING, 1000, 0, ONE_SHOT);
}
/*==================================================================================================
FUNCTION: hasPass
DESCRIPTION:
Description of this specific function.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
static OP_BOOLEAN hasPass(void )
{
return (pieces[0].x==1 && pieces[0].y==3);
}
/*==================================================================================================
FUNCTION: Huarong_Penmove
DESCRIPTION:
Description of this specific function.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
static OP_BOOLEAN Huarong_Penmove()
{
OP_UINT8 k=0,curx,cury;
OP_INT16 stepx,stepy,loopx,loopy;
OP_BOOLEAN hasMovedx=OP_TRUE,hasMovedy=OP_TRUE;
/*Translate the pen message to square position.*/
if(map[posy][posx] == map[cursorY][cursorX])
{
return OP_TRUE;
}
curx=posx;
cury=posy;
stepx=posx-cursorX;
stepy=posy-cursorY;
loopx=(stepx>0) ? stepx:(-stepx);
loopy=(stepy>0) ? stepy:(-stepy);
op_debug(DEBUG_MED,"map[%d+1][%d]=%d\n",cursorX,cursorY,map[cursorX+1][cursorY]);
op_debug(DEBUG_MED,"map[%d][%d]=%d\n",cursorX,cursorY,map[cursorX+1][cursorY]);
DrawSquare(map[cursorY][cursorX]);
/* Judge the exact step the picture should move.*/
if(stepx>0 && map[posy][posx-1]==map[posy][posx] )
{
curx--;
stepx--;
loopx--;
}
if(stepx<0 && map[posy][posx+1]==map[posy][posx] )
{
stepx--;
loopx--;
}
if(stepy>0 && map[posy-1][posx]==map[posy][posx] )
{
cury--;
stepy--;
loopy--;
}
if(stepy<0 && map[posy+1][posx]==map[posy][posx] )
{
stepy--;
loopy--;
}
op_debug(DEBUG_MED,"loopx=%d\n",loopx);
op_debug(DEBUG_MED,"map[%d][%d]=%d\n",posy,posx,map[posy][posx]);
/* If there is distance at x direction,then move it.*/
if(loopx > 0)
{
k=(OP_INT8)loopx;
while(k>0)
/* If the pen is put to the blank,then move the picture if possible,otherwise,just move the cursor.*/
if(map[posy][posx]==FIRST_BLANK || map[posy][posx]==SECOND_BLANK)
{
op_debug(DEBUG_MED,"stepx=%d\n",stepx);
if(stepx>0)
{
if(JudgeNextPiece(RIGHT))
{
k = k-JudgeStep(RIGHT);
state = MOVEPIECE;
movePiece(RIGHT);
op_debug(DEBUG_MED,"curmap[%d][%d]=%d,nextmap[%d][%d]=%d,nextmap[%d][%d]=%d\n",
cursorY,cursorX,map[cursorY][cursorX],cursorY+1,cursorX,map[cursorY+1][cursorX],
cursorY+1,cursorX+1,map[cursorY+1][cursorX+1]);
op_debug(DEBUG_MED,"movePiece(RIGHT)k=%d\n",k);
}
else
{
hasMovedx = OP_FALSE;
op_debug(DEBUG_MED,"curmap[%d][%d]=%d,nextmap[%d][%d]=%d,nextmap[%d][%d]=%d\n",
cursorY,cursorX,map[cursorY][cursorX],cursorY+1,cursorX,map[cursorY+1][cursorX],
cursorY+1,cursorX+1,map[cursorY+1][cursorX+1]);
break;
}
}
else
{
if(JudgeNextPiece(LEFT))
{
k = k-JudgeStep(LEFT);
state = MOVEPIECE;
movePiece(LEFT);
op_debug(DEBUG_MED,"curmap[%d][%d]=%d,nextmap[%d][%d]=%d,nextmap[%d][%d]=%d\n",
cursorY,cursorX,map[cursorY][cursorX],cursorY+1,cursorX,map[cursorY+1][cursorX],
cursorY+1,cursorX+1,map[cursorY+1][cursorX+1]);
op_debug(DEBUG_MED,"movePiece(LEFT)k=%d\n",k);
}
else
{
hasMovedx = OP_FALSE;
op_debug(DEBUG_MED,"curmap[%d][%d]=%d,nextmap[%d][%d]=%d,nextmap[%d][%d]=%d\n",
cursorY,cursorX,map[cursorY][cursorX],cursorY+1,cursorX,map[cursorY+1][cursorX],
cursorY+1,cursorX+1,map[cursorY+1][cursorX+1]);
break;
}
}
}
else
{
break;
}
}
op_debug(DEBUG_MED,"loopy=%d\n",loopy);
if(loopy >0 )
{
k=(OP_INT8)loopy;
while(k>0)
/* If the pen is put to the blank,then move the picture if possible,otherwise,just move the cursor.*/
if(map[posy][posx]==FIRST_BLANK || map[posy][posx]==SECOND_BLANK)
{
op_debug(DEBUG_MED,"stepy=%d\n",stepy);
if(stepy>0)
{
if(JudgeNextPiece(DOWN))
{
k = k-JudgeStep(DOWN);
state = MOVEPIECE;
movePiece(DOWN);
op_debug(DEBUG_MED,"curmap[%d][%d]=%d,nextmap[%d][%d]=%d,nextmap[%d][%d]=%d\n",
cursorY,cursorX,map[cursorY][cursorX],cursorY+1,cursorX,map[cursorY+1][cursorX],
cursorY+1,cursorX+1,map[cursorY+1][cursorX+1]);
op_debug(DEBUG_MED,"movePiece(DOWN)k=%d\n",k);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -