/* ** 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; }