diff options
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; +} |