From 630842effe8d39c0a6ddc7c1beea745aacca0f1d Mon Sep 17 00:00:00 2001 From: Gwenhael Le Moine Date: Mon, 4 Jul 2011 09:12:58 +0200 Subject: [PATCH] make get_pos more generic --- star.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/star.c b/star.c index cbb530d..3c97a6e 100644 --- a/star.c +++ b/star.c @@ -313,16 +313,16 @@ int count_gifts( struct state *s ) return n; } -/* Write the position of the currently moving actor into pos +/* Write the position of actor into pos */ -void get_pos( struct state *s, int* pos ) +void get_pos( struct state *s, int* pos, cell actor ) { int p; - p = (int)( strchr( s->board, s->moving ) - s->board ); + p = (int)( strchr( s->board, actor ) - s->board ); - pos[ 1 ] = p / LEVEL_WIDTH; - pos[ 0 ] = p - ( pos[ 1 ] * LEVEL_WIDTH ); + pos[ 1 ] = p / LEVEL_WIDTH; /* y */ + pos[ 0 ] = p - ( pos[ 1 ] * LEVEL_WIDTH ); /* x */ } /* Returns the content of cell( x, y ) of the current level @@ -372,7 +372,7 @@ void make_a_move( struct state *s, direction where ) { int dx = 0, dy = 0, tmpx, tmpy, *item_coord; item_coord = malloc( sizeof( int ) * 2 ); - get_pos( s, item_coord ); + get_pos( s, item_coord, s->moving ); tmpx = item_coord[ 0 ]; tmpy = item_coord[ 1 ];