diff --git a/README.md b/README.md index a779882..6f5692c 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,12 @@ Based off of the centuries old dice game. ### Changelog +#### V1.0.1 + * Fix dice roll - can now roll 11 and 12 + * Change dice overlay to increase size of text for selected element + * Auto restart game when going back from victory screen + * Increased size of dice images + #### V1.0 * Support for SDK2.0 * Improved logic to test if the player has lost diff --git a/appinfo.json b/appinfo.json index 25fd87a..1fd8030 100644 --- a/appinfo.json +++ b/appinfo.json @@ -3,8 +3,8 @@ "shortName": "Shut The Box", "longName": "Shut The Box", "companyName": "Dan Head", - "versionCode": 1, - "versionLabel": "1.0.0", + "versionCode": 2, + "versionLabel": "1.0.1", "watchapp": { "watchface": false }, diff --git a/resources/images/dice_1.png b/resources/images/dice_1.png index b2056e6..7396bb1 100644 Binary files a/resources/images/dice_1.png and b/resources/images/dice_1.png differ diff --git a/resources/images/dice_2.png b/resources/images/dice_2.png index f3d1a39..c8c2991 100644 Binary files a/resources/images/dice_2.png and b/resources/images/dice_2.png differ diff --git a/resources/images/dice_3.png b/resources/images/dice_3.png index 1a2cb16..7429046 100644 Binary files a/resources/images/dice_3.png and b/resources/images/dice_3.png differ diff --git a/resources/images/dice_4.png b/resources/images/dice_4.png index 67b4691..9fa78b6 100644 Binary files a/resources/images/dice_4.png and b/resources/images/dice_4.png differ diff --git a/resources/images/dice_5.png b/resources/images/dice_5.png index 271cccc..4624fd1 100644 Binary files a/resources/images/dice_5.png and b/resources/images/dice_5.png differ diff --git a/resources/images/dice_6.png b/resources/images/dice_6.png index 6ee36bb..e30dad6 100644 Binary files a/resources/images/dice_6.png and b/resources/images/dice_6.png differ diff --git a/shutthebox.pbw b/shutthebox.pbw index c689f6e..e065faa 100644 Binary files a/shutthebox.pbw and b/shutthebox.pbw differ diff --git a/src/game.c b/src/game.c index 91690a7..b76d31b 100644 --- a/src/game.c +++ b/src/game.c @@ -16,13 +16,8 @@ static struct { Layer *overlay; Layer *scoreboard; Layer *gameover; - GPath *pointer; } ui; static GFont font_s, font_l; -static GPathInfo arrow = { - .num_points = 3, - .points = (GPoint []) {{-7, -7}, {7, 0}, {-7, 7}} -}; typedef struct{ bool open; } object; @@ -103,12 +98,22 @@ static int total_left(void) { } static void roll_dice(int n) { - d1=(rand()%5)+1; + d1=(rand()%6)+1; d2=0; - if(n==2) d2=(rand()%5)+1; + if(n==2) d2=(rand()%6)+1; if(d1+d2<=total_left()) { game_stage=2; } + +} + +static void toggle_overlay() { + if(dice_selected == 1) { + dice_selected = 2; + } else { + dice_selected = 1; + } + layer_mark_dirty(ui.overlay); } void handle_second_tick(struct tm *tick_time, TimeUnits units_changed) { @@ -234,9 +239,9 @@ static void dice_update_callback(Layer *me, GContext* ctx) { } else if(game_stage == 2 || game_stage == 4) { int y = 10; if(game_stage == 4) y = 0; - graphics_draw_bitmap_in_rect(ctx, diceImgs[d1-1], GRect(30, y, 24, 24)); + graphics_draw_bitmap_in_rect(ctx, diceImgs[d1-1], GRect(30, y, 26, 26)); if(d2!=0) { - graphics_draw_bitmap_in_rect(ctx, diceImgs[d2-1], GRect(90, y, 24, 24)); + graphics_draw_bitmap_in_rect(ctx, diceImgs[d2-1], GRect(90, y, 26, 26)); } if(game_stage == 4) { graphics_draw_text(ctx, @@ -262,6 +267,8 @@ static void overlay_update_callback(Layer *me, GContext* ctx) { 8, GCornersAll); graphics_context_set_text_color(ctx, GColorBlack); + GFont die1 = (dice_selected==1)?font_l:font_s; + GFont die2 = (dice_selected==2)?font_l:font_s; graphics_draw_text(ctx, "How many dice?", font_s, @@ -271,20 +278,18 @@ static void overlay_update_callback(Layer *me, GContext* ctx) { NULL); graphics_draw_text(ctx, "1 Die", - font_s, - GRect(30, 25, 70, 25), + die1, + GRect(30, 22, 70, 30), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL); graphics_draw_text(ctx, "2 Dice", - font_s, - GRect(30, 50, 70, 25), + die2, + GRect(30, 48, 70, 30), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL); - graphics_context_set_fill_color(ctx, GColorBlack); - gpath_draw_filled(ctx, ui.pointer); } static void click_up(ClickRecognizerRef recognizer, void *context) { @@ -300,14 +305,7 @@ static void click_up(ClickRecognizerRef recognizer, void *context) { } selected = newtab; } else if(game_stage == 3) { - if(dice_selected == 1) { - dice_selected = 2; - gpath_move_to(ui.pointer, GPoint(15, 65)); - } else { - dice_selected = 1; - gpath_move_to(ui.pointer, GPoint(15, 42)); - layer_mark_dirty(ui.dice); - } + toggle_overlay(); } else if(game_stage == 4) { new_game(); //layer_mark_dirty(&dice); @@ -327,14 +325,7 @@ static void click_down(ClickRecognizerRef recognizer, void *context) { } selected = newtab; } else if(game_stage == 3) { - if(dice_selected == 1) { - dice_selected = 2; - gpath_move_to(ui.pointer, GPoint(15, 65)); - } else { - dice_selected = 1; - gpath_move_to(ui.pointer, GPoint(15, 42)); - } - layer_mark_dirty(ui.dice); + toggle_overlay(); } else if(game_stage == 4) { new_game(); layer_mark_dirty(ui.dice); @@ -347,8 +338,7 @@ static void click_select(ClickRecognizerRef recognizer, void *context) { layer_set_hidden(ui.overlay,false); game_stage = 3; dice_selected = 1; - gpath_move_to(ui.pointer, GPoint(15, 42)); - layer_mark_dirty(ui.dice); + layer_mark_dirty(ui.overlay); } else { roll_dice(2); if(!move_possible()) { @@ -365,6 +355,8 @@ static void click_select(ClickRecognizerRef recognizer, void *context) { tabs_closed++; if(check_move_is_done()) { if(tabs_closed==9) { + game_stage=1; + new_game(); gameover_init(true); } counter = 0; @@ -405,7 +397,6 @@ static void window_load(Window *window) { diceImgs[3] = gbitmap_create_with_resource(RESOURCE_ID_DICE_4); diceImgs[4] = gbitmap_create_with_resource(RESOURCE_ID_DICE_5); diceImgs[5] = gbitmap_create_with_resource(RESOURCE_ID_DICE_6); - ui.pointer = gpath_create(&arrow); ui.box = layer_create((GRect){ .origin = { 0, 0 }, diff --git a/src/menu.c b/src/menu.c index a953ab0..dbb59f3 100644 --- a/src/menu.c +++ b/src/menu.c @@ -69,6 +69,7 @@ static void toggle_menu(void) { } static void select_click_handler(ClickRecognizerRef recognizer, void *context) { if(combo[counter] == 1) { + counter=0; gameover_init(false); return; } diff --git a/src/overlay.c b/src/overlay.c deleted file mode 100644 index 738a5a9..0000000 --- a/src/overlay.c +++ /dev/null @@ -1,48 +0,0 @@ -#include -static Layer *layer; -static GRect bounds; -static void update_callback(Layer *me, GContext* ctx) { - graphics_context_set_fill_color(ctx, GColorBlack); - graphics_fill_rect(ctx, - GRect(0,0,bounds.size.w,bounds.size.h), - 8, - GCornersAll); - graphics_context_set_fill_color(ctx, GColorWhite); - graphics_fill_rect(ctx, - GRect(3,3,bounds.size.w-6,bounds.size.h-6), - 8, - GCornersAll); -} - -void overlay_init(Layer *window_layer, GRect b) { - bounds = b; - layer = layer_create(b); - layer_set_update_proc(layer, update_callback); - layer_set_hidden(layer, true); - layer_add_child(window_layer, layer); -} - -void overlay_deinit(void) { - layer_destroy(layer); -} -void overlay_show(void) { - layer_set_hidden(layer, false); -} -void overlay_hide(void) { - layer_set_hidden(layer, true); -} -bool overlay_is_visible(void) { - return !layer_get_hidden(layer); -} -void overlay_click_up(void) { - -} -void overlay_click_down(void) { - -} -void overlay_click_select(void) { - -} -void do_callback(void (*thecallback)(void)) { - thecallback(); -} \ No newline at end of file diff --git a/src/overlay.h b/src/overlay.h deleted file mode 100644 index c0d21d0..0000000 --- a/src/overlay.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once -#include - -void overlay_init(Layer *window_layer, GRect b); -void overlay_deinit(void); -void overlay_show(void); -void overlay_hide(void); -bool overlay_is_visible(void); -void overlay_click_up(void); -void overlay_click_down(void); -void overlay_click_select(void); -void do_callback(void (*thecallback)(void)); \ No newline at end of file diff --git a/src/rules.c b/src/rules.c index c49d455..f32da34 100644 --- a/src/rules.c +++ b/src/rules.c @@ -19,7 +19,7 @@ static void window_load(Window *window) { scroll_layer_add_child(ui.layer,text_layer_get_layer(ui.textTitle)); ui.textRules = text_layer_create(GRect(0,35,144,365)); - text_layer_set_text(ui.textRules,"The objective of the game is to close all 9 tiles and shut the box.\n\nRoll two dice and close any combination of tiles that equal the sum of the rolled dice.\n\nYou must use the sum of the dice each turn, if you cannot the game is over. Once the sum total of all the open tiles equals 6 or less, you have the choice of using one die instead of two.\n\n\nWritten by Daniel Head.\nme@danielhead.com"); + text_layer_set_text(ui.textRules,"The objective of the game is to close all 9 tiles and shut the box.\n\nRoll two dice and close any combination of tiles that equal the sum of the rolled dice.\n\nYou must use the sum of the dice each turn, if you cannot the game is over. Once the sum total of all the open tiles equals 6 or less, you have the choice of using one die instead of two.\n\n\nWritten by Daniel Head.\nme@danielhead.com\n\n\nV1.0.1"); text_layer_set_overflow_mode(ui.textRules,GTextOverflowModeWordWrap); text_layer_set_size(ui.textRules,GSize(144,365)); scroll_layer_add_child(ui.layer,text_layer_get_layer(ui.textRules));