📄 games_fallball.c
字号:
{
op_debug(DEBUG_MED,"RouteMove():return,not entered.\n");
return;
}
op_debug(DEBUG_MED,"RouteMove():\n");
pathstep ++;
if(pathstep+2 <= FallballCurPath)
{
next_x = FallballPath[pathstep].seat.x;
next_y = FallballPath[pathstep].seat.y;
MoveOneStep(next_x,next_y);
OPUS_Start_Timer(OPUS_TIMER_GAME_PEN,30,0,ONE_SHOT);
}
else
{
OPUS_Stop_Timer(OPUS_TIMER_GAME_PEN);
FallballCurPath = (OP_INT8)(MAX_LINE*MAX_COLUMN);
if(DeleteBall(cur_x,cur_y) == OP_FAIL)
{
FallNewBall();
}
ShowScore();
ds_refresh();
}
}
/*==================================================================================================
FUNCTION: JudgeOneLineNumber
DESCRIPTION:
If one line can be deleted ,delete it ,else ,just keep it.
judge how many balls which is the same with current ball at one line.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
OP_INT16 JudgeOneLineNumber(OP_INT16 x,OP_INT16 y,OP_INT16 *line_type)
{
OP_INT16 ball_type,line_number = 1;
OP_INT16 i,j;
ball_type = cur_box[y][x];
op_debug(DEBUG_MED,"JudgeOneLineNumber():\n");
for(i=x+1;i<MAX_COLUMN;i++)
{
if(cur_box[y][i] == ball_type)
{
line_number ++;
}
else
{
break;
}
}
for(i=x-1;i>=0;i--)
{
if(cur_box[y][i] == ball_type)
{
line_number ++;
}
else
{
break;
}
}
if(line_number >= 5)
{
*line_type = 1;
return line_number;
}
line_number = 1;
for(i=y+1;i<MAX_LINE;i++)
{
if(cur_box[i][x] == ball_type)
{
line_number ++;
}
else
{
break;
}
}
for(i=y-1;i>=0;i--)
{
if(cur_box[i][x] == ball_type)
{
line_number ++;
}
else
{
break;
}
}
if(line_number >= 5)
{
*line_type = 2;
return line_number;
}
line_number = 1;
for(i=x+1,j=y+1;i<MAX_COLUMN && y<MAX_LINE;i++,j++)
{
if(cur_box[j][i] == ball_type)
{
line_number ++;
}
else
{
break;
}
}
for(i=x-1,j=y-1;i>=0 && y>=0;i--,j--)
{
if(cur_box[j][i] == ball_type)
{
line_number ++;
}
else
{
break;
}
}
if(line_number >= 5)
{
*line_type = 3;
return line_number;
}
line_number = 1;
for(i=x+1,j=y-1;i<MAX_COLUMN && j>=0;i++,j--)
{
if(cur_box[j][i] == ball_type)
{
line_number ++;
}
else
{
break;
}
}
for(i=x-1,j=y+1;i>=0 && j<MAX_LINE;i--,j++)
{
if(cur_box[j][i] == ball_type)
{
line_number ++;
}
else
{
break;
}
}
*line_type = 4;
return line_number;
}
/*==================================================================================================
FUNCTION: DeleteBall
DESCRIPTION:
If one line is with more than 4 balls,delete it.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
static OP_BOOLEAN DeleteBall(OP_INT16 x,OP_INT16 y)
{
OP_INT16 i,j,LineSameBall;
OP_INT16 line_type;
OP_INT16 ball_type = cur_box[y][x];
if(ball_type == FLOOR)
{
return OP_FAIL;
}
op_debug(DEBUG_MED,"DeleteBall():\n");
LineSameBall = JudgeOneLineNumber(x,y,&line_type);
if(LineSameBall >= 5)
{
switch(line_type)
{
case 1:
for(i=x;i<MAX_COLUMN;i++)
{
if(cur_box[y][i] == ball_type)
{
DeleteOneBall(i,y);
}
else
{
break;
}
}
for(i=x-1;i>=0;i--)
{
if(cur_box[y][i] == ball_type)
{
DeleteOneBall(i,y);
}
else
{
break;
}
}
break;
case 2:
for(i=y;i<MAX_LINE;i++)
{
if(cur_box[i][x] == ball_type)
{
DeleteOneBall(x,i);
}
else
{
break;
}
}
for(i=y-1;i>=0;i--)
{
if(cur_box[i][x] == ball_type)
{
DeleteOneBall(x,i);
}
else
{
break;
}
}
break;
case 3:
for(i=x,j=y;i<MAX_COLUMN && j<MAX_LINE;i++,j++)
{
if(cur_box[j][i] == ball_type)
{
DeleteOneBall(i,j);
}
else
{
break;
}
}
for(i=x-1,j=y-1;i>=0 && j>=0;i--,j--)
{
if(cur_box[j][i] == ball_type)
{
DeleteOneBall(i,j);
}
else
{
break;
}
}
break;
case 4:
for(i=x,j=y;i<MAX_COLUMN && j>=0;i++,j--)
{
if(cur_box[j][i] == ball_type)
{
DeleteOneBall(i,j);
}
else
{
break;
}
}
for(i=x-1,j=y+1;i>=0 && j<MAX_LINE;i--,j++)
{
if(cur_box[j][i] == ball_type)
{
DeleteOneBall(i,j);
}
else
{
break;
}
}
break;
default:
break;
}
if (gamesApp_data.audio_on == OP_TRUE)
{
SP_Audio_play_request(sound_list[1], gamesApp_data.volume, OP_FALSE);
}
CountScore(&score,LineSameBall);
op_debug(DEBUG_MED,"DeleteBall():LineSameBall to be deleted is %d\n",LineSameBall);
return OP_SUCCESS;
}
else
{
return OP_FAIL;
}
}
/*==================================================================================================
FUNCTION: MoveOneStep
DESCRIPTION:
Move the ball just for one step.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
static void MoveOneStep(OP_INT16 x,OP_INT16 y)
{
if( (x == cur_x && abs(y - cur_y) == 1)
|| (y == cur_y && abs(x - cur_x) == 1) )
{
if(cur_box[cur_y][cur_x] == FLOOR)
{
return;
}
op_debug(DEBUG_MED,"MoveOneStep():\n");
cur_box[y][x] = cur_box[cur_y][cur_x];
cur_box[cur_y][cur_x] = FLOOR;
DrawSquare(cur_x,cur_y,FLOOR);
cur_x = x;
cur_y = y;
DrawSquare(cur_x,cur_y,cur_box[cur_y][cur_x]*2);
}
ds_refresh();
}
/*==================================================================================================
FUNCTION: DeleteOneBall
DESCRIPTION:
Delete just one ball.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
static void DeleteOneBall(OP_INT16 x,OP_INT16 y)
{
op_debug(DEBUG_MED,"DeleteOneBall():reserved_position=%d\n",reserved_position);
reserved_position ++;
cur_box[y][x] = FLOOR;
DrawSquare(x,y,cur_box[y][x]*2);
ds_refresh();
}
/*==================================================================================================
FUNCTION: FallNewBall
DESCRIPTION:
Fall three new balls, if the screen is full of balls ,then game over.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
static void FallNewBall()
{
OP_INT16 i;
OP_INT16 game_over;
OP_INT16 pos[3];
OP_INT16 line,column;
OP_INT16 ball_type;
op_debug(DEBUG_MED,"FallNewBall:entrance!\n");
GetRandomNumber(&pos[0],&pos[1],&pos[2]);
for(i=0;i<3;i++)
{
if(pos[i] == -1)
{
break;
}
ball_type = rand()%BALL_NUM;
line = (pos[i])/MAX_COLUMN;
column = (pos[i])%MAX_COLUMN;
cur_box[line][column] = ball_type+1;
DrawSquare(column,line,cur_box[line][column]*2);
//DeleteBall(cur_x,cur_y);
}
ShowScore();
ds_refresh();
for(i=0;i<3;i++)
{
cur_x = (pos[i])%MAX_COLUMN;
cur_y = (pos[i])/MAX_COLUMN;
DeleteBall(cur_x,cur_y);
}
/* Judge if the window is full of balls.*/
op_debug(DEBUG_MED,"reserved_position=%d\n",reserved_position);
game_over = JudgeGameOver(reserved_position);
if(game_over == 1)
{
OP_UINT8 ustr[MAX_STRING_LENGTH]={0};
OP_UINT8 tmpstr[MAX_STRING_LENGTH]={0};
char strscore[5]={0};
if (gamesApp_data.audio_on == OP_TRUE)
{
SP_Audio_play_request(sound_list[3], gamesApp_data.volume, OP_FALSE);
}
if (score > 0 && is_new_highscore(APP_GAMES_FALLBALL, score))
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -