diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..92968f0
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+build
+.lock-waf_linux2_build
diff --git a/README.md b/README.md
index 4d29fba..a779882 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,30 @@
-ShutTheBox
-==========
+## Shut the box Pebble app
-Shut the box game for the Pebble Watch
+Based off of the centuries old dice game.
+
+### Changelog
+
+#### V1.0
+ * Support for SDK2.0
+ * Improved logic to test if the player has lost
+ * New victory screen
+
+#### V0.1
+ * Initial release for SDK1.x
+
+# License
+Shut the box Pebble game
+Copyright (C) 2014 Daniel Head
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see .
diff --git a/appinfo.json b/appinfo.json
new file mode 100644
index 0000000..25fd87a
--- /dev/null
+++ b/appinfo.json
@@ -0,0 +1,89 @@
+{
+ "uuid": "b51ab6d6-496b-47d0-b015-9b5584121d09",
+ "shortName": "Shut The Box",
+ "longName": "Shut The Box",
+ "companyName": "Dan Head",
+ "versionCode": 1,
+ "versionLabel": "1.0.0",
+ "watchapp": {
+ "watchface": false
+ },
+ "appKeys": {
+ "dummy": 0
+ },
+ "resources": {
+ "media": [
+ {
+ "menuIcon":true,
+ "type":"png",
+ "name":"MENU_ICON",
+ "file":"images/menu_icon.png"
+ },
+ {
+ "type":"png",
+ "name":"MENU_BG",
+ "file":"images/menu_bg.png"
+ },
+ {
+ "type":"png",
+ "name":"BOX_BACKGROUND",
+ "file":"images/box_background.png"
+ },
+ {
+ "type":"png",
+ "name":"TAB_CLOSED",
+ "file":"images/tab_closed.png"
+ },
+ {
+ "type":"png",
+ "name":"TAB_OPEN",
+ "file":"images/tab_open.png"
+ },
+ {
+ "type":"png",
+ "name":"TAB_OPEN_SELECTED",
+ "file":"images/tab_open_selected.png"
+ },
+ {
+ "type":"png",
+ "name":"DICE_1",
+ "file":"images/dice_1.png"
+ },
+ {
+ "type":"png",
+ "name":"DICE_2",
+ "file":"images/dice_2.png"
+ },
+ {
+ "type":"png",
+ "name":"DICE_3",
+ "file":"images/dice_3.png"
+ },
+ {
+ "type":"png",
+ "name":"DICE_4",
+ "file":"images/dice_4.png"
+ },
+ {
+ "type":"png",
+ "name":"DICE_5",
+ "file":"images/dice_5.png"
+ },
+ {
+ "type":"png",
+ "name":"DICE_6",
+ "file":"images/dice_6.png"
+ },
+ {
+ "type":"png",
+ "name":"CITYSCAPE",
+ "file":"images/cityscape.png"
+ },
+ {
+ "type":"png",
+ "name":"MOON",
+ "file":"images/moon.png"
+ }
+ ]
+ }
+}
diff --git a/assets/header.png b/assets/header.png
new file mode 100644
index 0000000..de5e027
Binary files /dev/null and b/assets/header.png differ
diff --git a/assets/header.xcf b/assets/header.xcf
new file mode 100644
index 0000000..7ce9454
Binary files /dev/null and b/assets/header.xcf differ
diff --git a/assets/icon144.png b/assets/icon144.png
new file mode 100644
index 0000000..5641388
Binary files /dev/null and b/assets/icon144.png differ
diff --git a/assets/icon48.png b/assets/icon48.png
new file mode 100644
index 0000000..ee6fa8a
Binary files /dev/null and b/assets/icon48.png differ
diff --git a/assets/screenshot-game.png b/assets/screenshot-game.png
new file mode 100644
index 0000000..3a20527
Binary files /dev/null and b/assets/screenshot-game.png differ
diff --git a/assets/screenshot-menu.png b/assets/screenshot-menu.png
new file mode 100644
index 0000000..3f7ebcf
Binary files /dev/null and b/assets/screenshot-menu.png differ
diff --git a/resources/src/images/box_background.png b/resources/images/box_background.png
similarity index 100%
rename from resources/src/images/box_background.png
rename to resources/images/box_background.png
diff --git a/resources/images/cityscape.png b/resources/images/cityscape.png
new file mode 100644
index 0000000..f9aedfd
Binary files /dev/null and b/resources/images/cityscape.png differ
diff --git a/resources/src/images/dice_1.png b/resources/images/dice_1.png
similarity index 100%
rename from resources/src/images/dice_1.png
rename to resources/images/dice_1.png
diff --git a/resources/src/images/dice_2.png b/resources/images/dice_2.png
similarity index 100%
rename from resources/src/images/dice_2.png
rename to resources/images/dice_2.png
diff --git a/resources/src/images/dice_3.png b/resources/images/dice_3.png
similarity index 100%
rename from resources/src/images/dice_3.png
rename to resources/images/dice_3.png
diff --git a/resources/src/images/dice_4.png b/resources/images/dice_4.png
similarity index 100%
rename from resources/src/images/dice_4.png
rename to resources/images/dice_4.png
diff --git a/resources/src/images/dice_5.png b/resources/images/dice_5.png
similarity index 100%
rename from resources/src/images/dice_5.png
rename to resources/images/dice_5.png
diff --git a/resources/src/images/dice_6.png b/resources/images/dice_6.png
similarity index 100%
rename from resources/src/images/dice_6.png
rename to resources/images/dice_6.png
diff --git a/resources/images/menu_bg.png b/resources/images/menu_bg.png
new file mode 100644
index 0000000..c1674f1
Binary files /dev/null and b/resources/images/menu_bg.png differ
diff --git a/resources/src/images/menu_icon.png b/resources/images/menu_icon.png
similarity index 100%
rename from resources/src/images/menu_icon.png
rename to resources/images/menu_icon.png
diff --git a/resources/images/moon.png b/resources/images/moon.png
new file mode 100644
index 0000000..3b7b9b7
Binary files /dev/null and b/resources/images/moon.png differ
diff --git a/resources/src/images/tab_closed.png b/resources/images/tab_closed.png
similarity index 100%
rename from resources/src/images/tab_closed.png
rename to resources/images/tab_closed.png
diff --git a/resources/src/images/tab_open.png b/resources/images/tab_open.png
similarity index 100%
rename from resources/src/images/tab_open.png
rename to resources/images/tab_open.png
diff --git a/resources/src/images/tab_open_selected.png b/resources/images/tab_open_selected.png
similarity index 100%
rename from resources/src/images/tab_open_selected.png
rename to resources/images/tab_open_selected.png
diff --git a/resources/src/fonts/Google Android License.txt b/resources/src/fonts/Google Android License.txt
deleted file mode 100755
index 1a96dfd..0000000
--- a/resources/src/fonts/Google Android License.txt
+++ /dev/null
@@ -1,18 +0,0 @@
-Copyright (C) 2008 The Android Open Source Project
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-
-##########
-
-This directory contains the fonts for the platform. They are licensed
-under the Apache 2 license.
diff --git a/resources/src/fonts/Roboto-Bold.ttf b/resources/src/fonts/Roboto-Bold.ttf
deleted file mode 100755
index 91ec212..0000000
Binary files a/resources/src/fonts/Roboto-Bold.ttf and /dev/null differ
diff --git a/resources/src/fonts/Roboto-Condensed.ttf b/resources/src/fonts/Roboto-Condensed.ttf
deleted file mode 100755
index 6e7575a..0000000
Binary files a/resources/src/fonts/Roboto-Condensed.ttf and /dev/null differ
diff --git a/resources/src/images/me.png b/resources/src/images/me.png
deleted file mode 100644
index 38e2a6e..0000000
Binary files a/resources/src/images/me.png and /dev/null differ
diff --git a/resources/src/images/splash.png b/resources/src/images/splash.png
deleted file mode 100644
index efdedb0..0000000
Binary files a/resources/src/images/splash.png and /dev/null differ
diff --git a/resources/src/images/tab_closed_selected.png b/resources/src/images/tab_closed_selected.png
deleted file mode 100644
index 83592f4..0000000
Binary files a/resources/src/images/tab_closed_selected.png and /dev/null differ
diff --git a/resources/src/resource_map.json b/resources/src/resource_map.json
deleted file mode 100644
index c8398e9..0000000
--- a/resources/src/resource_map.json
+++ /dev/null
@@ -1,81 +0,0 @@
-
-{"friendlyVersion": "0.1",
- "versionDefName": "APP_RESOURCES",
- "media": [
- {
- "type":"png",
- "defName":"MENU_ICON",
- "file":"images/menu_icon.png"
- },
- {
- "type":"png",
- "defName":"SPLASH",
- "file":"images/splash.png"
- },
- {
- "type":"png",
- "defName":"BOX_BACKGROUND",
- "file":"images/box_background.png"
- },
- {
- "type":"png",
- "defName":"TAB_CLOSED",
- "file":"images/tab_closed.png"
- },
- {
- "type":"png",
- "defName":"TAB_OPEN",
- "file":"images/tab_open.png"
- },
- {
- "type":"png",
- "defName":"TAB_OPEN_SELECTED",
- "file":"images/tab_open_selected.png"
- },
- {
- "type":"png",
- "defName":"DICE_1",
- "file":"images/dice_1.png"
- },
- {
- "type":"png",
- "defName":"DICE_2",
- "file":"images/dice_2.png"
- },
- {
- "type":"png",
- "defName":"DICE_3",
- "file":"images/dice_3.png"
- },
- {
- "type":"png",
- "defName":"DICE_4",
- "file":"images/dice_4.png"
- },
- {
- "type":"png",
- "defName":"DICE_5",
- "file":"images/dice_5.png"
- },
- {
- "type":"png",
- "defName":"DICE_6",
- "file":"images/dice_6.png"
- },
- {
- "type":"png",
- "defName":"ME",
- "file":"images/me.png"
- },
- {
- "type": "font",
- "defName": "FONT_ROBOTO_BOLD_22",
- "file": "fonts/Roboto-Bold.ttf"
- },
- {
- "type": "font",
- "defName": "FONT_ROBOTO_BOLD_28",
- "file": "fonts/Roboto-Bold.ttf"
- }
- ]
-}
diff --git a/resources/wscript b/resources/wscript
deleted file mode 100644
index a9c383e..0000000
--- a/resources/wscript
+++ /dev/null
@@ -1,12 +0,0 @@
-
-import waftools.process_resources as res
-
-def build(bld):
-
- res.gen_resource_deps(bld,
- map_node=bld.path.find_node('src/resource_map.json'),
- pack_node=bld.path.parent.get_bld().make_node('app_resources.pbpack'),
- id_header_node=bld.path.parent.get_bld().make_node('src/resource_ids.auto.h'),
- resource_header_path="pebble_os.h")
-
-
diff --git a/shutthebox.pbw b/shutthebox.pbw
new file mode 100644
index 0000000..c689f6e
Binary files /dev/null and b/shutthebox.pbw differ
diff --git a/src/ShutTheBox.c b/src/ShutTheBox.c
deleted file mode 100644
index cf6b74c..0000000
--- a/src/ShutTheBox.c
+++ /dev/null
@@ -1,616 +0,0 @@
-#include "pebble_os.h"
-#include "pebble_app.h"
-#include "pebble_fonts.h"
-
-
-#define MY_UUID { 0xB5, 0x1A, 0xB6, 0xD6, 0x49, 0x6B, 0x47, 0xD0, 0xB0, 0x15, 0x9B, 0x55, 0x84, 0x12, 0x1D, 0x09 }
-PBL_APP_INFO(MY_UUID,
- "Shut the box", "Dan Head",
- 1, 0, /* App version */
- RESOURCE_ID_MENU_ICON,
- APP_INFO_STANDARD_APP);
-
-Window window_menu, window_rules, window_game, window_gameover;
-Layer menu, rules, box, dice, scoreboard, gameover;
-BmpContainer splash_image, box_background, tab_open, tab_open_selected, tab_closed, dice_images[6], me_image;
-GFont font_22, font_28;
-GPath arrows[4];
-
-GPathInfo arrow_up={3, (GPoint []){{10, 10}, {-10, 10}, {0, -10}}};
-GPathInfo arrow_right={3, (GPoint []){{-10, -10}, {10, 0}, {-10, 10}}};
-GPathInfo arrow_down={3, (GPoint []){{0, 10}, {-10, -10}, {10, -10}}};
-GPathInfo arrow_left={3, (GPoint []){{-10, 0}, {10, -10}, {10, 10}}};
-
-typedef struct{
- bool open;
-} object;
-
-object tabs[9];
-int selected, game_stage, d1, d2, counter, rules_posY = 5, menu_pointer, dice_selected, tabs_closed, random=0;
-PblTm current_time;
-long seed = 0;
-
-/* ------------------------------------------------------------------ //
-
- METHODS
-
-// ------------------------------------------------------------------ */
-
-void new_game() {
- get_time(¤t_time);
- seed = (current_time.tm_hour*3600)*(current_time.tm_min*60)*current_time.tm_sec;
- counter = 0;
- selected = 0;
- dice_selected = 0;
- tabs_closed = 0;
- game_stage = 1;
- for(int i=0;i<9;i++) {
- tabs[i].open = true;
- }
-}
-
-void new_gameover() {
- window_stack_push(&window_gameover, true);
- layer_mark_dirty(&gameover);
- new_game();
-}
-bool move_possible() {
- //get remaining numbers
- int nLeft[9], h = 0;
- int target = d1+d2;
- for(int i=0;id1+d2) return false;
- if(x>d1+d2-counter) return false;
- return true;
-}
-
-bool check_move_is_done() {
- if(counter==d1+d2) {
- return true;
- } else if(counter>d1+d2) {
-
- }
- return false;
-}
-
-int total_left() {
- int total = 0;
- for(int i=0;i<9;i++) {
- if(tabs[i].open) {
- total+=i+1;
- }
- }
- return total;
-}
-
-void roll_dice(int n) {
- seed = (((seed * 214013L + 2531011L) >> 16) & 32767);
- if ((seed%6) == 0) {
- seed++;
- seed = (((seed * 214013L + 2531011L) >> 16) & 32767);
- d1=((seed%6)+1);
- d2=((seed%6)+1);
- } else {
- d1=((seed%6)+1);
- seed++;
- seed = (((seed * 214013L + 2531011L) >> 16) & 32767);
- d2=((seed%6)+1);
- }
- if(n==1) d2=0;
- if(d1+d2<=total_left()) {
- game_stage=2;
- }
-}
-
-void menu_move_arrow() {
- if(menu_pointer == 0) {
- gpath_move_to(&arrows[0], GPoint(15, 150));
- menu_pointer = 1;
- } else {
- gpath_move_to(&arrows[0], GPoint(15, 120));
- menu_pointer = 0;
- }
- layer_mark_dirty(&menu);
-}
-
-/* ------------------------------------------------------------------ //
-
- UPDATE CALLBACKS
-
-// ------------------------------------------------------------------ */
-
-void menu_update_callback(Layer *me, GContext* ctx) {
- (void)me;
- (void)ctx;
- graphics_draw_bitmap_in_rect(ctx, &splash_image.bmp, GRect(0, 0, 144, 100));
- gpath_draw_filled(ctx, &arrows[0]);
- graphics_context_set_text_color(ctx, GColorBlack);
- graphics_text_draw(ctx,
- "Play",
- font_22,
- GRect(30, 105, 80, 30),
- GTextOverflowModeWordWrap,
- GTextAlignmentLeft,
- NULL);
- graphics_text_draw(ctx,
- "Rules",
- font_22,
- GRect(30, 135, 120, 30),
- GTextOverflowModeWordWrap,
- GTextAlignmentLeft,
- NULL);
-
-}
-
-void rules_update_callback(Layer *me, GContext* ctx) {
- (void)me;
- (void)ctx;
- graphics_context_set_text_color(ctx, GColorBlack);
-
- graphics_text_draw(ctx,"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",
- fonts_get_system_font(FONT_KEY_FONT_FALLBACK),
- GRect(5, rules_posY, 120, 400),
- GTextOverflowModeWordWrap,
- GTextAlignmentLeft,
- NULL);
-
- if(rules_posY!=5) {
- gpath_draw_filled(ctx, &arrows[1]);
- }
- if(rules_posY!=-250) {
- gpath_draw_filled(ctx, &arrows[2]);
- }
-}
-
-void box_update_callback(Layer *me, GContext* ctx) {
- (void)me;
- (void)ctx;
- GRect dest = layer_get_frame(&box_background.layer.layer);
- dest.origin.x = 4;
- dest.origin.y = 10;
- graphics_draw_bitmap_in_rect(ctx, &box_background.bmp, dest);
-
-
- for(int i=0;i<9;i++) {
- int x,y;
- BmpContainer image;
- if(i<5) {
- x = 8+(i*26);
- y = (tabs[i].open)?4:14;
- } else {
- x = 12+((i-5)*32);
- y = (tabs[i].open)?60:70;
- }
- if(tabs[i].open) {
- if(i==selected) {
- image = tab_open_selected;
- } else {
- image = tab_open;
- }
- } else {
- image = tab_closed;
- }
- graphics_draw_bitmap_in_rect(ctx, &image.bmp, GRect(x, y, 24, 44));
- }
- graphics_context_set_text_color(ctx, GColorBlack);
- if(tabs[0].open) {
- graphics_text_draw(ctx,
- "1",
- font_28,
- GRect(12, 15, 20, 30),
- GTextOverflowModeWordWrap,
- GTextAlignmentLeft,
- NULL);
- }
- if(tabs[1].open) {
- graphics_text_draw(ctx,
- "2",
- font_28,
- GRect(38, 15, 20, 30),
- GTextOverflowModeWordWrap,
- GTextAlignmentLeft,
- NULL);
- }
- if(tabs[2].open) {
- graphics_text_draw(ctx,
- "3",
- font_28,
- GRect(64, 16, 20, 30),
- GTextOverflowModeWordWrap,
- GTextAlignmentLeft,
- NULL);
- }
- if(tabs[3].open) {
- graphics_text_draw(ctx,
- "4",
- font_28,
- GRect(90, 15, 20, 30),
- GTextOverflowModeWordWrap,
- GTextAlignmentLeft,
- NULL);
- }
- if(tabs[4].open) {
- graphics_text_draw(ctx,
- "5",
- font_28,
- GRect(116, 15, 20, 30),
- GTextOverflowModeWordWrap,
- GTextAlignmentLeft,
- NULL);
- }
- if(tabs[5].open) {
- graphics_text_draw(ctx,
- "6",
- font_28,
- GRect(16, 71, 20, 30),
- GTextOverflowModeWordWrap,
- GTextAlignmentLeft,
- NULL);
- }
- if(tabs[6].open) {
- graphics_text_draw(ctx,
- "7",
- font_28,
- GRect(48, 71, 20, 30),
- GTextOverflowModeWordWrap,
- GTextAlignmentLeft,
- NULL);
- }
- if(tabs[7].open) {
- graphics_text_draw(ctx,
- "8",
- font_28,
- GRect(80, 71, 20, 30),
- GTextOverflowModeWordWrap,
- GTextAlignmentLeft,
- NULL);
- }
- if(tabs[8].open) {
- graphics_text_draw(ctx,
- "9",
- font_28,
- GRect(112, 71, 20, 30),
- GTextOverflowModeWordWrap,
- GTextAlignmentLeft,
- NULL);
- }
-}
-
-void dice_update_callback(Layer *me, GContext* ctx) {
- (void)me;
- (void)ctx;
-
- graphics_context_set_text_color(ctx, GColorBlack);
- if(game_stage == 1) {
-
- graphics_text_draw(ctx,
- "Roll Dice",
- font_22,
- GRect(30, 5, 100, 30),
- GTextOverflowModeWordWrap,
- GTextAlignmentLeft,
- NULL);
- } else if(game_stage == 2 || game_stage == 4) {
- graphics_draw_bitmap_in_rect(ctx, &dice_images[d1-1].bmp, GRect(25, 10, 24, 24));
- if(d2!=0) {
- graphics_draw_bitmap_in_rect(ctx, &dice_images[d2-1].bmp, GRect(90, 10, 24, 24));
- }
-
- } else if(game_stage == 3) {
-
- graphics_text_draw(ctx,
- "1 Die",
- font_22,
- GRect(30, 5, 100, 25),
- GTextOverflowModeWordWrap,
- GTextAlignmentLeft,
- NULL);
- graphics_text_draw(ctx,
- "2 Dice",
- font_22,
- GRect(30, 30, 100, 25),
- GTextOverflowModeWordWrap,
- GTextAlignmentLeft,
- NULL);
-
- gpath_draw_filled(ctx, &arrows[3]);
-
- }
- if(game_stage == 4) {
- graphics_text_draw(ctx,
- "Game over",
- font_22,
- GRect(20, 30, 120, 30),
- GTextOverflowModeWordWrap,
- GTextAlignmentLeft,
- NULL);
- }
-
-}
-
-void gameover_update_callback(Layer *me, GContext* ctx) {
- (void)me;
- (void)ctx;
- graphics_draw_bitmap_in_rect(ctx, &me_image.bmp, GRect(0, 0, 144, 130));
- graphics_context_set_text_color(ctx, GColorBlack);
- graphics_text_draw(ctx,
- "You win!",
- font_28,
- GRect(0, 125, 134, 40),
- GTextOverflowModeWordWrap,
- GTextAlignmentCenter,
- NULL);
-
-}
-
-/* ------------------------------------------------------------------ //
-
- CLICK HANDLERS
-
-// ------------------------------------------------------------------ */
-
-void menu_up_single_click_handler(ClickRecognizerRef recognizer, Window *window) {
- menu_move_arrow();
-}
-void menu_down_single_click_handler(ClickRecognizerRef recognizer, Window *window) {
- menu_move_arrow();
-
-}
-void menu_select_single_click_handler(ClickConfig **config, Window *window) {
- if(menu_pointer == 1) {
- window_stack_push(&window_rules, true);
- layer_mark_dirty(&rules);
- } else {
- new_game();
- window_stack_push(&window_game, true);
- layer_mark_dirty(&box);
- }
-}
-void rules_up_single_click_handler(ClickRecognizerRef recognizer, Window *window) {
- rules_posY=rules_posY+25;
- if(rules_posY>5) {
- rules_posY=5;
- }
- layer_mark_dirty(&rules);
-}
-void rules_down_single_click_handler(ClickRecognizerRef recognizer, Window *window) {
- rules_posY=rules_posY-25;
- if(rules_posY<-250) {
- rules_posY=-250;
- }
- layer_mark_dirty(&rules);
-}
-void rules_select_single_click_handler(ClickConfig **config, Window *window) {
-
-}
-void game_up_single_click_handler(ClickRecognizerRef recognizer, Window *window) {
- if(game_stage == 1) {
- roll_dice(2);
- } else if(game_stage == 2) {
- int newtab = selected+1;
- if(newtab>8) newtab = 0;
- while(!tabs[newtab].open) {
- newtab++;
- if(newtab>8) newtab = 0;
- if(newtab==selected) break;
- }
- selected = newtab;
- } else if(game_stage == 3) {
- if(dice_selected == 1) {
- dice_selected = 2;
- gpath_move_to(&arrows[3], GPoint(15, 45));
- } else {
- dice_selected = 1;
- gpath_move_to(&arrows[3], GPoint(15, 20));
- }
- } else if(game_stage == 4) {
- new_game();
- layer_mark_dirty(&dice);
- }
- layer_mark_dirty(&box);
-
-}
-void game_down_single_click_handler(ClickRecognizerRef recognizer, Window *window) {
- if(game_stage == 1) {
- roll_dice(2);
- } else if(game_stage == 2) {
- int newtab = selected-1;
- if(newtab<0) newtab = 8;
- while(!tabs[newtab].open) {
- newtab--;
- if(newtab<0) newtab = 8;
- if(newtab==selected) break;
- }
- selected = newtab;
- } else if(game_stage == 3) {
- if(dice_selected == 1) {
- dice_selected = 2;
- gpath_move_to(&arrows[3], GPoint(15, 45));
- } else {
- dice_selected = 1;
- gpath_move_to(&arrows[3], GPoint(15, 20));
- }
- } else if(game_stage == 4) {
- new_game();
- layer_mark_dirty(&dice);
- }
- layer_mark_dirty(&box);
-
-}
-void game_select_single_click_handler(ClickRecognizerRef recognizer, Window *window) {
- if(game_stage == 1) {
- if(total_left()<7) {
- game_stage = 3;
- dice_selected = 1;
- gpath_move_to(&arrows[3], GPoint(15, 20));
- layer_mark_dirty(&dice);
- } else {
- roll_dice(2);
- if(!move_possible()) {
- game_stage=4;
- layer_mark_dirty(&scoreboard);
- }
- }
- } else if(game_stage == 2) {
- if(tabs[selected].open) {
- int x = selected+1;
- if(is_legal(x)) {
- counter+=x;
- tabs[selected].open = false;
- tabs_closed++;
- if(check_move_is_done()) {
- if(tabs_closed==9) {
- new_gameover();
- }
- counter = 0;
- game_stage = 1;
- selected = 0;
- while(!tabs[selected].open) {
- selected++;
- }
- layer_mark_dirty(&dice);
- }
- }
- }
- } else if(game_stage == 3) {
- roll_dice(dice_selected);
- if(!move_possible()) {
- game_stage=4;
- }
- } else if(game_stage == 4) {
- new_game();
- layer_mark_dirty(&dice);
- }
- layer_mark_dirty(&box);
-}
-void menu_config_provider(ClickConfig **config, Window *window) {
- config[BUTTON_ID_UP]->click.handler = (ClickHandler) menu_up_single_click_handler;
- config[BUTTON_ID_DOWN]->click.handler = (ClickHandler) menu_down_single_click_handler;
- config[BUTTON_ID_SELECT]->click.handler = (ClickHandler) menu_select_single_click_handler;
- (void)window;
-}
-void rules_config_provider(ClickConfig **config, Window *window) {
- config[BUTTON_ID_UP]->click.handler = (ClickHandler) rules_up_single_click_handler;
- config[BUTTON_ID_DOWN]->click.handler = (ClickHandler) rules_down_single_click_handler;
- config[BUTTON_ID_SELECT]->click.handler = (ClickHandler) rules_select_single_click_handler;
- (void)window;
-}
-void game_config_provider(ClickConfig **config, Window *window) {
- config[BUTTON_ID_UP]->click.handler = (ClickHandler) game_up_single_click_handler;
- config[BUTTON_ID_DOWN]->click.handler = (ClickHandler) game_down_single_click_handler;
- config[BUTTON_ID_SELECT]->click.handler = (ClickHandler) game_select_single_click_handler;
- (void)window;
-}
-
-/* ------------------------------------------------------------------ //
-
- INIT / DEINIT STUFF
-
-// ------------------------------------------------------------------ */
-
-void handle_init(AppContextRef ctx) {
- (void)ctx;
- window_init(&window_menu, "Shut the box");
- window_init(&window_rules, "Shut the box rules");
- window_init(&window_game, "Shut the box");
- window_init(&window_gameover, "Game Over");
- window_set_fullscreen(&window_menu, true);
- window_set_fullscreen(&window_game, true);
- window_set_fullscreen(&window_gameover, true);
- window_stack_push(&window_menu, true);
- layer_init(&menu, window_menu.layer.frame);
- layer_init(&rules, window_rules.layer.frame);
- layer_init(&box, window_game.layer.frame);
- layer_init(&dice, GRect(0, 110, 144, 58));
- layer_init(&gameover, window_gameover.layer.frame);
- menu.update_proc = &menu_update_callback;
- rules.update_proc = &rules_update_callback;
- box.update_proc = &box_update_callback;
- dice.update_proc = &dice_update_callback;
- gameover.update_proc = &gameover_update_callback;
- layer_add_child(&window_menu.layer, &menu);
- layer_add_child(&window_rules.layer, &rules);
- layer_add_child(&window_game.layer, &box);
- layer_add_child(&window_game.layer, &dice);
- layer_add_child(&window_gameover.layer, &gameover);
-
- resource_init_current_app(&APP_RESOURCES);
- font_22 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_BOLD_22));
- font_28 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_BOLD_28));
- bmp_init_container(RESOURCE_ID_SPLASH, &splash_image);
- bmp_init_container(RESOURCE_ID_BOX_BACKGROUND, &box_background);
- bmp_init_container(RESOURCE_ID_TAB_CLOSED, &tab_closed);
- bmp_init_container(RESOURCE_ID_TAB_OPEN, &tab_open);
- bmp_init_container(RESOURCE_ID_TAB_OPEN_SELECTED, &tab_open_selected);
- bmp_init_container(RESOURCE_ID_ME, &me_image);
- bmp_init_container(RESOURCE_ID_DICE_1, &dice_images[0]);
- bmp_init_container(RESOURCE_ID_DICE_2, &dice_images[1]);
- bmp_init_container(RESOURCE_ID_DICE_3, &dice_images[2]);
- bmp_init_container(RESOURCE_ID_DICE_4, &dice_images[3]);
- bmp_init_container(RESOURCE_ID_DICE_5, &dice_images[4]);
- bmp_init_container(RESOURCE_ID_DICE_6, &dice_images[5]);
- window_set_click_config_provider(&window_menu, (ClickConfigProvider) menu_config_provider);
- window_set_click_config_provider(&window_rules, (ClickConfigProvider) rules_config_provider);
- window_set_click_config_provider(&window_game, (ClickConfigProvider) game_config_provider);
-
- gpath_init(&arrows[0], &arrow_right);
- gpath_move_to(&arrows[0], GPoint(15, 120));
- gpath_init(&arrows[1], &arrow_up);
- gpath_move_to(&arrows[1], GPoint(133, 10));
- gpath_init(&arrows[2], &arrow_down);
- gpath_move_to(&arrows[2], GPoint(133, 138));
- gpath_init(&arrows[3], &arrow_right);
- layer_mark_dirty(&menu);
-}
-
-void handle_deinit(AppContextRef ctx) {
- (void)ctx;
- bmp_deinit_container(&splash_image);
- bmp_deinit_container(&box_background);
- bmp_deinit_container(&tab_closed);
- bmp_deinit_container(&tab_open);
- bmp_deinit_container(&tab_open_selected);
- bmp_deinit_container(&me_image);
- for(int i=0;i<6;i++){
- bmp_deinit_container(&dice_images[i]);
- }
-}
-
-void pbl_main(void *params) {
- PebbleAppHandlers handlers = {
- .init_handler = &handle_init,
- .deinit_handler = &handle_deinit
- };
- app_event_loop(params, &handlers);
-}
diff --git a/src/game.c b/src/game.c
new file mode 100644
index 0000000..91690a7
--- /dev/null
+++ b/src/game.c
@@ -0,0 +1,464 @@
+#include
+#include "gameover.h"
+
+static struct {
+ GBitmap *background;
+ GBitmap *tab_closed;
+ GBitmap *tab_open;
+ GBitmap *tab_open_selected;
+} boxImgs;
+GBitmap *diceImgs[6];
+
+static struct {
+ Window *window;
+ Layer *box;
+ Layer *dice;
+ 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;
+object tabs[9];
+int selected, game_stage, d1, d2, counter, dice_selected, tabs_closed;
+
+static void new_game(void) {
+ srand(time(0));
+ counter = 0;
+ selected = 0;
+ dice_selected = 0;
+ tabs_closed = 0;
+ game_stage = 1;
+ for(int i=0;i<9;i++) {
+ tabs[i].open = true;
+ }
+}
+
+static bool move_possible(void) {
+ //get remaining numbers
+ int nLeft[9], h = 0;
+ int target = d1+d2-counter;
+ for(int i=0;id1+d2) return false;
+ if(x>d1+d2-counter) return false;
+ return true;
+}
+
+static bool check_move_is_done(void) {
+ if(counter==d1+d2) {
+ return true;
+ } else if(counter8) newtab = 0;
+ while(!tabs[newtab].open) {
+ newtab++;
+ if(newtab>8) newtab = 0;
+ if(newtab==selected) break;
+ }
+ 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);
+ }
+ } else if(game_stage == 4) {
+ new_game();
+ //layer_mark_dirty(&dice);
+ }
+ layer_mark_dirty(ui.box);
+}
+static void click_down(ClickRecognizerRef recognizer, void *context) {
+ if(game_stage == 1) {
+ roll_dice(2);
+ } else if(game_stage == 2) {
+ int newtab = selected-1;
+ if(newtab<0) newtab = 8;
+ while(!tabs[newtab].open) {
+ newtab--;
+ if(newtab<0) newtab = 8;
+ if(newtab==selected) break;
+ }
+ 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);
+ } else if(game_stage == 4) {
+ new_game();
+ layer_mark_dirty(ui.dice);
+ }
+ layer_mark_dirty(ui.box);
+}
+static void click_select(ClickRecognizerRef recognizer, void *context) {
+ if(game_stage == 1) {
+ if(total_left()<7) {
+ 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);
+ } else {
+ roll_dice(2);
+ if(!move_possible()) {
+ game_stage=4;
+ layer_mark_dirty(ui.dice);
+ }
+ }
+ } else if(game_stage == 2) {
+ if(tabs[selected].open) {
+ int x = selected+1;
+ if(is_legal(x)) {
+ counter+=x;
+ tabs[selected].open = false;
+ tabs_closed++;
+ if(check_move_is_done()) {
+ if(tabs_closed==9) {
+ gameover_init(true);
+ }
+ counter = 0;
+ game_stage = 1;
+ selected = 0;
+ while(!tabs[selected].open) {
+ selected++;
+ }
+ layer_mark_dirty(ui.dice);
+ }
+ }
+ }
+ } else if(game_stage == 3) {
+ layer_set_hidden(ui.overlay,true);
+ roll_dice(dice_selected);
+ if(!move_possible()) {
+ game_stage=4;
+ layer_mark_dirty(ui.dice);
+ }
+ } else if(game_stage == 4) {
+ new_game();
+ layer_mark_dirty(ui.dice);
+ }
+ layer_mark_dirty(ui.box);
+}
+
+static void window_load(Window *window) {
+ Layer *window_layer = window_get_root_layer(ui.window);
+ font_s = fonts_get_system_font(FONT_KEY_GOTHIC_24);
+ font_l = fonts_get_system_font(FONT_KEY_GOTHIC_28);
+ boxImgs.background = gbitmap_create_with_resource(RESOURCE_ID_BOX_BACKGROUND);
+ boxImgs.tab_closed = gbitmap_create_with_resource(RESOURCE_ID_TAB_CLOSED);
+ boxImgs.tab_open = gbitmap_create_with_resource(RESOURCE_ID_TAB_OPEN);
+ boxImgs.tab_open_selected = gbitmap_create_with_resource(RESOURCE_ID_TAB_OPEN_SELECTED);
+ diceImgs[0] = gbitmap_create_with_resource(RESOURCE_ID_DICE_1);
+ diceImgs[1] = gbitmap_create_with_resource(RESOURCE_ID_DICE_2);
+ diceImgs[2] = gbitmap_create_with_resource(RESOURCE_ID_DICE_3);
+ 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 },
+ .size = { 144, 118 }
+ });
+ ui.dice = layer_create((GRect){
+ .origin = { 0, 120 },
+ .size = { 144, 48 }
+ });
+ ui.overlay = layer_create((GRect) {
+ .origin = { 15, 70 },
+ .size = { 114, 80 }
+ });
+ layer_set_hidden(ui.overlay,true);
+ layer_set_update_proc(ui.box, box_update_callback);
+ layer_set_update_proc(ui.dice, dice_update_callback);
+ layer_set_update_proc(ui.overlay, overlay_update_callback);
+ layer_add_child(window_layer, ui.box);
+ layer_add_child(window_layer, ui.dice);
+ layer_add_child(window_layer, ui.overlay);
+
+ new_game();
+}
+
+static void window_unload(Window *window) {
+ gbitmap_destroy(boxImgs.background);
+ gbitmap_destroy(boxImgs.tab_closed);
+ gbitmap_destroy(boxImgs.tab_open);
+ gbitmap_destroy(boxImgs.tab_open_selected);
+ gbitmap_destroy(diceImgs[0]);
+ gbitmap_destroy(diceImgs[1]);
+ gbitmap_destroy(diceImgs[2]);
+ gbitmap_destroy(diceImgs[3]);
+ gbitmap_destroy(diceImgs[4]);
+ gbitmap_destroy(diceImgs[5]);
+}
+
+static void click_config_provider(void *context) {
+ window_single_click_subscribe(BUTTON_ID_SELECT, click_select);
+ window_single_click_subscribe(BUTTON_ID_UP, click_up);
+ window_single_click_subscribe(BUTTON_ID_DOWN, click_down);
+}
+
+void game_init(void) {
+ ui.window = window_create();
+ window_set_fullscreen(ui.window, true);
+ window_set_click_config_provider(ui.window, click_config_provider);
+ window_set_window_handlers(ui.window, (WindowHandlers) {
+ .load = window_load,
+ .unload = window_unload,
+ });
+ window_stack_push(ui.window, true);
+}
+void game_deinit(void) {
+ window_destroy(ui.window);
+}
\ No newline at end of file
diff --git a/src/game.h b/src/game.h
new file mode 100644
index 0000000..a09a443
--- /dev/null
+++ b/src/game.h
@@ -0,0 +1,4 @@
+#pragma once
+
+void game_init(void);
+void game_deinit(void);
\ No newline at end of file
diff --git a/src/gameover.c b/src/gameover.c
new file mode 100644
index 0000000..1da8e0c
--- /dev/null
+++ b/src/gameover.c
@@ -0,0 +1,204 @@
+#include
+
+static struct {
+ Window *window;
+ Layer *cityscape;
+ Layer *moon;
+ Layer *anim;
+ Layer *text;
+} ui;
+static struct {
+ GBitmap *cityscape;
+ GBitmap *moon;
+} images;
+static GPoint firework;
+static PropertyAnimation *moon_animation, *cityscape_animation, *text_animation;
+static AppTimer *timer;
+static GFont font_l;
+static bool exploded;
+static int duration, particles, gravity, speed;
+static char wintext[12];
+
+static struct {
+ int d;
+ int s;
+ int delay;
+ GPoint pos;
+} points[256];
+
+void firework_start(int x) {
+ particles = 256;
+ duration = 0;
+ gravity = 20;
+ speed = 30;
+ exploded = false;
+ firework.x = x;
+ firework.y = 160;
+}
+void explosion_start(void) {
+ exploded = true;
+ duration = 0;
+ int d = 0;
+ for(int c=0;c360) d-=360;
+ d+=(rand()%250)+1;
+ points[c].d = d*180;
+ points[c].s = (rand()%10)+10;
+ points[c].delay = (rand()%250);
+ points[c].pos = (GPoint){
+ .x = firework.x,
+ .y = firework.y
+ };
+ }
+ vibes_long_pulse();
+}
+void firework_update(void) {
+ if(!exploded) {
+ speed=(int16_t)(speed - (int32_t)(speed*gravity/100));
+ firework.y-=speed;
+ if(firework.y<(rand()%30)+40) {
+ explosion_start();
+ }
+ }
+ if(exploded && duration < 2500) {
+ for(int c=0;cpoints[c].delay) {
+ points[c].s = (int16_t)(points[c].s - (int32_t)(points[c].s*gravity/100));
+ int x = (int16_t)(sin_lookup(points[c].d) * (int32_t)points[c].s / TRIG_MAX_RATIO);
+ x = (int16_t)(x - (int32_t)(x*gravity/100));
+ int y = (int16_t)(-cos_lookup(points[c].d) * (int32_t)points[c].s / TRIG_MAX_RATIO);
+ y = (int16_t)(y - (int32_t)(y*gravity/100));
+ points[c].pos = (GPoint){
+ .x = x + points[c].pos.x,
+ .y = y + points[c].pos.y
+ };
+ }
+ }
+ }
+}
+
+static void timer_callback(void *context) {
+ const uint32_t timeout_ms = 50;
+ duration += 50;
+ if(duration>2500) {
+ firework_start(rand()%80+30);
+ }
+ firework_update();
+ layer_mark_dirty(ui.anim);
+ timer = app_timer_register(timeout_ms, timer_callback, NULL);
+}
+static void cityscape_update_callback(Layer *me, GContext* ctx) {
+ graphics_draw_bitmap_in_rect(ctx, images.cityscape, GRect(0,0,250,168));
+}
+static void moon_update_callback(Layer *me, GContext* ctx) {
+ graphics_draw_bitmap_in_rect(ctx, images.moon, GRect(0,0,32,33));
+}
+static void anim_update_callback(Layer *me, GContext* ctx) {
+ graphics_context_set_stroke_color(ctx, GColorWhite);
+ if(!exploded) {
+ for(int c=0;c<3;c++) {
+ for(int d=0;d<6;d++) {
+ graphics_draw_pixel(ctx, GPoint((firework.x+c),(firework.y+d)));
+ }
+ }
+ } else {
+ for(int c=0;c
+#include "menu.h"
+#include "rules.h"
+#include "game.h"
+#include "gameover.h"
+
+static uint32_t resources[] = {
+ RESOURCE_ID_MENU_BG
+};
+static struct {
+ Window *window;
+ Layer *layer;
+ TextLayer *textPlay;
+ TextLayer *textRules;
+ GBitmap *background;
+ GPath *pointer;
+} ui;
+static int choice = 0, counter = 0, combo[] = {0,0,2,2,0,2,0,2,1};
+static GFont font;
+static GPathInfo arrow = {
+ .num_points = 3,
+ .points = (GPoint []) {{-7, -7}, {7, 0}, {-7, 7}}
+};
+
+static void update_callback(Layer *me, GContext* ctx) {
+ graphics_draw_bitmap_in_rect(ctx, ui.background, GRect(0,0,144,168));
+ graphics_context_set_fill_color(ctx, GColorBlack);
+ gpath_draw_filled(ctx, ui.pointer);
+}
+
+static void window_load(Window *window) {
+ Layer *window_layer = window_get_root_layer(ui.window);
+ font = fonts_get_system_font(FONT_KEY_GOTHIC_24);
+ GRect bounds = layer_get_frame(window_layer);
+ ui.layer = layer_create(bounds);
+ layer_set_update_proc(ui.layer, update_callback);
+ ui.background = gbitmap_create_with_resource(resources[0]);
+
+ ui.textPlay = text_layer_create((GRect) { .origin = { 70, 32 }, .size = { bounds.size.w, 40 } });
+ ui.textRules = text_layer_create((GRect) { .origin = { 70, 50 }, .size = { bounds.size.w, 40 } });
+ text_layer_set_text(ui.textPlay, "Play");
+ text_layer_set_text(ui.textRules, "Rules");
+ //text_layer_set_text_alignment(text_layer, GTextAlignmentCenter);
+ layer_add_child(ui.layer, text_layer_get_layer(ui.textPlay));
+ layer_add_child(ui.layer, text_layer_get_layer(ui.textRules));
+
+ ui.pointer = gpath_create(&arrow);
+ gpath_move_to(ui.pointer, GPoint(55,40));
+ layer_add_child(window_layer, ui.layer);
+}
+
+static void window_unload(Window *window) {
+ text_layer_destroy(ui.textPlay);
+ text_layer_destroy(ui.textRules);
+ gpath_destroy(ui.pointer);
+ gbitmap_destroy(ui.background);
+}
+
+static void toggle_menu(void) {
+ if(choice==0) {
+ choice=1;
+ gpath_move_to(ui.pointer, GPoint(55,60));
+ } else {
+ choice=0;
+ gpath_move_to(ui.pointer, GPoint(55,40));
+ }
+ layer_mark_dirty(ui.layer);
+
+}
+static void select_click_handler(ClickRecognizerRef recognizer, void *context) {
+ if(combo[counter] == 1) {
+ gameover_init(false);
+ return;
+ }
+ if(choice==0) {
+ game_init();
+ } else {
+ rules_init();
+ }
+}
+
+static void up_click_handler(ClickRecognizerRef recognizer, void *context) {
+ if(combo[counter] == 0) counter++;
+ else counter = 0;
+ toggle_menu();
+}
+
+static void down_click_handler(ClickRecognizerRef recognizer, void *context) {
+ if(combo[counter] == 2) counter++;
+ else counter = 0;
+ toggle_menu();
+}
+
+static void click_config_provider(void *context) {
+ window_single_click_subscribe(BUTTON_ID_SELECT, select_click_handler);
+ window_single_click_subscribe(BUTTON_ID_UP, up_click_handler);
+ window_single_click_subscribe(BUTTON_ID_DOWN, down_click_handler);
+}
+
+void menu_init(void) {
+ ui.window = window_create();
+ window_set_fullscreen(ui.window, true);
+ window_set_click_config_provider(ui.window, click_config_provider);
+ window_set_window_handlers(ui.window, (WindowHandlers) {
+ .load = window_load,
+ .unload = window_unload,
+ });
+ window_stack_push(ui.window, true);
+}
+void menu_deinit(void) {
+ window_destroy(ui.window);
+}
\ No newline at end of file
diff --git a/src/menu.h b/src/menu.h
new file mode 100644
index 0000000..91caf95
--- /dev/null
+++ b/src/menu.h
@@ -0,0 +1,4 @@
+#pragma once
+
+void menu_init(void);
+void menu_deinit(void);
\ No newline at end of file
diff --git a/src/overlay.c b/src/overlay.c
new file mode 100644
index 0000000..738a5a9
--- /dev/null
+++ b/src/overlay.c
@@ -0,0 +1,48 @@
+#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
new file mode 100644
index 0000000..c0d21d0
--- /dev/null
+++ b/src/overlay.h
@@ -0,0 +1,12 @@
+#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
new file mode 100644
index 0000000..c49d455
--- /dev/null
+++ b/src/rules.c
@@ -0,0 +1,51 @@
+#include
+#include "rules.h"
+
+static struct {
+ Window *window;
+ ScrollLayer *layer;
+ TextLayer *textTitle;
+ TextLayer *textRules;
+} ui;
+
+static void window_load(Window *window) {
+ Layer *window_layer = window_get_root_layer(ui.window);
+ GRect bounds = layer_get_bounds(window_layer);
+ ui.layer = scroll_layer_create(bounds);
+
+ ui.textTitle = text_layer_create(GRect(0,0,144,35));
+ text_layer_set_text(ui.textTitle,"Rules");
+ text_layer_set_font(ui.textTitle,fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));
+ 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_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));
+
+ layer_add_child(window_layer,scroll_layer_get_layer(ui.layer));
+ scroll_layer_set_click_config_onto_window(ui.layer,ui.window);
+ scroll_layer_set_content_size(ui.layer,GSize(144,400));
+
+
+}
+
+static void window_unload(Window *window) {
+ scroll_layer_destroy(ui.layer);
+ text_layer_destroy(ui.textTitle);
+ text_layer_destroy(ui.textRules);
+}
+
+void rules_init(void) {
+ ui.window = window_create();
+ window_set_fullscreen(ui.window,true);
+ window_set_window_handlers(ui.window, (WindowHandlers) {
+ .load = window_load,
+ .unload = window_unload,
+ });
+ window_stack_push(ui.window, true);
+}
+void rules_deinit(void) {
+ window_destroy(ui.window);
+}
\ No newline at end of file
diff --git a/src/rules.h b/src/rules.h
new file mode 100644
index 0000000..5cea02c
--- /dev/null
+++ b/src/rules.h
@@ -0,0 +1,4 @@
+#pragma once
+
+void rules_init(void);
+void rules_deinit(void);
\ No newline at end of file
diff --git a/src/shutthebox.c b/src/shutthebox.c
new file mode 100644
index 0000000..d4442b8
--- /dev/null
+++ b/src/shutthebox.c
@@ -0,0 +1,14 @@
+#include
+#include "menu.h"
+
+static void init(void) {
+ menu_init();
+}
+static void deinit(void) {
+ menu_deinit();
+}
+int main(void) {
+ init();
+ app_event_loop();
+ deinit();
+}
\ No newline at end of file
diff --git a/wscript b/wscript
new file mode 100644
index 0000000..0554dc8
--- /dev/null
+++ b/wscript
@@ -0,0 +1,24 @@
+
+#
+# This file is the default set of rules to compile a Pebble project.
+#
+# Feel free to customize this to your needs.
+#
+
+top = '.'
+out = 'build'
+
+def options(ctx):
+ ctx.load('pebble_sdk')
+
+def configure(ctx):
+ ctx.load('pebble_sdk')
+
+def build(ctx):
+ ctx.load('pebble_sdk')
+
+ ctx.pbl_program(source=ctx.path.ant_glob('src/**/*.c'),
+ target='pebble-app.elf')
+
+ ctx.pbl_bundle(elf='pebble-app.elf',
+ js=ctx.path.ant_glob('src/js/**/*.js'))