add typedef'd enums, use direction's

This commit is contained in:
Gwenhael Le Moine 2011-07-01 12:27:57 +02:00
parent 0aea5112e4
commit 11f804d1cf

19
star.c
View file

@ -6,11 +6,8 @@
#define LEVEL_HEIGHT 9 #define LEVEL_HEIGHT 9
#define LEVEL_WIDTH 16 #define LEVEL_WIDTH 16
#define WALL '#' typedef enum { WALL='#', BALL='@', CUBE='H', VOID=' ', GIFT='*' } cell;
#define BALL '@' typedef enum { UP='u', DOWN='d', LEFT='l', RIGHT='r' } direction;
#define CUBE 'H'
#define VOID ' '
#define GIFT '*'
char* levels[] = { "################" char* levels[] = { "################"
"#@## *#H#" "#@## *#H#"
@ -316,7 +313,7 @@ int won_or_not( struct state *s )
return( count_gifts( s ) == 0 ); return( count_gifts( s ) == 0 );
} }
void move( struct state *s, int direction ) void move( struct state *s, direction where )
{ {
int dx = 0, dy = 0, tmpx, tmpy, *item_coord; int dx = 0, dy = 0, tmpx, tmpy, *item_coord;
item_coord = malloc( sizeof( int ) * 2 ); item_coord = malloc( sizeof( int ) * 2 );
@ -324,17 +321,17 @@ void move( struct state *s, int direction )
tmpx = item_coord[ 0 ]; tmpx = item_coord[ 0 ];
tmpy = item_coord[ 1 ]; tmpy = item_coord[ 1 ];
switch( direction ) { switch( where ) {
case 'u': case UP:
dy--; dy--;
break; break;
case 'd': case DOWN:
dy++; dy++;
break; break;
case 'l': case LEFT:
dx--; dx--;
break; break;
case 'r': case RIGHT:
dx++; dx++;
break; break;
default: break; default: break;