navigation.c (978B)
1 #include "navigation.h" 2 3 void 4 navigate(Board *b, int *mv) 5 { 6 static int y = 1, x = 2; 7 update_curs(b, y, x); 8 b->x = (x-2)/3; 9 b->y = y-1; 10 refresh(); 11 getmv(b, mv, &y, &x); 12 } 13 14 void 15 getmv(const Board *b, int *mv, int *y, int *x) 16 { 17 *mv = wgetch(b->gw); 18 switch (*mv) 19 { 20 case 'k': case 'K': /* FALLTHROUGH */ 21 case 'w': case 'W': 22 mvup(y); 23 break; 24 case 'j': case 'J': /* FALLTHROUGH */ 25 case 's': case 'S': 26 mvdown(y, YMAX(b->gw)); 27 break; 28 case 'h': case 'H': /* FALLTHROUGH */ 29 case 'a': case 'A': 30 mvleft(x); 31 break; 32 case 'l': case 'L': /* FALLTHROUGH */ 33 case 'd': case 'D': 34 mvright(x, XMAX(b->gw)); 35 break; 36 } 37 } 38 39 void 40 mvup(int *y) 41 { 42 (*y)--; 43 if (*y < 1) *y = 1; 44 } 45 46 void 47 mvdown(int *y, int ymax) 48 { 49 (*y)++; 50 if (*y > ymax-2) *y = ymax-2; 51 } 52 53 void 54 mvleft(int *x) 55 { 56 *x -= 3; 57 if (*x < 2) *x = 2; 58 } 59 60 void 61 mvright(int *x, int xmax) 62 { 63 *x += 3; 64 if (*x > xmax-3) *x = xmax-3; 65 } 66 67 void 68 update_curs(const Board *b, int y, int x) 69 { 70 wmove(b->gw, y, x); 71 }