Support for SDK2.0
Improved logic to test if the player has lost New victory screen
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
build
|
||||
.lock-waf_linux2_build
|
||||
32
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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
89
appinfo.json
Normal file
@@ -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"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
BIN
assets/header.png
Normal file
|
After Width: | Height: | Size: 195 KiB |
BIN
assets/header.xcf
Normal file
BIN
assets/icon144.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
assets/icon48.png
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
assets/screenshot-game.png
Normal file
|
After Width: | Height: | Size: 1.6 KiB |
BIN
assets/screenshot-menu.png
Normal file
|
After Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
BIN
resources/images/cityscape.png
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
|
Before Width: | Height: | Size: 970 B After Width: | Height: | Size: 970 B |
|
Before Width: | Height: | Size: 981 B After Width: | Height: | Size: 981 B |
|
Before Width: | Height: | Size: 988 B After Width: | Height: | Size: 988 B |
|
Before Width: | Height: | Size: 977 B After Width: | Height: | Size: 977 B |
|
Before Width: | Height: | Size: 989 B After Width: | Height: | Size: 989 B |
|
Before Width: | Height: | Size: 980 B After Width: | Height: | Size: 980 B |
BIN
resources/images/menu_bg.png
Normal file
|
After Width: | Height: | Size: 973 B |
|
Before Width: | Height: | Size: 159 B After Width: | Height: | Size: 159 B |
BIN
resources/images/moon.png
Normal file
|
After Width: | Height: | Size: 265 B |
|
Before Width: | Height: | Size: 232 B After Width: | Height: | Size: 232 B |
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 969 B After Width: | Height: | Size: 969 B |
@@ -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.
|
||||
|
Before Width: | Height: | Size: 939 B |
|
Before Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 141 B |
@@ -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"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -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")
|
||||
|
||||
|
||||
BIN
shutthebox.pbw
Normal file
616
src/ShutTheBox.c
@@ -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;i<target;i++) {
|
||||
if(tabs[i].open) {
|
||||
nLeft[h] = i+1;
|
||||
h++;
|
||||
}
|
||||
}
|
||||
//check individual numbers and combinations
|
||||
for(int i=0;i<h;i++) {
|
||||
if(nLeft[i] == target) return true;
|
||||
for(int j=0;j<h;j++) {
|
||||
if(nLeft[i]+nLeft[j] == target && nLeft[i]!=nLeft[j]) return true;
|
||||
for(int k=0;k<h;k++) {
|
||||
if(nLeft[i]!=nLeft[j] &&
|
||||
nLeft[i]!=nLeft[k] &&
|
||||
nLeft[j]!=nLeft[k] &&
|
||||
nLeft[i]+nLeft[j]+nLeft[k] == target) return true;
|
||||
for(int l=0;l<h;l++) {
|
||||
if(nLeft[i]!=nLeft[j] &&
|
||||
nLeft[i]!=nLeft[k] &&
|
||||
nLeft[i]!=nLeft[l] &&
|
||||
nLeft[j]!=nLeft[k] &&
|
||||
nLeft[j]!=nLeft[l] &&
|
||||
nLeft[k]!=nLeft[l] &&
|
||||
nLeft[i]+nLeft[j]+nLeft[k]+nLeft[l] == target) return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool is_legal(int x) {
|
||||
if(x>d1+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);
|
||||
}
|
||||
464
src/game.c
Normal file
@@ -0,0 +1,464 @@
|
||||
#include <pebble.h>
|
||||
#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;i<target;i++) {
|
||||
if(tabs[i].open) {
|
||||
nLeft[h] = i+1;
|
||||
h++;
|
||||
}
|
||||
}
|
||||
//check individual numbers and combinations
|
||||
for(int i=0;i<h;i++) {
|
||||
if(nLeft[i] == target) return true;
|
||||
for(int j=0;j<h;j++) {
|
||||
if(nLeft[i]+nLeft[j] == target && nLeft[i]!=nLeft[j]) return true;
|
||||
for(int k=0;k<h;k++) {
|
||||
if(nLeft[i]!=nLeft[j] &&
|
||||
nLeft[i]!=nLeft[k] &&
|
||||
nLeft[j]!=nLeft[k] &&
|
||||
nLeft[i]+nLeft[j]+nLeft[k] == target) return true;
|
||||
for(int l=0;l<h;l++) {
|
||||
if(nLeft[i]!=nLeft[j] &&
|
||||
nLeft[i]!=nLeft[k] &&
|
||||
nLeft[i]!=nLeft[l] &&
|
||||
nLeft[j]!=nLeft[k] &&
|
||||
nLeft[j]!=nLeft[l] &&
|
||||
nLeft[k]!=nLeft[l] &&
|
||||
nLeft[i]+nLeft[j]+nLeft[k]+nLeft[l] == target) return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool is_legal(int x) {
|
||||
if(x>d1+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(counter<d1+d2 && !move_possible()) {
|
||||
game_stage = 4;
|
||||
layer_mark_dirty(ui.dice);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static int total_left(void) {
|
||||
int total = 0;
|
||||
for(int i=0;i<9;i++) {
|
||||
if(tabs[i].open) {
|
||||
total+=i+1;
|
||||
}
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
static void roll_dice(int n) {
|
||||
d1=(rand()%5)+1;
|
||||
d2=0;
|
||||
if(n==2) d2=(rand()%5)+1;
|
||||
if(d1+d2<=total_left()) {
|
||||
game_stage=2;
|
||||
}
|
||||
}
|
||||
|
||||
void handle_second_tick(struct tm *tick_time, TimeUnits units_changed) {
|
||||
|
||||
}
|
||||
|
||||
static void box_update_callback(Layer *me, GContext* ctx) {
|
||||
graphics_draw_bitmap_in_rect(ctx, boxImgs.background, GRect(4,10,136,108));
|
||||
for(int i=0;i<9;i++) {
|
||||
int x,y;
|
||||
GBitmap *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 = boxImgs.tab_open_selected;
|
||||
} else {
|
||||
image = boxImgs.tab_open;
|
||||
}
|
||||
} else {
|
||||
image = boxImgs.tab_closed;
|
||||
}
|
||||
graphics_draw_bitmap_in_rect(ctx, image, GRect(x, y, 24, 44));
|
||||
}
|
||||
graphics_context_set_text_color(ctx, GColorBlack);
|
||||
if(tabs[0].open) {
|
||||
graphics_draw_text(ctx,
|
||||
"1",
|
||||
font_l,
|
||||
GRect(15, 15, 20, 30),
|
||||
GTextOverflowModeWordWrap,
|
||||
GTextAlignmentLeft,
|
||||
NULL);
|
||||
}
|
||||
if(tabs[1].open) {
|
||||
graphics_draw_text(ctx,
|
||||
"2",
|
||||
font_l,
|
||||
GRect(41, 15, 20, 30),
|
||||
GTextOverflowModeWordWrap,
|
||||
GTextAlignmentLeft,
|
||||
NULL);
|
||||
}
|
||||
if(tabs[2].open) {
|
||||
graphics_draw_text(ctx,
|
||||
"3",
|
||||
font_l,
|
||||
GRect(67, 16, 20, 30),
|
||||
GTextOverflowModeWordWrap,
|
||||
GTextAlignmentLeft,
|
||||
NULL);
|
||||
}
|
||||
if(tabs[3].open) {
|
||||
graphics_draw_text(ctx,
|
||||
"4",
|
||||
font_l,
|
||||
GRect(93, 15, 20, 30),
|
||||
GTextOverflowModeWordWrap,
|
||||
GTextAlignmentLeft,
|
||||
NULL);
|
||||
}
|
||||
if(tabs[4].open) {
|
||||
graphics_draw_text(ctx,
|
||||
"5",
|
||||
font_l,
|
||||
GRect(119, 15, 20, 30),
|
||||
GTextOverflowModeWordWrap,
|
||||
GTextAlignmentLeft,
|
||||
NULL);
|
||||
}
|
||||
if(tabs[5].open) {
|
||||
graphics_draw_text(ctx,
|
||||
"6",
|
||||
font_l,
|
||||
GRect(19, 71, 20, 30),
|
||||
GTextOverflowModeWordWrap,
|
||||
GTextAlignmentLeft,
|
||||
NULL);
|
||||
}
|
||||
if(tabs[6].open) {
|
||||
graphics_draw_text(ctx,
|
||||
"7",
|
||||
font_l,
|
||||
GRect(51, 71, 20, 30),
|
||||
GTextOverflowModeWordWrap,
|
||||
GTextAlignmentLeft,
|
||||
NULL);
|
||||
}
|
||||
if(tabs[7].open) {
|
||||
graphics_draw_text(ctx,
|
||||
"8",
|
||||
font_l,
|
||||
GRect(83, 71, 20, 30),
|
||||
GTextOverflowModeWordWrap,
|
||||
GTextAlignmentLeft,
|
||||
NULL);
|
||||
}
|
||||
if(tabs[8].open) {
|
||||
graphics_draw_text(ctx,
|
||||
"9",
|
||||
font_l,
|
||||
GRect(115, 71, 20, 30),
|
||||
GTextOverflowModeWordWrap,
|
||||
GTextAlignmentLeft,
|
||||
NULL);
|
||||
}
|
||||
}
|
||||
static void dice_update_callback(Layer *me, GContext* ctx) {
|
||||
graphics_context_set_text_color(ctx, GColorBlack);
|
||||
if(game_stage == 1) {
|
||||
graphics_draw_text(ctx,
|
||||
"Roll Dice",
|
||||
font_l,
|
||||
GRect(30, 0, 100, 29),
|
||||
GTextOverflowModeWordWrap,
|
||||
GTextAlignmentLeft,
|
||||
NULL);
|
||||
} 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));
|
||||
if(d2!=0) {
|
||||
graphics_draw_bitmap_in_rect(ctx, diceImgs[d2-1], GRect(90, y, 24, 24));
|
||||
}
|
||||
if(game_stage == 4) {
|
||||
graphics_draw_text(ctx,
|
||||
"GAME OVER",
|
||||
font_l,
|
||||
GRect(20, 18, 120, 30),
|
||||
GTextOverflowModeWordWrap,
|
||||
GTextAlignmentLeft,
|
||||
NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void overlay_update_callback(Layer *me, GContext* ctx) {
|
||||
graphics_context_set_fill_color(ctx, GColorBlack);
|
||||
graphics_fill_rect(ctx,
|
||||
GRect(0,0,114,80),
|
||||
8,
|
||||
GCornersAll);
|
||||
graphics_context_set_fill_color(ctx, GColorWhite);
|
||||
graphics_fill_rect(ctx,
|
||||
GRect(3,3,108,74),
|
||||
8,
|
||||
GCornersAll);
|
||||
graphics_context_set_text_color(ctx, GColorBlack);
|
||||
graphics_draw_text(ctx,
|
||||
"How many dice?",
|
||||
font_s,
|
||||
GRect(0, 0, 114, 25),
|
||||
GTextOverflowModeWordWrap,
|
||||
GTextAlignmentCenter,
|
||||
NULL);
|
||||
graphics_draw_text(ctx,
|
||||
"1 Die",
|
||||
font_s,
|
||||
GRect(30, 25, 70, 25),
|
||||
GTextOverflowModeWordWrap,
|
||||
GTextAlignmentLeft,
|
||||
NULL);
|
||||
graphics_draw_text(ctx,
|
||||
"2 Dice",
|
||||
font_s,
|
||||
GRect(30, 50, 70, 25),
|
||||
GTextOverflowModeWordWrap,
|
||||
GTextAlignmentLeft,
|
||||
NULL);
|
||||
graphics_context_set_fill_color(ctx, GColorBlack);
|
||||
gpath_draw_filled(ctx, ui.pointer);
|
||||
}
|
||||
|
||||
static void click_up(ClickRecognizerRef recognizer, void *context) {
|
||||
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(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);
|
||||
}
|
||||
4
src/game.h
Normal file
@@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
void game_init(void);
|
||||
void game_deinit(void);
|
||||
204
src/gameover.c
Normal file
@@ -0,0 +1,204 @@
|
||||
#include <pebble.h>
|
||||
|
||||
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;c<particles;c++) {
|
||||
if(d>360) 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;c<particles;c++) {
|
||||
if(duration>points[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<particles;c++) {
|
||||
for(int i=0;i<2;i++) {
|
||||
for(int j=0;j<2;j++) {
|
||||
GPoint point = GPoint(points[c].pos.x+i, points[c].pos.y+j);
|
||||
graphics_draw_pixel(ctx, point);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void text_update_callback(Layer *me, GContext* ctx) {
|
||||
graphics_context_set_text_color(ctx, GColorWhite);
|
||||
graphics_draw_text(ctx,
|
||||
wintext,
|
||||
font_l,
|
||||
GRect(0, 0, 144, 29),
|
||||
GTextOverflowModeWordWrap,
|
||||
GTextAlignmentCenter,
|
||||
NULL);
|
||||
}
|
||||
|
||||
|
||||
static void window_load(Window *window) {
|
||||
light_enable(true);
|
||||
Layer *window_layer = window_get_root_layer(ui.window);
|
||||
font_l = fonts_get_system_font(FONT_KEY_GOTHIC_28);
|
||||
images.cityscape = gbitmap_create_with_resource(RESOURCE_ID_CITYSCAPE);
|
||||
images.moon = gbitmap_create_with_resource(RESOURCE_ID_MOON);
|
||||
ui.cityscape = layer_create((GRect){
|
||||
.origin = { 0, 90 },
|
||||
.size = { 250, 78 }
|
||||
});
|
||||
ui.moon = layer_create((GRect){
|
||||
.origin = { 120, 10 },
|
||||
.size = { 32, 33 }
|
||||
});
|
||||
ui.anim = layer_create((GRect){
|
||||
.origin = { 0, 0 },
|
||||
.size = { 144, 168 }
|
||||
});
|
||||
ui.text = layer_create((GRect){
|
||||
.origin = { 0, 45 },
|
||||
.size = { 144, 30 }
|
||||
});
|
||||
layer_set_update_proc(ui.cityscape, cityscape_update_callback);
|
||||
layer_set_update_proc(ui.moon, moon_update_callback);
|
||||
layer_set_update_proc(ui.anim, anim_update_callback);
|
||||
layer_set_update_proc(ui.text, text_update_callback);
|
||||
layer_add_child(window_layer, ui.moon);
|
||||
layer_add_child(window_layer, ui.cityscape);
|
||||
layer_add_child(window_layer, ui.anim);
|
||||
layer_add_child(window_layer, ui.text);
|
||||
|
||||
GRect from_rect = GRect(120, 10, 32, 33);
|
||||
GRect to_rect = GRect(100, 10, 32, 33);
|
||||
moon_animation = property_animation_create_layer_frame(ui.moon, &from_rect, &to_rect);
|
||||
animation_set_duration((Animation*) moon_animation, 5000);
|
||||
animation_set_delay((Animation*) moon_animation, 1000);
|
||||
animation_schedule((Animation*) moon_animation);
|
||||
|
||||
from_rect = GRect(0, 90, 250, 78);
|
||||
to_rect = GRect(-50, 90, 250, 78);
|
||||
cityscape_animation = property_animation_create_layer_frame(ui.cityscape, &from_rect, &to_rect);
|
||||
animation_set_duration((Animation*) cityscape_animation, 5000);
|
||||
animation_set_delay((Animation*) cityscape_animation, 1000);
|
||||
animation_schedule((Animation*) cityscape_animation);
|
||||
|
||||
from_rect = GRect(0, 45, 144, 30);
|
||||
to_rect = GRect(-144, 45, 144, 30);
|
||||
text_animation = property_animation_create_layer_frame(ui.text, &from_rect, &to_rect);
|
||||
animation_set_duration((Animation*) text_animation, 4000);
|
||||
animation_set_delay((Animation*) text_animation, 1000);
|
||||
animation_schedule((Animation*) text_animation);
|
||||
|
||||
}
|
||||
static void window_unload(Window *window) {
|
||||
app_timer_cancel(timer);
|
||||
light_enable(false);
|
||||
gbitmap_destroy(images.cityscape);
|
||||
gbitmap_destroy(images.moon);
|
||||
}
|
||||
void gameover_init(bool legit) {
|
||||
if(legit) snprintf(wintext, 12, "You win!");
|
||||
else snprintf(wintext, 12, "You Cheat!");
|
||||
ui.window = window_create();
|
||||
window_set_fullscreen(ui.window, true);
|
||||
window_set_background_color(ui.window, GColorBlack);
|
||||
window_set_window_handlers(ui.window, (WindowHandlers) {
|
||||
.load = window_load,
|
||||
.unload = window_unload
|
||||
});
|
||||
window_stack_push(ui.window, true);
|
||||
const uint32_t timeout_ms = 50;
|
||||
timer = app_timer_register(timeout_ms, timer_callback, NULL);
|
||||
}
|
||||
void gameover_deinit(void) {
|
||||
window_destroy(ui.window);
|
||||
}
|
||||
4
src/gameover.h
Normal file
@@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
void gameover_init(bool legit);
|
||||
void gameover_deinit(void);
|
||||
112
src/menu.c
Normal file
@@ -0,0 +1,112 @@
|
||||
#include <pebble.h>
|
||||
#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);
|
||||
}
|
||||
4
src/menu.h
Normal file
@@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
void menu_init(void);
|
||||
void menu_deinit(void);
|
||||
48
src/overlay.c
Normal file
@@ -0,0 +1,48 @@
|
||||
#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();
|
||||
}
|
||||
12
src/overlay.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#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));
|
||||
51
src/rules.c
Normal file
@@ -0,0 +1,51 @@
|
||||
#include <pebble.h>
|
||||
#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);
|
||||
}
|
||||
4
src/rules.h
Normal file
@@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
void rules_init(void);
|
||||
void rules_deinit(void);
|
||||
14
src/shutthebox.c
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <pebble.h>
|
||||
#include "menu.h"
|
||||
|
||||
static void init(void) {
|
||||
menu_init();
|
||||
}
|
||||
static void deinit(void) {
|
||||
menu_deinit();
|
||||
}
|
||||
int main(void) {
|
||||
init();
|
||||
app_event_loop();
|
||||
deinit();
|
||||
}
|
||||
24
wscript
Normal file
@@ -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'))
|
||||