From 316eb6538e2fc88efa93248deb761679071409f1 Mon Sep 17 00:00:00 2001 From: Antoine Cellerier Date: Sun, 26 Jun 2005 19:35:29 +0000 Subject: * fix some cursor bugs (patch 1222287) * added call to srand (patch 1223090) git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6876 a1c6a512-1295-4272-9138-f99709370657 --- apps/plugins/solitaire.c | 106 +++++++++++++++++++++++++++-------------------- 1 file changed, 60 insertions(+), 46 deletions(-) (limited to 'apps/plugins') diff --git a/apps/plugins/solitaire.c b/apps/plugins/solitaire.c index 066af9da73..1ef1cf5c90 100644 --- a/apps/plugins/solitaire.c +++ b/apps/plugins/solitaire.c @@ -7,7 +7,7 @@ * \/ \/ \/ \/ \/ * $Id$ * - * Copyright (C) 2004 dionoea (Antoine Cellerier) + * Copyright (C) 2004-2005 dionoea (Antoine Cellerier) * * All files in this archive are subject to the GNU General Public License. * See the file COPYING in the source tree root for full license agreement. @@ -328,10 +328,10 @@ typedef struct card { unsigned char next_random_card(card *deck){ unsigned char i,r; - + r = rb->rand()%(COLORS * CARDS_PER_COLOR)+1; i = 0; - + while(r>0){ i = (i + 1)%(COLORS * CARDS_PER_COLOR); if(!deck[i].used) r--; @@ -352,7 +352,7 @@ int solitaire_help(void){ int lastbutton = BUTTON_NONE; while(1){ - + rb->lcd_clear_display(); #if CONFIG_KEYPAD == RECORDER_PAD @@ -382,7 +382,7 @@ int solitaire_help(void){ #endif rb->lcd_update(); - + button = rb->button_get(true); switch(button){ case SOL_UP: @@ -459,7 +459,7 @@ int solitaire_help(void){ case SOL_QUIT: return HELP_QUIT; - + default: if(rb->default_event_handler(button) == SYS_USB_CONNECTED) return HELP_USB; @@ -488,7 +488,7 @@ int solitaire_help(void){ /* text displayed changes depending on the 'when' parameter */ int solitaire_menu(unsigned char when) { - static char menu[2][MENU_LENGTH][13] = + static char menu[2][MENU_LENGTH][13] = { { "Start Game", "", "Help", @@ -498,7 +498,7 @@ int solitaire_menu(unsigned char when) "Help", "Quit"} }; - + int i; int cursor=0; int button; @@ -506,16 +506,16 @@ int solitaire_menu(unsigned char when) rb->lcd_getstringsize("A", NULL, &fh); fh++; - + if(when!=MENU_BEFOREGAME && when!=MENU_DURINGGAME) when = MENU_DURINGGAME; - + while(1){ - + rb->lcd_clear_display(); rb->lcd_putsxy(20, 1, "Solitaire"); - + for(i = 0; ilcd_putsxy(1, 17+fh*i, menu[when][i]); if(cursor == i) { @@ -556,7 +556,7 @@ int solitaire_menu(unsigned char when) break; } break; - + case SOL_MENU_INFO: #if defined(SOL_MENU_INFO2) && defined(SOL_MENU_INFO3) case SOL_MENU_INFO2: @@ -612,7 +612,7 @@ void solitaire_init(void){ deck[i*CARDS_PER_COLOR+j].next = NOT_A_CARD; } } - + /* deal the cards ... */ /* ... in the columns */ for(i=0; iget_time()); + rb->srand( ( ( ( time.tm_year + 365 * time.tm_yday ) * 24 + + time.tm_hour ) * 60 + time.tm_min ) * 60 + time.tm_sec ); + + switch(solitaire_menu(MENU_BEFOREGAME)) { case MENU_QUIT: return SOLITAIRE_QUIT; @@ -847,14 +853,14 @@ int solitaire(void){ } solitaire_init(); - + while(true){ - + rb->lcd_clear_display(); /* get the biggest column length so that display can be "optimized" */ biggest_col_length = 0; - + for(i=0;ibiggest_col_length) biggest_col_length = j; } - + /* check if there are cards remaining in the game. */ /* if there aren't any, that means you won :) */ if(biggest_col_length == 0 && rem == NOT_A_CARD){ rb->splash(HZ*2, true, "You Won :)"); return SOLITAIRE_WIN; } - + /* draw the columns */ for(i=0;ilcd_fillrect(LCD_WIDTH - CARD_WIDTH+1, LCD_HEIGHT-CARD_HEIGHT,CARD_WIDTH-1, CARD_HEIGHT-1); rb->lcd_set_drawmode(DRMODE_SOLID); } - + rb->lcd_update(); - + /* what to do when a key is pressed ... */ button = rb->button_get(true); switch(button){ - + /* move cursor to the last card of the previous column */ /* or to the previous color stack */ /* or to the remains stack */ @@ -1004,7 +1010,7 @@ int solitaire(void){ } cur_card = find_last_card(cur_col); break; - + /* move cursor to the last card of the next column */ /* or to the next color stack */ /* or to the remains stack */ @@ -1026,7 +1032,7 @@ int solitaire(void){ } cur_card = find_last_card(cur_col); break; - + /* move cursor to card that's bellow */ case SOL_DOWN: #ifdef SOL_DOWN_PRE @@ -1053,7 +1059,7 @@ int solitaire(void){ } } break; - + /* move cursor to card that's above */ case SOL_UP: #ifdef SOL_UP_PRE @@ -1117,7 +1123,7 @@ int solitaire(void){ } } break; - + /* If the card on the top of the remains can be put where */ /* the cursor is, go ahead */ case SOL_REM2CUR: @@ -1153,6 +1159,7 @@ int solitaire(void){ break; } if(rem != NOT_A_CARD) { + int cur_rem_old = cur_rem; /* draw new cards form the remains of the deck */ if(cur_rem == NOT_A_CARD){ cur_rem = rem; @@ -1169,15 +1176,19 @@ int solitaire(void){ if(i == CARDS_PER_DRAW){ cur_rem = NOT_A_CARD; } + /* if cursor was on remains' stack when new cards were + * drawn, put cursor on top of remains' stack */ + if(cur_col == REM_COL && cur_card == cur_rem_old) + cur_card = cur_rem; } break; - + /* Show the menu */ case SOL_QUIT: switch(solitaire_menu(MENU_DURINGGAME)){ case MENU_QUIT: return SOLITAIRE_QUIT; - + case MENU_USB: return SOLITAIRE_USB; @@ -1190,7 +1201,7 @@ int solitaire(void){ return SOLITAIRE_USB; break; } - + if(button != BUTTON_NONE) lastbutton = button; @@ -1198,6 +1209,9 @@ int solitaire(void){ c = find_card_col(cur_card); if(c != NOT_A_COL && c != cur_col) cur_card = find_last_card(cur_col); + + if(cur_card == NOT_A_CARD && find_last_card(cur_col) != NOT_A_CARD) + cur_card = find_last_card(cur_col); } } @@ -1210,10 +1224,10 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) (void)parameter; rb = api; /* end of plugin init */ - + /* Welcome to Solitaire ! */ rb->splash(HZ*2, true, "Welcome to Solitaire !"); - + /* play the game :) */ /* Keep playing if a game was won (that means display the menu after */ /* winning instead of quiting) */ -- cgit v1.2.3