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 Increase size of dice images
@@ -4,6 +4,12 @@ Based off of the centuries old dice game.
|
|||||||
|
|
||||||
### Changelog
|
### 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
|
#### V1.0
|
||||||
* Support for SDK2.0
|
* Support for SDK2.0
|
||||||
* Improved logic to test if the player has lost
|
* Improved logic to test if the player has lost
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
"shortName": "Shut The Box",
|
"shortName": "Shut The Box",
|
||||||
"longName": "Shut The Box",
|
"longName": "Shut The Box",
|
||||||
"companyName": "Dan Head",
|
"companyName": "Dan Head",
|
||||||
"versionCode": 1,
|
"versionCode": 2,
|
||||||
"versionLabel": "1.0.0",
|
"versionLabel": "1.0.1",
|
||||||
"watchapp": {
|
"watchapp": {
|
||||||
"watchface": false
|
"watchface": false
|
||||||
},
|
},
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 970 B After Width: | Height: | Size: 161 B |
|
Before Width: | Height: | Size: 981 B After Width: | Height: | Size: 171 B |
|
Before Width: | Height: | Size: 988 B After Width: | Height: | Size: 181 B |
|
Before Width: | Height: | Size: 977 B After Width: | Height: | Size: 167 B |
|
Before Width: | Height: | Size: 989 B After Width: | Height: | Size: 174 B |
|
Before Width: | Height: | Size: 980 B After Width: | Height: | Size: 163 B |
BIN
shutthebox.pbw
59
src/game.c
@@ -16,13 +16,8 @@ static struct {
|
|||||||
Layer *overlay;
|
Layer *overlay;
|
||||||
Layer *scoreboard;
|
Layer *scoreboard;
|
||||||
Layer *gameover;
|
Layer *gameover;
|
||||||
GPath *pointer;
|
|
||||||
} ui;
|
} ui;
|
||||||
static GFont font_s, font_l;
|
static GFont font_s, font_l;
|
||||||
static GPathInfo arrow = {
|
|
||||||
.num_points = 3,
|
|
||||||
.points = (GPoint []) {{-7, -7}, {7, 0}, {-7, 7}}
|
|
||||||
};
|
|
||||||
typedef struct{
|
typedef struct{
|
||||||
bool open;
|
bool open;
|
||||||
} object;
|
} object;
|
||||||
@@ -103,12 +98,22 @@ static int total_left(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void roll_dice(int n) {
|
static void roll_dice(int n) {
|
||||||
d1=(rand()%5)+1;
|
d1=(rand()%6)+1;
|
||||||
d2=0;
|
d2=0;
|
||||||
if(n==2) d2=(rand()%5)+1;
|
if(n==2) d2=(rand()%6)+1;
|
||||||
if(d1+d2<=total_left()) {
|
if(d1+d2<=total_left()) {
|
||||||
game_stage=2;
|
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) {
|
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) {
|
} else if(game_stage == 2 || game_stage == 4) {
|
||||||
int y = 10;
|
int y = 10;
|
||||||
if(game_stage == 4) y = 0;
|
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) {
|
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) {
|
if(game_stage == 4) {
|
||||||
graphics_draw_text(ctx,
|
graphics_draw_text(ctx,
|
||||||
@@ -262,6 +267,8 @@ static void overlay_update_callback(Layer *me, GContext* ctx) {
|
|||||||
8,
|
8,
|
||||||
GCornersAll);
|
GCornersAll);
|
||||||
graphics_context_set_text_color(ctx, GColorBlack);
|
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,
|
graphics_draw_text(ctx,
|
||||||
"How many dice?",
|
"How many dice?",
|
||||||
font_s,
|
font_s,
|
||||||
@@ -271,20 +278,18 @@ static void overlay_update_callback(Layer *me, GContext* ctx) {
|
|||||||
NULL);
|
NULL);
|
||||||
graphics_draw_text(ctx,
|
graphics_draw_text(ctx,
|
||||||
"1 Die",
|
"1 Die",
|
||||||
font_s,
|
die1,
|
||||||
GRect(30, 25, 70, 25),
|
GRect(30, 22, 70, 30),
|
||||||
GTextOverflowModeWordWrap,
|
GTextOverflowModeWordWrap,
|
||||||
GTextAlignmentLeft,
|
GTextAlignmentLeft,
|
||||||
NULL);
|
NULL);
|
||||||
graphics_draw_text(ctx,
|
graphics_draw_text(ctx,
|
||||||
"2 Dice",
|
"2 Dice",
|
||||||
font_s,
|
die2,
|
||||||
GRect(30, 50, 70, 25),
|
GRect(30, 48, 70, 30),
|
||||||
GTextOverflowModeWordWrap,
|
GTextOverflowModeWordWrap,
|
||||||
GTextAlignmentLeft,
|
GTextAlignmentLeft,
|
||||||
NULL);
|
NULL);
|
||||||
graphics_context_set_fill_color(ctx, GColorBlack);
|
|
||||||
gpath_draw_filled(ctx, ui.pointer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void click_up(ClickRecognizerRef recognizer, void *context) {
|
static void click_up(ClickRecognizerRef recognizer, void *context) {
|
||||||
@@ -300,14 +305,7 @@ static void click_up(ClickRecognizerRef recognizer, void *context) {
|
|||||||
}
|
}
|
||||||
selected = newtab;
|
selected = newtab;
|
||||||
} else if(game_stage == 3) {
|
} else if(game_stage == 3) {
|
||||||
if(dice_selected == 1) {
|
toggle_overlay();
|
||||||
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);
|
|
||||||
}
|
|
||||||
} else if(game_stage == 4) {
|
} else if(game_stage == 4) {
|
||||||
new_game();
|
new_game();
|
||||||
//layer_mark_dirty(&dice);
|
//layer_mark_dirty(&dice);
|
||||||
@@ -327,14 +325,7 @@ static void click_down(ClickRecognizerRef recognizer, void *context) {
|
|||||||
}
|
}
|
||||||
selected = newtab;
|
selected = newtab;
|
||||||
} else if(game_stage == 3) {
|
} else if(game_stage == 3) {
|
||||||
if(dice_selected == 1) {
|
toggle_overlay();
|
||||||
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);
|
|
||||||
} else if(game_stage == 4) {
|
} else if(game_stage == 4) {
|
||||||
new_game();
|
new_game();
|
||||||
layer_mark_dirty(ui.dice);
|
layer_mark_dirty(ui.dice);
|
||||||
@@ -347,8 +338,7 @@ static void click_select(ClickRecognizerRef recognizer, void *context) {
|
|||||||
layer_set_hidden(ui.overlay,false);
|
layer_set_hidden(ui.overlay,false);
|
||||||
game_stage = 3;
|
game_stage = 3;
|
||||||
dice_selected = 1;
|
dice_selected = 1;
|
||||||
gpath_move_to(ui.pointer, GPoint(15, 42));
|
layer_mark_dirty(ui.overlay);
|
||||||
layer_mark_dirty(ui.dice);
|
|
||||||
} else {
|
} else {
|
||||||
roll_dice(2);
|
roll_dice(2);
|
||||||
if(!move_possible()) {
|
if(!move_possible()) {
|
||||||
@@ -365,6 +355,8 @@ static void click_select(ClickRecognizerRef recognizer, void *context) {
|
|||||||
tabs_closed++;
|
tabs_closed++;
|
||||||
if(check_move_is_done()) {
|
if(check_move_is_done()) {
|
||||||
if(tabs_closed==9) {
|
if(tabs_closed==9) {
|
||||||
|
game_stage=1;
|
||||||
|
new_game();
|
||||||
gameover_init(true);
|
gameover_init(true);
|
||||||
}
|
}
|
||||||
counter = 0;
|
counter = 0;
|
||||||
@@ -405,7 +397,6 @@ static void window_load(Window *window) {
|
|||||||
diceImgs[3] = gbitmap_create_with_resource(RESOURCE_ID_DICE_4);
|
diceImgs[3] = gbitmap_create_with_resource(RESOURCE_ID_DICE_4);
|
||||||
diceImgs[4] = gbitmap_create_with_resource(RESOURCE_ID_DICE_5);
|
diceImgs[4] = gbitmap_create_with_resource(RESOURCE_ID_DICE_5);
|
||||||
diceImgs[5] = gbitmap_create_with_resource(RESOURCE_ID_DICE_6);
|
diceImgs[5] = gbitmap_create_with_resource(RESOURCE_ID_DICE_6);
|
||||||
ui.pointer = gpath_create(&arrow);
|
|
||||||
|
|
||||||
ui.box = layer_create((GRect){
|
ui.box = layer_create((GRect){
|
||||||
.origin = { 0, 0 },
|
.origin = { 0, 0 },
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ static void toggle_menu(void) {
|
|||||||
}
|
}
|
||||||
static void select_click_handler(ClickRecognizerRef recognizer, void *context) {
|
static void select_click_handler(ClickRecognizerRef recognizer, void *context) {
|
||||||
if(combo[counter] == 1) {
|
if(combo[counter] == 1) {
|
||||||
|
counter=0;
|
||||||
gameover_init(false);
|
gameover_init(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
#include <pebble.h>
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <pebble.h>
|
|
||||||
|
|
||||||
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));
|
|
||||||
@@ -19,7 +19,7 @@ static void window_load(Window *window) {
|
|||||||
scroll_layer_add_child(ui.layer,text_layer_get_layer(ui.textTitle));
|
scroll_layer_add_child(ui.layer,text_layer_get_layer(ui.textTitle));
|
||||||
|
|
||||||
ui.textRules = text_layer_create(GRect(0,35,144,365));
|
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_overflow_mode(ui.textRules,GTextOverflowModeWordWrap);
|
||||||
text_layer_set_size(ui.textRules,GSize(144,365));
|
text_layer_set_size(ui.textRules,GSize(144,365));
|
||||||
scroll_layer_add_child(ui.layer,text_layer_get_layer(ui.textRules));
|
scroll_layer_add_child(ui.layer,text_layer_get_layer(ui.textRules));
|
||||||
|
|||||||