introduce some naughtiness, use ncurses' KEY_ codes to define direction

This commit is contained in:
Gwenhael Le Moine 2011-07-03 23:01:02 +02:00
parent 73717a08a0
commit 9585ed44d3

18
star.c
View file

@ -279,11 +279,11 @@ typedef enum { /* characters used to design levels */
GIFT = 'x' GIFT = 'x'
} cell; } cell;
typedef enum { /* values aren't strictly necessary but useful for unit-testing */ typedef enum { /* and now a nasty trick to slightly simplify key handling */
UP = 'u', UP = KEY_UP, /* we'll use ncurses codes to define directions */
DOWN = 'd', DOWN = KEY_DOWN,
LEFT = 'l', LEFT = KEY_LEFT,
RIGHT = 'r' RIGHT = KEY_RIGHT
} direction; } direction;
struct options { /* store how the game is started (controlled by --arguments) */ struct options { /* store how the game is started (controlled by --arguments) */
@ -601,16 +601,10 @@ int main( int argc, char* argv[] )
key = getch(); key = getch();
switch( key ) { switch( key ) {
case KEY_UP: case KEY_UP:
make_a_move( s, UP );
break;
case KEY_DOWN: case KEY_DOWN:
make_a_move( s, DOWN );
break;
case KEY_LEFT: case KEY_LEFT:
make_a_move( s, LEFT );
break;
case KEY_RIGHT: case KEY_RIGHT:
make_a_move( s, RIGHT ); make_a_move( s, key );
break; break;
case ' ': case ' ':
switch_actor( s ); switch_actor( s );