diff options
author | Olivier Gayot <duskcoder@gmail.com> | 2017-12-28 21:30:20 +0100 |
---|---|---|
committer | Olivier Gayot <duskcoder@gmail.com> | 2017-12-28 21:31:01 +0100 |
commit | 54f40f6cb863f00fbcaa77ebdb930d8d7fc6988d (patch) | |
tree | 0757b1da4f95b1096877fcbd101ef7edf923b4ce /src/move.c |
Imported the code into Git
Signed-off-by: Olivier Gayot <duskcoder@gmail.com>
Diffstat (limited to 'src/move.c')
-rw-r--r-- | src/move.c | 55 |
1 files changed, 55 insertions, 0 deletions
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 <gayot_o@epitech.net> +** +** 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; +} |