summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Dilly <bdilly@profusion.mobi>2012-09-03 23:18:07 +0000
committerBruno Dilly <bdilly@profusion.mobi>2012-09-03 23:18:07 +0000
commit8cf88615ee8bdf7961f1091449b42ab33bf6caf2 (patch)
treeeaa5f5bab7d4b2015247ff4a7b4b7df03bf70d86
parent0d3ffcc35e92aea4703457abfcea1c52a8892fea (diff)
Econcentration: store hi-scores
SVN revision: 76088
-rw-r--r--configure.ac1
-rw-r--r--src/bin/Makefile.am9
-rw-r--r--src/bin/main.c76
3 files changed, 73 insertions, 13 deletions
diff --git a/configure.ac b/configure.ac
index 1ebc1de..ccf15df 100644
--- a/configure.ac
+++ b/configure.ac
@@ -62,6 +62,7 @@ AC_FUNC_ALLOCA
62AC_C___ATTRIBUTE__ 62AC_C___ATTRIBUTE__
63 63
64PKG_CHECK_MODULES([ELEMENTARY], [elementary evas ecore]) 64PKG_CHECK_MODULES([ELEMENTARY], [elementary evas ecore])
65PKG_CHECK_MODULES([ETROPHY], [etrophy])
65 66
66want_quicklaunch="auto" 67want_quicklaunch="auto"
67AC_ARG_ENABLE([quicklaunch], 68AC_ARG_ENABLE([quicklaunch],
diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am
index 0619030..c30f3e0 100644
--- a/src/bin/Makefile.am
+++ b/src/bin/Makefile.am
@@ -4,14 +4,15 @@ INCLUDES = \
4-I$(top_srcdir) \ 4-I$(top_srcdir) \
5-I$(top_srcdir)/src/bin \ 5-I$(top_srcdir)/src/bin \
6-DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \ 6-DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \
7@ELEMENTARY_CFLAGS@ 7@ELEMENTARY_CFLAGS@ \
8@ETROPHY_CFLAGS@
8 9
9bin_PROGRAMS = econcentration 10bin_PROGRAMS = econcentration
10if BUILD_QUICKLAUNCH 11if BUILD_QUICKLAUNCH
11bin_PROGRAMS += econcentration_ql 12bin_PROGRAMS += econcentration_ql
12endif 13endif
13 14
14econcentration_LDADD = @ELEMENTARY_LIBS@ 15econcentration_LDADD = @ELEMENTARY_LIBS@ @ETROPHY_LIBS@
15econcentration_SOURCES = main.c 16econcentration_SOURCES = main.c
16 17
17if BUILD_QUICKLAUNCH 18if BUILD_QUICKLAUNCH
@@ -24,11 +25,11 @@ if BUILD_QUICKLAUNCH
24econcentration_qldir = $(quicklauncher_libdir) 25econcentration_qldir = $(quicklauncher_libdir)
25econcentration_ql_LTLIBRARIES = econcentration_ql.la 26econcentration_ql_LTLIBRARIES = econcentration_ql.la
26econcentration_ql_la_SOURCES = main.c 27econcentration_ql_la_SOURCES = main.c
27econcentration_ql_la_LIBADD = @ELEMENTARY_LIBS@ 28econcentration_ql_la_LIBADD = @ELEMENTARY_LIBS@ @ETROPHY_LIBS@
28econcentration_ql_la_CFLAGS = 29econcentration_ql_la_CFLAGS =
29econcentration_ql_la_LDFLAGS = -module -avoid-version -no-undefined 30econcentration_ql_la_LDFLAGS = -module -avoid-version -no-undefined
30econcentration_ql_SOURCES = main.c 31econcentration_ql_SOURCES = main.c
31econcentration_ql_LDADD = @ELEMENTARY_LIBS@ 32econcentration_ql_LDADD = @ELEMENTARY_LIBS@ @ETROPHY_LIBS@
32econcentration_ql_CFLAGS = -DELM_LIB_QUICKLAUNCH=1 33econcentration_ql_CFLAGS = -DELM_LIB_QUICKLAUNCH=1
33econcentration_ql_LDFLAGS = 34econcentration_ql_LDFLAGS =
34endif 35endif
diff --git a/src/bin/main.c b/src/bin/main.c
index a3d5228..e1ffb89 100644
--- a/src/bin/main.c
+++ b/src/bin/main.c
@@ -4,6 +4,7 @@
4#include <Elementary.h> 4#include <Elementary.h>
5#include <Edje.h> 5#include <Edje.h>
6#include <Eina.h> 6#include <Eina.h>
7#include <Etrophy.h>
7#include <Evas.h> 8#include <Evas.h>
8#ifndef ELM_LIB_QUICKLAUNCH 9#ifndef ELM_LIB_QUICKLAUNCH
9 10
@@ -15,6 +16,9 @@
15 16
16#define HELP_STRING "To play this game in a mobile version use econcentration" \ 17#define HELP_STRING "To play this game in a mobile version use econcentration" \
17 " --mobile" 18 " --mobile"
19
20static const char *BOARD_SIZE[] = {"Small", "Normal", "Big"};
21
18typedef struct _Card 22typedef struct _Card
19{ 23{
20 int value; 24 int value;
@@ -26,8 +30,10 @@ typedef struct _Game
26 int play_time, attempts, found, board_size, prev_board_size, total_size; 30 int play_time, attempts, found, board_size, prev_board_size, total_size;
27 Card cards[BOARD_SIZE_MAX]; 31 Card cards[BOARD_SIZE_MAX];
28 Card *first_card, *second_card; 32 Card *first_card, *second_card;
29 Evas_Object *time_lb, *attempts_lb, *found_lb, *won_lb, *inwin, *table; 33 Evas_Object *time_lb, *best_time_lb, *attempts_lb, *found_lb, *won_lb;
34 Evas_Object *inwin, *table, *sp;
30 Ecore_Timer *play_timer, *show_timer, *dl_pop; 35 Ecore_Timer *play_timer, *show_timer, *dl_pop;
36 Etrophy_Gamescore *gamescore;
31 Eina_Bool running:1; 37 Eina_Bool running:1;
32 /* Are we running in a mobile device? */ 38 /* Are we running in a mobile device? */
33 Eina_Bool econcentration_mobile; 39 Eina_Bool econcentration_mobile;
@@ -37,8 +43,14 @@ static void
37_board_size_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__) 43_board_size_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
38{ 44{
39 Game *game = data; 45 Game *game = data;
46 char buf[16];
40 game->board_size = elm_spinner_value_get(obj) * 2 + 2; 47 game->board_size = elm_spinner_value_get(obj) * 2 + 2;
41 game->total_size = game->board_size * game->board_size; 48 game->total_size = game->board_size * game->board_size;
49 snprintf(buf, sizeof(buf), "%i s",
50 etrophy_gamescore_level_low_score_get(
51 game->gamescore,
52 BOARD_SIZE[(int)elm_spinner_value_get(obj) - 1]));
53 elm_object_text_set(game->best_time_lb, buf);
42} 54}
43 55
44static Eina_Bool 56static Eina_Bool
@@ -96,11 +108,23 @@ _player_win(Game *game)
96 "ZzzzZz. You won.<br>But you can do better.<br>"); 108 "ZzzzZz. You won.<br>But you can do better.<br>");
97 } 109 }
98 else 110 else
99 snprintf(buf, sizeof(buf), 111 {
100 "Congratulations, you solved it!<br>" 112 etrophy_gamescore_level_score_add(
101 "You spent %i seconds and<br>" 113 game->gamescore,
102 "made %i attempts.", 114 BOARD_SIZE[(int)elm_spinner_value_get(game->sp) - 1],
103 game->play_time, game->attempts); 115 NULL, game->play_time, 0);
116 snprintf(buf, sizeof(buf), "%i s",
117 etrophy_gamescore_level_low_score_get(
118 game->gamescore,
119 BOARD_SIZE[(int)elm_spinner_value_get(game->sp) - 1]));
120 elm_object_text_set(game->best_time_lb, buf);
121
122 snprintf(buf, sizeof(buf),
123 "Congratulations, you solved it!<br>"
124 "You spent %i seconds and<br>"
125 "made %i attempts.",
126 game->play_time, game->attempts);
127 }
104 128
105 elm_object_text_set(game->won_lb, buf); 129 elm_object_text_set(game->won_lb, buf);
106} 130}
@@ -453,6 +477,7 @@ static Eina_Bool
453_create_window_desktop(Game *game) 477_create_window_desktop(Game *game)
454{ 478{
455 Evas_Object *win, *inwin, *bg, *bx, *bxctl, *table, *bt, *sp, *fr, *lb; 479 Evas_Object *win, *inwin, *bg, *bx, *bxctl, *table, *bt, *sp, *fr, *lb;
480 char buf[16];
456 481
457 win = elm_win_add(NULL, PACKAGE_NAME, ELM_WIN_BASIC); 482 win = elm_win_add(NULL, PACKAGE_NAME, ELM_WIN_BASIC);
458 if (!win) return EINA_FALSE; 483 if (!win) return EINA_FALSE;
@@ -508,13 +533,14 @@ _create_window_desktop(Game *game)
508 elm_spinner_min_max_set(sp, 1, 3); 533 elm_spinner_min_max_set(sp, 1, 3);
509 elm_spinner_step_set(sp, 1.0); 534 elm_spinner_step_set(sp, 1.0);
510 elm_spinner_editable_set(sp, EINA_FALSE); 535 elm_spinner_editable_set(sp, EINA_FALSE);
511 elm_spinner_special_value_add(sp, 1, "Small"); 536 elm_spinner_special_value_add(sp, 1, BOARD_SIZE[0]);
512 elm_spinner_special_value_add(sp, 2, "Normal"); 537 elm_spinner_special_value_add(sp, 2, BOARD_SIZE[1]);
513 elm_spinner_special_value_add(sp, 3, "Big"); 538 elm_spinner_special_value_add(sp, 3, BOARD_SIZE[2]);
514 evas_object_smart_callback_add(sp, "changed", _board_size_cb, game); 539 evas_object_smart_callback_add(sp, "changed", _board_size_cb, game);
515 evas_object_size_hint_align_set(sp, EVAS_HINT_FILL, 0); 540 evas_object_size_hint_align_set(sp, EVAS_HINT_FILL, 0);
516 elm_object_content_set(fr, sp); 541 elm_object_content_set(fr, sp);
517 evas_object_show(sp); 542 evas_object_show(sp);
543 game->sp = sp;
518 544
519 fr = elm_frame_add(win); 545 fr = elm_frame_add(win);
520 evas_object_size_hint_weight_set(fr, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); 546 evas_object_size_hint_weight_set(fr, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
@@ -558,6 +584,24 @@ _create_window_desktop(Game *game)
558 elm_object_content_set(fr, lb); 584 elm_object_content_set(fr, lb);
559 evas_object_show(lb); 585 evas_object_show(lb);
560 586
587 fr = elm_frame_add(win);
588 evas_object_size_hint_weight_set(fr, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
589 evas_object_size_hint_align_set(fr, EVAS_HINT_FILL, EVAS_HINT_FILL);
590 elm_object_text_set(fr, "Best Time:");
591 elm_box_pack_end(bxctl, fr);
592 evas_object_show(fr);
593
594 lb = elm_label_add(win);
595 snprintf(buf, sizeof(buf), "%i s",
596 etrophy_gamescore_level_low_score_get(game->gamescore,
597 BOARD_SIZE[0]));
598 elm_object_text_set(lb, buf);
599 evas_object_size_hint_weight_set(lb, 0.0, 0.0);
600 evas_object_size_hint_align_set(lb, 1, 0.5);
601 elm_object_content_set(fr, lb);
602 evas_object_show(lb);
603 game->best_time_lb = lb;
604
561 game->inwin = inwin = elm_win_inwin_add(win); 605 game->inwin = inwin = elm_win_inwin_add(win);
562 elm_object_style_set(inwin, "minimal"); 606 elm_object_style_set(inwin, "minimal");
563 607
@@ -626,6 +670,16 @@ elm_main(int argc, char **argv)
626 if (argc > 1) 670 if (argc > 1)
627 checkArguments(argv, &game); 671 checkArguments(argv, &game);
628 672
673 etrophy_init();
674 game.gamescore = etrophy_gamescore_load("econcentration");
675 if (!game.gamescore)
676 game.gamescore = etrophy_gamescore_new();
677 if (!game.gamescore)
678 {
679 r = -1;
680 goto no_score;
681 }
682
629 if(!_win_new(&game)) 683 if(!_win_new(&game))
630 { 684 {
631 r = -1; 685 r = -1;
@@ -634,7 +688,11 @@ elm_main(int argc, char **argv)
634 688
635 elm_run(); 689 elm_run();
636 690
691 etrophy_gamescore_save(game.gamescore, "econcentration");
692
637end: 693end:
694 etrophy_shutdown();
695no_score:
638 elm_shutdown(); 696 elm_shutdown();
639 return r; 697 return r;
640} 698}