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 57f28094493f20950095f12aac51692225f4b662
Author: Vincent Torri <vto...@outlook.fr>
AuthorDate: Fri Jul 11 10:32:03 2025 +0200
add remaining mines based on flagged tiles
---
src/bin/elimine.c | 37 ++++----
src/bin/elimine.h | 27 ++++++
src/bin/meson.build | 2 +-
src/bin/score.c | 261 ++++++++++++++++++++++++++++++++++++++++++++++++++++
src/bin/score.h | 12 +++
5 files changed, 319 insertions(+), 20 deletions(-)
diff --git a/src/bin/elimine.c b/src/bin/elimine.c
index 2744d85..2bee80e 100644
--- a/src/bin/elimine.c
+++ b/src/bin/elimine.c
@@ -10,6 +10,7 @@
#include <Elementary.h>
#include "icon.h"
+#include "score.h"
#define lookup(l, c) (l) * ctx->nc + (c)
@@ -30,8 +31,8 @@ typedef enum
typedef struct
{
- Evas *evas;
Evas_Object *grd;
+ Evas_Object *remain; /* nbr of remaing bombs */
Evas_Object *smiley;
Eina_List *tiles;
@@ -39,9 +40,8 @@ typedef struct
int *known;
int nl; /* number of lines of the board */
int nc; /* number of columns of the board */
- int nm; /* number of mines in the board */
+ int nm; /* number of remaining mines in the board based on flagged tiles */
int pixel_sz; /* size in pixels of a tile */
- int flagged; /* number of tile with a flag */
Eina_Bool finished;
} Ctx;
@@ -271,12 +271,15 @@ _cb_mouse_up(void *ctx_, Evas *evas EINA_UNUSED, Evas_Object *obj, void *event_i
{
ctx->known[lookup(l, c)] = TILE_FLAG;
TILE(TILE_FLAG, l, c);
- ctx->flagged++;
+ ctx->nm--;
+ score_set(ctx->remain, ctx->nm);
}
else if (ctx->known[lookup(l, c)] == TILE_FLAG)
{
ctx->known[lookup(l, c)] = TILE_UNKNOWN;
TILE(TILE_UNKNOWN, l, c);
+ ctx->nm++;
+ score_set(ctx->remain, ctx->nm);
}
return;
@@ -375,7 +378,7 @@ elm_main(int argc, char **argv)
int win_h;
int l;
- ctx = ctx_new(HARD, 3);
+ ctx = ctx_new(BEGINNER, 3);
if (!ctx)
return 1;
@@ -385,6 +388,7 @@ elm_main(int argc, char **argv)
win = elm_win_add(NULL, "Elimine", ELM_WIN_BASIC);
elm_win_title_set(win, "Elimine");
elm_win_autodel_set(win, EINA_TRUE);
+ evas_object_data_set(win, "ctx", ctx);
/* background */
@@ -411,20 +415,15 @@ elm_main(int argc, char **argv)
evas_object_show(o);
hbox = o;
- o = evas_object_image_filled_add(evas_object_evas_get(win));
- int icon_w;
- int icon_h;
- cipher_size_get(&icon_w, &icon_h);
- icon_w *= ctx->pixel_sz;
- icon_h *= ctx->pixel_sz;
- evas_object_image_size_set(o, icon_w, icon_h);
- evas_object_image_data_set(o, cipher_bmp_get(CIPHER_ZERO));
- evas_object_resize(o, icon_w, icon_h);
- evas_object_size_hint_min_set(o, icon_w, icon_h);
- evas_object_size_hint_max_set(o, icon_w, icon_h);
+ o = score_add(win);
+ score_set(o, ctx->nm);
+ //evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_box_pack_end(hbox, o);
evas_object_show(o);
- cph = o;
+ ctx->remain = o;
+
+ int icon_w, icon_h;
o = evas_object_image_filled_add(evas_object_evas_get(win));
smiley_size_get(&icon_w, &icon_h);
@@ -440,6 +439,8 @@ elm_main(int argc, char **argv)
ctx->smiley = o;
o = evas_object_image_filled_add(evas_object_evas_get(win));
+ evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
tile_size_get(&icon_w, &icon_h);
icon_w *= ctx->pixel_sz;
icon_h *= ctx->pixel_sz;
@@ -517,8 +518,6 @@ elm_main(int argc, char **argv)
display_board(ctx);
- //ctx_draw(ctx);
-
win_w = ctx->nc * ctx->pixel_sz;
win_h = ctx->nl * ctx->pixel_sz;
evas_object_resize(win,
diff --git a/src/bin/elimine.h b/src/bin/elimine.h
new file mode 100644
index 0000000..f50087f
--- /dev/null
+++ b/src/bin/elimine.h
@@ -0,0 +1,27 @@
+/*
+ * SPDX-FileCopyrightText: Vincent Torri <vincent.to...@gmail.com>
+ * SPDX-License-Identifier: MIT
+ */
+
+#ifndef ELIMINATE_H
+#define ELIMINATE_H
+
+typedef struct
+{
+ Evas *evas;
+ Evas_Object *grd;
+ Evas_Object *smiley;
+ Eina_List *tiles;
+
+ int *state;
+ int *known;
+ int nl; /* number of lines of the board */
+ int nc; /* number of columns of the board */
+ int nm; /* number of mines in the board */
+ int pixel_sz; /* size in pixels of a tile */
+ int flagged; /* number of tile with a flag */
+
+ Eina_Bool finished;
+} Ctx;
+
+#endif /* ELIMINATE_H */
diff --git a/src/bin/meson.build b/src/bin/meson.build
index 685dad6..60b4785 100644
--- a/src/bin/meson.build
+++ b/src/bin/meson.build
@@ -3,7 +3,7 @@
elimine = executable('elimine',
- files(['elimine.c', 'icon.c']),
+ files(['elimine.c', 'icon.c', 'score.c']),
dependencies : [ elm_deps ],
include_directories : config_dir,
install : true
diff --git a/src/bin/score.c b/src/bin/score.c
new file mode 100644
index 0000000..f0150e4
--- /dev/null
+++ b/src/bin/score.c
@@ -0,0 +1,261 @@
+/*
+ * SPDX-FileCopyrightText: Vincent Torri <vincent.to...@gmail.com>
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <Elementary.h>
+
+#include "icon.h"
+#include "elimine.h"
+
+typedef struct Score Score;
+
+struct Score
+{
+ Evas_Object *icons[3];
+ int val;
+ int pixel_sz;
+};
+
+static Evas_Smart *_smart = NULL;
+static Evas_Smart_Class _parent_sc = EVAS_SMART_CLASS_INIT_NULL;
+
+static void
+_smart_add(Evas_Object *obj)
+{
+ Score *sd;
+
+ //INF(" * %s", __FUNCTION__);
+ printf(" * %s\n", __FUNCTION__);
+
+ sd = calloc(1, sizeof(Score));
+ EINA_SAFETY_ON_NULL_RETURN(sd);
+
+ evas_object_smart_data_set(obj, sd);
+
+ _parent_sc.add(obj);
+}
+
+static void
+_smart_del(Evas_Object *obj)
+{
+ Score *sd;
+
+ //INF(" * %s", __FUNCTION__);
+ printf(" * %s\n", __FUNCTION__);
+
+ sd = evas_object_smart_data_get(obj);
+ EINA_SAFETY_ON_NULL_RETURN(sd);
+
+ _parent_sc.del(obj);
+
+ evas_object_del(sd->icons[0]);
+ evas_object_del(sd->icons[1]);
+ evas_object_del(sd->icons[2]);
+
+ evas_object_smart_data_set(obj, NULL);
+ memset(sd, 0, sizeof(*sd));
+ free(sd);
+}
+
+static void
+_smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
+{
+ Score *sd;
+ int icon_w;
+ int icon_h;
+
+ //INF(" * %s", __FUNCTION__);
+ printf(" * %s %d %d\n", __FUNCTION__, x, y);
+
+ sd = evas_object_smart_data_get(obj);
+ EINA_SAFETY_ON_NULL_RETURN(sd);
+
+ cipher_size_get(&icon_w, &icon_h);
+ icon_w *= sd->pixel_sz;
+ icon_h *= sd->pixel_sz;
+ evas_object_move(sd->icons[0], x, y);
+ evas_object_move(sd->icons[1], x + icon_w, y);
+ evas_object_move(sd->icons[2], x + 2 * icon_w, y);
+}
+
+static void
+_smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
+{
+ Score *sd;
+ int icon_w;
+ int icon_h;
+
+ //INF(" * %s", __FUNCTION__);
+ printf(" * %s\n", __FUNCTION__);
+
+ sd = evas_object_smart_data_get(obj);
+ EINA_SAFETY_ON_NULL_RETURN(sd);
+
+ cipher_size_get(&icon_w, &icon_h);
+ icon_w *= sd->pixel_sz;
+ icon_h *= sd->pixel_sz;
+
+ evas_object_size_hint_min_set(obj, 3 * icon_w, icon_h);
+ evas_object_size_hint_max_set(obj, 3 * icon_w, icon_h);
+ evas_object_resize(obj, 3 * icon_w, icon_h);
+}
+
+static void
+_smart_show(Evas_Object *obj)
+{
+ Score *sd;
+
+ //INF(" * %s", __FUNCTION__);
+ printf(" * %s\n", __FUNCTION__);
+
+ sd = evas_object_smart_data_get(obj);
+ EINA_SAFETY_ON_NULL_RETURN(sd);
+
+ evas_object_show(sd->icons[0]);
+ evas_object_show(sd->icons[1]);
+ evas_object_show(sd->icons[2]);
+}
+
+static void
+_smart_hide(Evas_Object *obj)
+{
+ Score *sd;
+
+ //INF(" * %s", __FUNCTION__);
+ printf(" * %s\n", __FUNCTION__);
+
+ sd = evas_object_smart_data_get(obj);
+ EINA_SAFETY_ON_NULL_RETURN(sd);
+
+ evas_object_hide(sd->icons[0]);
+ evas_object_hide(sd->icons[1]);
+ evas_object_hide(sd->icons[2]);
+}
+
+static void
+_smart_calculate(Evas_Object *obj)
+{
+ /* Img *sd; */
+ /* Evas_Coord ox; */
+ /* Evas_Coord oy; */
+ /* Evas_Coord ow; */
+ /* Evas_Coord oh; */
+
+ /* INF(" * %s", __FUNCTION__); */
+
+ /* sd = evas_object_smart_data_get(obj); */
+ /* EINA_SAFETY_ON_NULL_RETURN(sd); */
+
+ /* evas_object_geometry_get(obj, &ox, &oy, &ow, &oh); */
+
+ /* evas_object_move(sd->img, ox, oy); */
+ /* evas_object_resize(sd->img, ow, oh); */
+
+ printf("calculate\n");
+}
+
+static void
+_smart_init(void)
+{
+ static Evas_Smart_Class sc;
+
+ //INF(" * %s", __FUNCTION__);
+ printf(" * %s\n", __FUNCTION__);
+
+ evas_object_smart_clipped_smart_set(&_parent_sc);
+ sc = _parent_sc;
+ sc.name = "score";
+ sc.version = EVAS_SMART_CLASS_VERSION;
+ sc.add = _smart_add;
+ sc.del = _smart_del;
+ sc.move = _smart_move;
+ sc.resize = _smart_resize;
+ sc.show = _smart_show;
+ sc.hide = _smart_hide;
+ sc.calculate = _smart_calculate;
+ _smart = evas_smart_class_new(&sc);
+}
+
+Evas_Object *
+score_add(Evas_Object *win)
+{
+ Evas *evas;
+ Evas_Object *obj;
+ Ctx *ctx;
+
+ //INF(" * %s", __FUNCTION__);
+ printf(" * %s\n", __FUNCTION__);
+
+ EINA_SAFETY_ON_NULL_RETURN_VAL(win, NULL);
+ evas = evas_object_evas_get(win);
+ if (!_smart) _smart_init();
+ obj = evas_object_smart_add(evas, _smart);
+
+ ctx = evas_object_data_get(win, "ctx");
+ EINA_SAFETY_ON_NULL_RETURN_VAL(ctx, NULL);
+
+ evas_object_data_set(obj, "ctx", ctx);
+
+ return obj;
+}
+
+void
+score_set(Evas_Object *obj, int val)
+{
+ Score *sd;
+ Ctx *ctx;
+
+ printf(" * %s\n", __FUNCTION__);
+
+ sd = evas_object_smart_data_get(obj);
+ EINA_SAFETY_ON_NULL_RETURN(sd);
+
+ ctx = evas_object_data_get(obj, "ctx");
+ EINA_SAFETY_ON_NULL_RETURN(ctx);
+
+ if (!sd->pixel_sz)
+ {
+ /* nothing is setup */
+ int icon_w;
+ int icon_h;
+
+ sd->pixel_sz = ctx->pixel_sz;
+ cipher_size_get(&icon_w, &icon_h);
+ icon_w *= sd->pixel_sz;
+ icon_h *= sd->pixel_sz;
+
+ for (int i = 0; i < 3; i++)
+ {
+ Evas_Object *o;
+
+ o = evas_object_image_filled_add(evas_object_evas_get(obj));
+ evas_object_image_size_set(o, icon_w, icon_h);
+ evas_object_resize(o, icon_w, icon_h);
+ evas_object_size_hint_min_set(o, icon_w, icon_h);
+ evas_object_size_hint_max_set(o, icon_w, icon_h);
+ sd->icons[i] = o;
+ }
+ }
+
+ if (val < -99) val = -99;
+ if (val < 0)
+ {
+ val = -val;
+ evas_object_image_data_set(sd->icons[0], cipher_bmp_get(CIPHER_DASH));
+ evas_object_image_data_set(sd->icons[1], cipher_bmp_get(val / 10));
+ val = val % 10;
+ evas_object_image_data_set(sd->icons[2], cipher_bmp_get(val));
+ }
+ else
+ {
+ evas_object_image_data_set(sd->icons[0], cipher_bmp_get(val / 100));
+ val = val % 100;
+ evas_object_image_data_set(sd->icons[1], cipher_bmp_get(val / 10));
+ val = val % 10;
+ evas_object_image_data_set(sd->icons[2], cipher_bmp_get(val));
+ }
+ evas_object_image_pixels_dirty_set(sd->icons[0], EINA_TRUE);
+ evas_object_image_pixels_dirty_set(sd->icons[1], EINA_TRUE);
+ evas_object_image_pixels_dirty_set(sd->icons[2], EINA_TRUE);
+}
diff --git a/src/bin/score.h b/src/bin/score.h
new file mode 100644
index 0000000..8ca58ef
--- /dev/null
+++ b/src/bin/score.h
@@ -0,0 +1,12 @@
+/*
+ * SPDX-FileCopyrightText: Vincent Torri <vincent.to...@gmail.com>
+ * SPDX-License-Identifier: MIT
+ */
+
+#ifndef SCORE_H
+#define SCORE_H
+
+Evas_Object *score_add(Evas_Object *win);
+void score_set(Evas_Object *obj, int score);
+
+#endif /* SCORE_H */
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.