1
0
Fork 0
forked from len0rd/rockbox

clix: fix bug that game isn't over when no move is possible.

clean up a bit.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21774 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Teruaki Kawashima 2009-07-11 14:06:00 +00:00
parent 75fa699814
commit ad825d66c7

View file

@ -209,14 +209,14 @@ struct highscore highest[NUM_SCORES];
struct clix_game_state_t { struct clix_game_state_t {
unsigned char level; /* current level */ int level; /* current level */
char x,y; /* current positions of the cursor */ int score; /* current game score */
int x,y; /* current positions of the cursor */
int board[BOARD_WIDTH * BOARD_HEIGHT]; /* play board*/ int board[BOARD_WIDTH * BOARD_HEIGHT]; /* play board*/
/* state of selected fields,maybe we can store this in the play board too */ /* state of selected fields,maybe we can store this in the play board too */
bool board_selected[ BOARD_WIDTH * BOARD_HEIGHT]; bool board_selected[ BOARD_WIDTH * BOARD_HEIGHT];
char selected_count; int selected_count;
unsigned short score; /* current game score */ int status;
char status;
bool blink; /* true if selected CELLS are currently white */ bool blink; /* true if selected CELLS are currently white */
}; };
@ -292,7 +292,7 @@ static void clix_show_highscores(int position)
rb->lcd_setfont(FONT_SYSFIXED); rb->lcd_setfont(FONT_SYSFIXED);
} }
/* recursiv function to check if a neighbour cell is of the same color /* recursive function to check if a neighbour cell is of the same color
if so call the function with the neighbours position if so call the function with the neighbours position
*/ */
static void clix_set_selected(struct clix_game_state_t* state, static void clix_set_selected(struct clix_game_state_t* state,
@ -463,7 +463,7 @@ static void clix_draw(struct clix_game_state_t* state)
static void clix_move_cursor(struct clix_game_state_t* state, const bool left) static void clix_move_cursor(struct clix_game_state_t* state, const bool left)
{ {
signed char x, y; int x, y;
x = state->x; x = state->x;
do do
@ -522,14 +522,18 @@ static int clix_clear_selected(struct clix_game_state_t* state)
} }
} }
/* count score */
state->score += state->selected_count * state->level;
state->selected_count = 0;
/* let blocks falling down */ /* let blocks falling down */
for( i = BOARD_WIDTH - 1; i >= 0; --i) for( i = BOARD_WIDTH - 1; i >= 0; --i)
{ {
for( j = BOARD_HEIGHT - 1; j >= 0; --j) for( j = BOARD_HEIGHT - 1; j >= 0; --j)
{ {
y = j; y = j;
while( state->board[ XYPOS( i, y + 1)] == CC_BLACK && while( (y + 1) < BOARD_HEIGHT &&
y < BOARD_HEIGHT state->board[ XYPOS( i, y + 1)] == CC_BLACK
) )
y++; y++;
@ -540,32 +544,26 @@ static int clix_clear_selected(struct clix_game_state_t* state)
} }
} }
/* count score */ /* move columns to left side */
state->score += state->selected_count * state->level; for( i = 0; i < BOARD_WIDTH; ++i)
/* check every column (from right to left) if its empty,
if so copy the contents from the right side */
for( i = BOARD_WIDTH - 1; i >= 0; --i)
{ {
if (state->board[ XYPOS( i, BOARD_HEIGHT - 1)] == CC_BLACK) { x = i;
if( (i + 1) < BOARD_WIDTH && while( (x - 1) >= 0 &&
state->board[ XYPOS( i + 1, BOARD_HEIGHT - 1)] != CC_BLACK) state->board[ XYPOS( x - 1, BOARD_HEIGHT - 1)] == CC_BLACK
{ )
for( x = (i + 1); x < BOARD_WIDTH; ++x) x--;
if (x != i)
{ {
for( j = 0; j < BOARD_HEIGHT; ++j) for( j = 0; j < BOARD_HEIGHT; ++j)
{ {
state->board[ XYPOS( x - 1, j)] = state->board[ XYPOS( x, j)] = state->board[ XYPOS( i, j)];
state->board[ XYPOS( x, j)]; state->board[ XYPOS( i, j)] = CC_BLACK;
}
}
}
state->board[ XYPOS( x, j)] = CC_BLACK; if(state->board[ XYPOS( 0, BOARD_HEIGHT - 1)] != CC_BLACK)
}
}
}
}
else
state->status = CLIX_CONTINUE; state->status = CLIX_CONTINUE;
}
if (state->status != CLIX_CLEARED) { if (state->status != CLIX_CLEARED) {
/* check if a move is still possible, otherwise the game is over. /* check if a move is still possible, otherwise the game is over.
@ -576,18 +574,15 @@ static int clix_clear_selected(struct clix_game_state_t* state)
{ {
for( j = BOARD_HEIGHT - 1; j >= 0; --j) for( j = BOARD_HEIGHT - 1; j >= 0; --j)
{ {
if (state->board[ XYPOS( i, j)] != CC_BLACK) { int color = state->board[ XYPOS( i, j)];
if ( state->board[ XYPOS( i, j)] == if (color != CC_BLACK) {
clix_get_color( state, i - 1, j) || if (color == clix_get_color( state, i - 1, j) ||
state->board[ XYPOS( i, j)] == color == clix_get_color( state, i + 1, j) ||
clix_get_color( state, i + 1, j) || color == clix_get_color( state, i, j - 1) ||
state->board[ XYPOS( i, j)] == color == clix_get_color( state, i, j + 1)
clix_get_color( state, i, j - 1) ||
state->board[ XYPOS( i, j)] ==
clix_get_color( state, i, j + 1)
) )
{ {
/* and the loop, but in a diffrent way than usually*/ /* end the loop, but in a diffrent way than usually*/
i = BOARD_WIDTH + 1; i = BOARD_WIDTH + 1;
j = -2; j = -2;
} }
@ -613,7 +608,7 @@ static int clix_help(void)
rb->lcd_setfont(FONT_UI); rb->lcd_setfont(FONT_UI);
rb->lcd_set_foreground(LCD_WHITE); rb->lcd_set_foreground(LCD_WHITE);
#define WORDS (sizeof help_text / sizeof (char*)) #define WORDS (sizeof help_text / sizeof (char*))
char *help_text[] = { static char *help_text[] = {
"Clix", "", "Aim", "", "Remove", "all", "blocks", "from", "the", "Clix", "", "Aim", "", "Remove", "all", "blocks", "from", "the",
"board", "to", "achieve", "the", "next", "level.", "You", "can", "board", "to", "achieve", "the", "next", "level.", "You", "can",
"only", "remove", "blocks,", "if", "at", "least", "two", "blocks", "only", "remove", "blocks,", "if", "at", "least", "two", "blocks",
@ -665,8 +660,7 @@ static int clix_menu(struct clix_game_state_t* state, bool ingame)
"Quit"); "Quit");
while (true) { while (true) {
choice = rb->do_menu(&main_menu, &choice, NULL, false); switch (rb->do_menu(&main_menu, &choice, NULL, false)) {
switch (choice) {
case 0: case 0:
return 0; return 0;
case 1: case 1:
@ -773,10 +767,10 @@ static int clix_handle_game(struct clix_game_state_t* state)
switch( clix_clear_selected( state)) switch( clix_clear_selected( state))
{ {
case CLIX_CLEARED: case CLIX_CLEARED:
state->score += state->level * 100;
clix_draw( state); clix_draw( state);
if (state->level < NUM_LEVELS) { if (state->level < NUM_LEVELS) {
rb->splash(HZ*2, "Great! Next Level!"); rb->splash(HZ*2, "Great! Next Level!");
state->score += state->level * 100;
state->level++; state->level++;
clix_init_new_level( state); clix_init_new_level( state);
clix_update_selected( state); clix_update_selected( state);
@ -842,7 +836,6 @@ enum plugin_status plugin_start(const void* parameter)
{ {
(void)parameter; (void)parameter;
#ifdef HAVE_LCD_COLOR
rb->lcd_set_backdrop(NULL); rb->lcd_set_backdrop(NULL);
rb->lcd_set_foreground(LCD_WHITE); rb->lcd_set_foreground(LCD_WHITE);
rb->lcd_set_background(LCD_BLACK); rb->lcd_set_background(LCD_BLACK);
@ -855,9 +848,5 @@ enum plugin_status plugin_start(const void* parameter)
highscore_save(HIGHSCORE_FILE, highest, NUM_SCORES); highscore_save(HIGHSCORE_FILE, highest, NUM_SCORES);
rb->lcd_set_foreground(LCD_WHITE);
rb->lcd_setfont(FONT_UI);
#endif
return PLUGIN_OK; return PLUGIN_OK;
} }