This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository elimine.

View the commit online.

commit 141ced2c7396fc9fe36dd6af5d76ec1f2c45b40a
Author: Vincent Torri <vto...@outlook.fr>
AuthorDate: Tue Jul 15 13:45:02 2025 +0200

    add timer
---
 src/bin/elimine.c | 34 ++++++++++++++++++++++++++++++----
 src/bin/elimine.h |  2 ++
 2 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/src/bin/elimine.c b/src/bin/elimine.c
index 966c9e6..587407e 100644
--- a/src/bin/elimine.c
+++ b/src/bin/elimine.c
@@ -176,6 +176,8 @@ void ctx_del(Ctx *ctx)
     if (!ctx)
         return;
 
+    ecore_timer_del(ctx->timer);
+    ctx->timer = NULL;
     free(ctx->known);
     free(ctx->state);
     eina_array_free(ctx->tiles);
@@ -228,6 +230,25 @@ static void uncover(Ctx *ctx, int l, int c)
     }
 }
 
+static Eina_Bool
+_cb_time(void *ctx_)
+{
+    Ctx *ctx;
+
+    ctx = (Ctx *)ctx_;
+    ctx->time_count++;
+    if (ctx->time_count > 999)
+    {
+        ecore_timer_del(ctx->timer);
+        ctx->timer = NULL;
+        return ECORE_CALLBACK_CANCEL;
+    }
+
+    score_set(ctx->time, ctx->time_count);
+
+    return ECORE_CALLBACK_RENEW;
+}
+
 static void
 _cb_mouse_up(void *ctx_, Evas *evas EINA_UNUSED, Evas_Object *obj, void *event_info)
 {
@@ -279,6 +300,12 @@ _cb_mouse_up(void *ctx_, Evas *evas EINA_UNUSED, Evas_Object *obj, void *event_i
         {
             int y;
 
+            ecore_timer_del(ctx->timer);
+            ctx->timer = NULL;
+            ctx->finished = EINA_TRUE;
+            evas_object_image_data_set(ctx->smiley, smiley_bmp_get(SMILEY_LOST));
+            evas_object_image_pixels_dirty_set(ctx->smiley, EINA_TRUE);
+
             for (y = 0; y < ctx->nl; y++)
             {
                 int x;
@@ -308,10 +335,6 @@ _cb_mouse_up(void *ctx_, Evas *evas EINA_UNUSED, Evas_Object *obj, void *event_i
                     }
                 }
             }
-
-            ctx->finished = EINA_TRUE;
-            evas_object_image_data_set(ctx->smiley, smiley_bmp_get(SMILEY_LOST));
-            evas_object_image_pixels_dirty_set(ctx->smiley, EINA_TRUE);
         }
         else if (ctx->state[lookup(l, c)] == TILE_NOTHING)
         {
@@ -336,6 +359,9 @@ _cb_mouse_down(void *ctx_, Evas *evas EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
 
     ctx = (Ctx *)ctx_;
 
+    if (!ctx->timer)
+        ctx->timer = ecore_timer_add(1.0, _cb_time, ctx);
+
     evas_object_image_data_set(ctx->smiley, smiley_bmp_get(SMILEY_SURPRISED));
     evas_object_image_pixels_dirty_set(ctx->smiley, EINA_TRUE);
     int x, y, w, h;
diff --git a/src/bin/elimine.h b/src/bin/elimine.h
index 5f58219..2e42bfb 100644
--- a/src/bin/elimine.h
+++ b/src/bin/elimine.h
@@ -13,12 +13,14 @@ typedef struct
     Evas_Object *smiley;
     Evas_Object *grd;
     Eina_Array *tiles;
+    Ecore_Timer *timer;
 
     int *state;
     int *known;
     int nl; /* number of lines of the board */
     int nc; /* number of columns of the board */
     int nm; /* number of remaining mines in the board based on flagged tiles */
+    int time_count; /* time spent in game, <= 999 */
     int pixel_sz; /* size in pixels of a tile */
 
     Eina_Bool finished;

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to