diff options
Diffstat (limited to 'apps/plugins/sudoku/sudoku.c')
-rw-r--r-- | apps/plugins/sudoku/sudoku.c | 67 |
1 files changed, 62 insertions, 5 deletions
diff --git a/apps/plugins/sudoku/sudoku.c b/apps/plugins/sudoku/sudoku.c index 9ca5376a58..bd171f1192 100644 --- a/apps/plugins/sudoku/sudoku.c +++ b/apps/plugins/sudoku/sudoku.c | |||
@@ -66,6 +66,10 @@ Example ".ss" file, and one with a saved state: | |||
66 | 66 | ||
67 | PLUGIN_HEADER | 67 | PLUGIN_HEADER |
68 | 68 | ||
69 | /* here is a global api struct pointer. while not strictly necessary, | ||
70 | it's nice not to have to pass the api pointer in all function calls | ||
71 | in the plugin */ | ||
72 | |||
69 | struct plugin_api* rb; | 73 | struct plugin_api* rb; |
70 | 74 | ||
71 | /* The bitmaps */ | 75 | /* The bitmaps */ |
@@ -887,7 +891,7 @@ bool sudoku_menu(struct sudoku_state_t* state) | |||
887 | result=rb->menu_show(m); | 891 | result=rb->menu_show(m); |
888 | 892 | ||
889 | switch (result) { | 893 | switch (result) { |
890 | case 0: /* Save state */ | 894 | case 0: /* Audio playback */ |
891 | playback_control(rb); | 895 | playback_control(rb); |
892 | break; | 896 | break; |
893 | 897 | ||
@@ -991,10 +995,12 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
991 | button = rb->button_get(true); | 995 | button = rb->button_get(true); |
992 | 996 | ||
993 | switch(button){ | 997 | switch(button){ |
998 | #ifdef SUDOKU_BUTTON_QUIT | ||
994 | /* Exit game */ | 999 | /* Exit game */ |
995 | case SUDOKU_BUTTON_QUIT: | 1000 | case SUDOKU_BUTTON_QUIT: |
996 | exit=1; | 1001 | exit=1; |
997 | break; | 1002 | break; |
1003 | #endif | ||
998 | 1004 | ||
999 | /* Increment digit */ | 1005 | /* Increment digit */ |
1000 | #ifdef SUDOKU_BUTTON_ALTTOGGLE | 1006 | #ifdef SUDOKU_BUTTON_ALTTOGGLE |
@@ -1037,26 +1043,74 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
1037 | update_cell(&state,state.y,state.x); | 1043 | update_cell(&state,state.y,state.x); |
1038 | break; | 1044 | break; |
1039 | 1045 | ||
1046 | #ifdef SUDOKU_BUTTON_TOGGLEBACK | ||
1047 | case SUDOKU_BUTTON_TOGGLEBACK | BUTTON_REPEAT: | ||
1048 | /* Slow down the repeat speed to 1/3 second */ | ||
1049 | if ((*rb->current_tick-ticks) < (HZ/3)) { | ||
1050 | break; | ||
1051 | } | ||
1052 | |||
1053 | case SUDOKU_BUTTON_TOGGLEBACK: | ||
1054 | /* Decrement digit */ | ||
1055 | ticks=*rb->current_tick; | ||
1056 | if (state.editmode) { | ||
1057 | if (state.startboard[state.y][state.x]=='0') { | ||
1058 | state.startboard[state.y][state.x]='9'; | ||
1059 | state.currentboard[state.y][state.x]='9'; | ||
1060 | } else { | ||
1061 | state.startboard[state.y][state.x]--; | ||
1062 | state.currentboard[state.y][state.x]--; | ||
1063 | } | ||
1064 | } else { | ||
1065 | if (state.startboard[state.y][state.x]=='0') { | ||
1066 | if (state.currentboard[state.y][state.x]=='0') { | ||
1067 | state.currentboard[state.y][state.x]='9'; | ||
1068 | } else { | ||
1069 | state.currentboard[state.y][state.x]--; | ||
1070 | } | ||
1071 | } | ||
1072 | } | ||
1073 | update_cell(&state,state.y,state.x); | ||
1074 | break; | ||
1075 | #endif | ||
1076 | |||
1040 | /* move cursor left */ | 1077 | /* move cursor left */ |
1041 | case BUTTON_LEFT: | 1078 | case SUDOKU_BUTTON_LEFT: |
1042 | case (BUTTON_LEFT | BUTTON_REPEAT): | 1079 | case (SUDOKU_BUTTON_LEFT | BUTTON_REPEAT): |
1043 | if (state.x==0) { | 1080 | if (state.x==0) { |
1081 | #ifndef SUDOKU_BUTTON_UP | ||
1082 | if (state.y==0) { | ||
1083 | move_cursor(&state,8,8); | ||
1084 | } else { | ||
1085 | move_cursor(&state,8,state.y-1); | ||
1086 | } | ||
1087 | #else | ||
1044 | move_cursor(&state,8,state.y); | 1088 | move_cursor(&state,8,state.y); |
1089 | #endif | ||
1045 | } else { | 1090 | } else { |
1046 | move_cursor(&state,state.x-1,state.y); | 1091 | move_cursor(&state,state.x-1,state.y); |
1047 | } | 1092 | } |
1048 | break; | 1093 | break; |
1049 | 1094 | ||
1050 | /* move cursor right */ | 1095 | /* move cursor right */ |
1051 | case BUTTON_RIGHT: | 1096 | case SUDOKU_BUTTON_RIGHT: |
1052 | case (BUTTON_RIGHT | BUTTON_REPEAT): | 1097 | case (SUDOKU_BUTTON_RIGHT | BUTTON_REPEAT): |
1053 | if (state.x==8) { | 1098 | if (state.x==8) { |
1099 | #ifndef SUDOKU_BUTTON_DOWN | ||
1100 | if (state.y==8) { | ||
1101 | move_cursor(&state,0,0); | ||
1102 | } else { | ||
1103 | move_cursor(&state,0,state.y+1); | ||
1104 | } | ||
1105 | #else | ||
1054 | move_cursor(&state,0,state.y); | 1106 | move_cursor(&state,0,state.y); |
1107 | #endif | ||
1055 | } else { | 1108 | } else { |
1056 | move_cursor(&state,state.x+1,state.y); | 1109 | move_cursor(&state,state.x+1,state.y); |
1057 | } | 1110 | } |
1058 | break; | 1111 | break; |
1059 | 1112 | ||
1113 | #ifdef SUDOKU_BUTTON_UP | ||
1060 | /* move cursor up */ | 1114 | /* move cursor up */ |
1061 | case SUDOKU_BUTTON_UP: | 1115 | case SUDOKU_BUTTON_UP: |
1062 | case (SUDOKU_BUTTON_UP | BUTTON_REPEAT): | 1116 | case (SUDOKU_BUTTON_UP | BUTTON_REPEAT): |
@@ -1066,7 +1120,9 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
1066 | move_cursor(&state,state.x,state.y-1); | 1120 | move_cursor(&state,state.x,state.y-1); |
1067 | } | 1121 | } |
1068 | break; | 1122 | break; |
1123 | #endif | ||
1069 | 1124 | ||
1125 | #ifdef SUDOKU_BUTTON_DOWN | ||
1070 | /* move cursor down */ | 1126 | /* move cursor down */ |
1071 | case SUDOKU_BUTTON_DOWN: | 1127 | case SUDOKU_BUTTON_DOWN: |
1072 | case (SUDOKU_BUTTON_DOWN | BUTTON_REPEAT): | 1128 | case (SUDOKU_BUTTON_DOWN | BUTTON_REPEAT): |
@@ -1076,6 +1132,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
1076 | move_cursor(&state,state.x,state.y+1); | 1132 | move_cursor(&state,state.x,state.y+1); |
1077 | } | 1133 | } |
1078 | break; | 1134 | break; |
1135 | #endif | ||
1079 | 1136 | ||
1080 | case SUDOKU_BUTTON_MENU: | 1137 | case SUDOKU_BUTTON_MENU: |
1081 | #ifdef SUDOKU_BUTTON_MENU_PRE | 1138 | #ifdef SUDOKU_BUTTON_MENU_PRE |