summaryrefslogtreecommitdiff
path: root/apps/plugins/clix.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/clix.c')
-rw-r--r--apps/plugins/clix.c95
1 files changed, 42 insertions, 53 deletions
diff --git a/apps/plugins/clix.c b/apps/plugins/clix.c
index 24b1e8e00b..e04de3ca72 100644
--- a/apps/plugins/clix.c
+++ b/apps/plugins/clix.c
@@ -155,7 +155,7 @@ PLUGIN_HEADER
155#define CLIX_BUTTON_RIGHT BUTTON_MIDRIGHT 155#define CLIX_BUTTON_RIGHT BUTTON_MIDRIGHT
156#endif 156#endif
157#ifndef CLIX_BUTTON_CLICK 157#ifndef CLIX_BUTTON_CLICK
158#define CLIX_BUTTON_CLICK BUTTON_CENTER 158#define CLIX_BUTTON_CLICK BUTTON_CENTER
159#endif 159#endif
160#ifndef CLIX_BUTTON_UP 160#ifndef CLIX_BUTTON_UP
161#define CLIX_BUTTON_UP BUTTON_TOPMIDDLE 161#define CLIX_BUTTON_UP BUTTON_TOPMIDDLE
@@ -209,14 +209,14 @@ struct highscore highest[NUM_SCORES];
209 209
210 210
211struct clix_game_state_t { 211struct clix_game_state_t {
212 unsigned char level; /* current level */ 212 int level; /* current level */
213 char x,y; /* current positions of the cursor */ 213 int score; /* current game score */
214 int x,y; /* current positions of the cursor */
214 int board[BOARD_WIDTH * BOARD_HEIGHT]; /* play board*/ 215 int board[BOARD_WIDTH * BOARD_HEIGHT]; /* play board*/
215 /* state of selected fields,maybe we can store this in the play board too */ 216 /* state of selected fields,maybe we can store this in the play board too */
216 bool board_selected[ BOARD_WIDTH * BOARD_HEIGHT]; 217 bool board_selected[ BOARD_WIDTH * BOARD_HEIGHT];
217 char selected_count; 218 int selected_count;
218 unsigned short score; /* current game score */ 219 int status;
219 char status;
220 bool blink; /* true if selected CELLS are currently white */ 220 bool blink; /* true if selected CELLS are currently white */
221}; 221};
222 222
@@ -292,7 +292,7 @@ static void clix_show_highscores(int position)
292 rb->lcd_setfont(FONT_SYSFIXED); 292 rb->lcd_setfont(FONT_SYSFIXED);
293} 293}
294 294
295/* recursiv function to check if a neighbour cell is of the same color 295/* recursive function to check if a neighbour cell is of the same color
296 if so call the function with the neighbours position 296 if so call the function with the neighbours position
297*/ 297*/
298static void clix_set_selected(struct clix_game_state_t* state, 298static void clix_set_selected(struct clix_game_state_t* state,
@@ -463,7 +463,7 @@ static void clix_draw(struct clix_game_state_t* state)
463 463
464static void clix_move_cursor(struct clix_game_state_t* state, const bool left) 464static void clix_move_cursor(struct clix_game_state_t* state, const bool left)
465{ 465{
466 signed char x, y; 466 int x, y;
467 467
468 x = state->x; 468 x = state->x;
469 do 469 do
@@ -522,51 +522,49 @@ static int clix_clear_selected(struct clix_game_state_t* state)
522 } 522 }
523 } 523 }
524 524
525 /* count score */
526 state->score += state->selected_count * state->level;
527 state->selected_count = 0;
528
525 /* let blocks falling down */ 529 /* let blocks falling down */
526 for( i = BOARD_WIDTH - 1; i >= 0; --i) 530 for( i = BOARD_WIDTH - 1; i >= 0; --i)
527 { 531 {
528 for( j = BOARD_HEIGHT - 1; j >= 0; --j) 532 for( j = BOARD_HEIGHT - 1; j >= 0; --j)
529 { 533 {
530 y = j; 534 y = j;
531 while( state->board[ XYPOS( i, y + 1)] == CC_BLACK && 535 while( (y + 1) < BOARD_HEIGHT &&
532 y < BOARD_HEIGHT 536 state->board[ XYPOS( i, y + 1)] == CC_BLACK
533 ) 537 )
534 y++; 538 y++;
535 539
536 if (y != j) { 540 if (y != j) {
537 state->board[ XYPOS(i, y)] = state->board[ XYPOS( i, j)]; 541 state->board[ XYPOS( i, y)] = state->board[ XYPOS( i, j)];
538 state->board[ XYPOS( i, j)] = CC_BLACK; 542 state->board[ XYPOS( i, j)] = CC_BLACK;
539 } 543 }
540 } 544 }
541 } 545 }
542 546
543 /* count score */ 547 /* move columns to left side */
544 state->score += state->selected_count * state->level; 548 for( i = 0; i < BOARD_WIDTH; ++i)
545
546 /* check every column (from right to left) if its empty,
547 if so copy the contents from the right side */
548 for( i = BOARD_WIDTH - 1; i >= 0; --i)
549 { 549 {
550 if (state->board[ XYPOS( i, BOARD_HEIGHT - 1)] == CC_BLACK) { 550 x = i;
551 if( (i + 1) < BOARD_WIDTH && 551 while( (x - 1) >= 0 &&
552 state->board[ XYPOS( i + 1, BOARD_HEIGHT - 1)] != CC_BLACK) 552 state->board[ XYPOS( x - 1, BOARD_HEIGHT - 1)] == CC_BLACK
553 )
554 x--;
555 if (x != i)
556 {
557 for( j = 0; j < BOARD_HEIGHT; ++j)
553 { 558 {
554 for( x = (i + 1); x < BOARD_WIDTH; ++x) 559 state->board[ XYPOS( x, j)] = state->board[ XYPOS( i, j)];
555 { 560 state->board[ XYPOS( i, j)] = CC_BLACK;
556 for( j = 0; j < BOARD_HEIGHT; ++j)
557 {
558 state->board[ XYPOS( x - 1, j)] =
559 state->board[ XYPOS( x, j)];
560
561 state->board[ XYPOS( x, j)] = CC_BLACK;
562 }
563 }
564 } 561 }
565 } 562 }
566 else
567 state->status = CLIX_CONTINUE;
568 } 563 }
569 564
565 if(state->board[ XYPOS( 0, BOARD_HEIGHT - 1)] != CC_BLACK)
566 state->status = CLIX_CONTINUE;
567
570 if (state->status != CLIX_CLEARED) { 568 if (state->status != CLIX_CLEARED) {
571 /* check if a move is still possible, otherwise the game is over. 569 /* check if a move is still possible, otherwise the game is over.
572 tart from the left bottom, because there are the last fields 570 tart from the left bottom, because there are the last fields
@@ -576,18 +574,15 @@ static int clix_clear_selected(struct clix_game_state_t* state)
576 { 574 {
577 for( j = BOARD_HEIGHT - 1; j >= 0; --j) 575 for( j = BOARD_HEIGHT - 1; j >= 0; --j)
578 { 576 {
579 if (state->board[ XYPOS( i, j)] != CC_BLACK) { 577 int color = state->board[ XYPOS( i, j)];
580 if ( state->board[ XYPOS( i, j)] == 578 if (color != CC_BLACK) {
581 clix_get_color( state, i - 1, j) || 579 if (color == clix_get_color( state, i - 1, j) ||
582 state->board[ XYPOS( i, j)] == 580 color == clix_get_color( state, i + 1, j) ||
583 clix_get_color( state, i + 1, j) || 581 color == clix_get_color( state, i, j - 1) ||
584 state->board[ XYPOS( i, j)] == 582 color == clix_get_color( state, i, j + 1)
585 clix_get_color( state, i, j - 1) ||
586 state->board[ XYPOS( i, j)] ==
587 clix_get_color( state, i, j + 1)
588 ) 583 )
589 { 584 {
590 /* and the loop, but in a diffrent way than usually*/ 585 /* end the loop, but in a diffrent way than usually*/
591 i = BOARD_WIDTH + 1; 586 i = BOARD_WIDTH + 1;
592 j = -2; 587 j = -2;
593 } 588 }
@@ -613,8 +608,8 @@ static int clix_help(void)
613 rb->lcd_setfont(FONT_UI); 608 rb->lcd_setfont(FONT_UI);
614 rb->lcd_set_foreground(LCD_WHITE); 609 rb->lcd_set_foreground(LCD_WHITE);
615#define WORDS (sizeof help_text / sizeof (char*)) 610#define WORDS (sizeof help_text / sizeof (char*))
616 char *help_text[] = { 611 static char *help_text[] = {
617 "Clix", "", "Aim", "", "Remove", "all", "blocks", "from", "the", 612 "Clix", "", "Aim", "", "Remove", "all", "blocks", "from", "the",
618 "board", "to", "achieve", "the", "next", "level.", "You", "can", 613 "board", "to", "achieve", "the", "next", "level.", "You", "can",
619 "only", "remove", "blocks,", "if", "at", "least", "two", "blocks", 614 "only", "remove", "blocks,", "if", "at", "least", "two", "blocks",
620 "with", "the", "same", "color", "have", "a", "direct", "connection.", 615 "with", "the", "same", "color", "have", "a", "direct", "connection.",
@@ -665,8 +660,7 @@ static int clix_menu(struct clix_game_state_t* state, bool ingame)
665 "Quit"); 660 "Quit");
666 661
667 while (true) { 662 while (true) {
668 choice = rb->do_menu(&main_menu, &choice, NULL, false); 663 switch (rb->do_menu(&main_menu, &choice, NULL, false)) {
669 switch (choice) {
670 case 0: 664 case 0:
671 return 0; 665 return 0;
672 case 1: 666 case 1:
@@ -773,10 +767,10 @@ static int clix_handle_game(struct clix_game_state_t* state)
773 switch( clix_clear_selected( state)) 767 switch( clix_clear_selected( state))
774 { 768 {
775 case CLIX_CLEARED: 769 case CLIX_CLEARED:
770 state->score += state->level * 100;
776 clix_draw( state); 771 clix_draw( state);
777 if (state->level < NUM_LEVELS) { 772 if (state->level < NUM_LEVELS) {
778 rb->splash(HZ*2, "Great! Next Level!"); 773 rb->splash(HZ*2, "Great! Next Level!");
779 state->score += state->level * 100;
780 state->level++; 774 state->level++;
781 clix_init_new_level( state); 775 clix_init_new_level( state);
782 clix_update_selected( state); 776 clix_update_selected( state);
@@ -797,7 +791,7 @@ static int clix_handle_game(struct clix_game_state_t* state)
797 highest, NUM_SCORES)) { 791 highest, NUM_SCORES)) {
798 position=highscore_update(state->score, 792 position=highscore_update(state->score,
799 state->level, "", 793 state->level, "",
800 highest,NUM_SCORES); 794 highest,NUM_SCORES);
801 if (position == 0) { 795 if (position == 0) {
802 rb->splash(HZ*2, "New High Score"); 796 rb->splash(HZ*2, "New High Score");
803 } 797 }
@@ -842,7 +836,6 @@ enum plugin_status plugin_start(const void* parameter)
842{ 836{
843 (void)parameter; 837 (void)parameter;
844 838
845#ifdef HAVE_LCD_COLOR
846 rb->lcd_set_backdrop(NULL); 839 rb->lcd_set_backdrop(NULL);
847 rb->lcd_set_foreground(LCD_WHITE); 840 rb->lcd_set_foreground(LCD_WHITE);
848 rb->lcd_set_background(LCD_BLACK); 841 rb->lcd_set_background(LCD_BLACK);
@@ -854,10 +847,6 @@ enum plugin_status plugin_start(const void* parameter)
854 clix_handle_game( &state); 847 clix_handle_game( &state);
855 848
856 highscore_save(HIGHSCORE_FILE, highest, NUM_SCORES); 849 highscore_save(HIGHSCORE_FILE, highest, NUM_SCORES);
857
858 rb->lcd_set_foreground(LCD_WHITE);
859 rb->lcd_setfont(FONT_UI);
860#endif
861 850
862 return PLUGIN_OK; 851 return PLUGIN_OK;
863} 852}