[aisleriot] sol: Move score keeping to the guile side
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [aisleriot] sol: Move score keeping to the guile side
- Date: Sat, 3 Dec 2011 21:54:24 +0000 (UTC)
commit 1c0add493717c7fe839ab9e7cd383d20032ea4ce
Author: Christian Persch <chpe gnome org>
Date: Sat Dec 3 22:19:25 2011 +0100
sol: Move score keeping to the guile side
https://bugzilla.gnome.org/show_bug.cgi?id=556359
games/api.scm | 16 +++++++++++++++-
src/game.c | 48 ++++++++++--------------------------------------
2 files changed, 25 insertions(+), 39 deletions(-)
---
diff --git a/games/api.scm b/games/api.scm
index 787d090..b033e1c 100644
--- a/games/api.scm
+++ b/games/api.scm
@@ -77,7 +77,8 @@
(set! TOP-SLOTS '())
(set! BOTTOM-SLOTS '())
(set! LEFT-SLOTS '())
- (set! RIGHT-SLOTS '()))
+ (set! RIGHT-SLOTS '())
+ (set! SCORE 0))
; Use this instead of define for variables which determine the state of
; the game. i.e. anything that isn't a constant. This is so undo/redo
@@ -619,6 +620,18 @@
(define-public (register-undo-function function data)
(set! MOVE (cons '(function data) (cdr MOVE))))
+; set score
+(define-public (set-score! value)
+ (begin
+ (set! SCORE value)
+ (update-score SCORE)))
+
+(define-public (get-score)
+ SCORE)
+
+(define-public (add-to-score! delta)
+ (set-score! (+ (get-score) delta)))
+
;; INTERNAL procedures
; global variables
@@ -638,6 +651,7 @@
(define-public BOTTOM-SLOTS '())
(define-public LEFT-SLOTS '())
(define-public RIGHT-SLOTS '())
+(define-public SCORE 0)
; called from C:
(define-public (start-game)
diff --git a/src/game.c b/src/game.c
index 9eac26c..a9c49d2 100644
--- a/src/game.c
+++ b/src/game.c
@@ -185,17 +185,6 @@ set_game_state (AisleriotGame *game,
}
static void
-set_game_score (AisleriotGame *game,
- int score)
-{
- if (score != game->score) {
- game->score = score;
-
- g_object_notify (G_OBJECT (game), "score");
- }
-}
-
-static void
set_game_undoable (AisleriotGame *game,
gboolean enabled)
{
@@ -993,34 +982,22 @@ scm_click_to_move_p (void)
}
static SCM
-scm_get_score (void)
+scm_update_score (SCM new_score)
{
AisleriotGame *game = app_game;
+ int score;
- return scm_from_int (game->score);
-}
+ score = scm_to_int (new_score);
+ if (score != game->score) {
+ game->score = score;
-static SCM
-scm_set_score (SCM new_score)
-{
- AisleriotGame *game = app_game;
+ g_object_notify (G_OBJECT (game), "score");
+ }
- set_game_score (game, scm_to_int (new_score));
return new_score;
}
static SCM
-scm_add_to_score (SCM delta)
-{
- AisleriotGame *game = app_game;
- int new_score;
-
- new_score = game->score + scm_to_int (delta);
- set_game_score (game, new_score);
- return scm_from_int (new_score);
-}
-
-static SCM
scm_set_timeout (SCM new)
{
AisleriotGame *game = app_game;
@@ -1116,12 +1093,10 @@ cscm_init (void *data G_GNUC_UNUSED)
scm_c_define_gsubr ("set-lambda!", 2, 0, 0, scm_set_lambda_x);
scm_c_define_gsubr ("aisleriot-random", 1, 0, 0, scm_myrandom);
scm_c_define_gsubr ("click-to-move?", 0, 0, 0, scm_click_to_move_p);
- scm_c_define_gsubr ("get-score", 0, 0, 0, scm_get_score);
- scm_c_define_gsubr ("set-score!", 1, 0, 0, scm_set_score);
+ scm_c_define_gsubr ("update-score", 1, 0, 0, scm_update_score);
scm_c_define_gsubr ("get-timeout", 0, 0, 0, scm_get_timeout);
scm_c_define_gsubr ("set-timeout!", 1, 0, 0, scm_set_timeout);
scm_c_define_gsubr ("delayed-call", 1, 0, 0, scm_delayed_call);
- scm_c_define_gsubr ("add-to-score!", 1, 0, 0, scm_add_to_score);
scm_c_define_gsubr ("_", 1, 0, 0, scm_gettext);
scm_c_define_gsubr ("undo-set-sensitive", 1, 0, 0, scm_undo_set_sensitive);
scm_c_define_gsubr ("redo-set-sensitive", 1, 0, 0, scm_redo_set_sensitive);
@@ -1140,12 +1115,10 @@ cscm_init (void *data G_GNUC_UNUSED)
"set-lambda!",
"aisleriot-random",
"click-to-move?",
- "get-score",
- "set-score!",
+ "update-score",
"get-timeout",
"set-timeout!",
"delayed-call",
- "add-to-score!",
"_",
"undo-set-sensitive",
"redo-set-sensitive",
@@ -1205,6 +1178,7 @@ aisleriot_game_init (AisleriotGame *game)
game->timer = g_timer_new ();
game->timeout = 60 * 60;
+ game->score = 0;
}
static GObject *
@@ -1786,7 +1760,6 @@ aisleriot_game_load_game (AisleriotGame *game,
clear_delayed_call (game);
set_game_state (game, GAME_UNINITIALISED);
- set_game_score (game, 0);
set_game_undoable (game, FALSE);
set_game_redoable (game, FALSE);
set_game_dealable (game, FALSE);
@@ -1918,7 +1891,6 @@ aisleriot_game_new_game_internal (AisleriotGame *game,
clear_delayed_call (game);
/* The game isn't actually in progress until the user makes a move */
set_game_state (game, GAME_BEGIN);
- set_game_score (game, 0);
set_game_undoable (game, FALSE);
set_game_redoable (game, FALSE);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]