From 54f40f6cb863f00fbcaa77ebdb930d8d7fc6988d Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Thu, 28 Dec 2017 21:30:20 +0100 Subject: Imported the code into Git Signed-off-by: Olivier Gayot --- src/move.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/move.c (limited to 'src/move.c') diff --git a/src/move.c b/src/move.c new file mode 100644 index 0000000..c14724c --- /dev/null +++ b/src/move.c @@ -0,0 +1,55 @@ +/* +** move.c for in /home/gayot_o/prog/minesweeper +** +** Made by olivier gayot +** Login +** +** Started on Sun Apr 22 17:08:59 2012 olivier gayot +** Last update Sun Apr 22 17:08:59 2012 olivier gayot +*/ + +#include "minesweeper.h" + +static void incr_selection(int incr, map_t *map, int *selection); + +int move_left(map_t *map, int *selection) { + if (*selection % BLOCK_W) + incr_selection(-1, map, selection); + else /* beginning of the line */ + incr_selection(BLOCK_W - 1, map, selection); + show_map(map); + return 0; +} + +int move_right(map_t *map, int *selection) { + if (*selection % BLOCK_W != (BLOCK_W - 1)) + incr_selection(+1, map, selection); + else /* beginning of the line */ + incr_selection(-(BLOCK_W - 1), map, selection); + show_map(map); + return 0; +} + +int move_up(map_t *map, int *selection) { + if (*selection / BLOCK_W) + incr_selection(-BLOCK_W, map, selection); + else /* beginning of the line */ + incr_selection(BLOCK_W * (BLOCK_H - 1), map, selection); + show_map(map); + return 0; +} + +int move_down(map_t *map, int *selection) { + if (*selection / BLOCK_W != (BLOCK_H - 1)) + incr_selection(BLOCK_W, map, selection); + else /* beginning of the line */ + incr_selection(-(BLOCK_W * (BLOCK_H - 1)), map, selection); + show_map(map); + return 0; +} + +static void incr_selection(int incr, map_t *map, int *selection) { + map->tab[*selection / BLOCK_W][*selection % BLOCK_W].selected = false; + (*selection) += incr; + map->tab[*selection / BLOCK_W][*selection % BLOCK_W].selected = true; +} -- cgit v1.2.3