diff --git a/src/game_logic.c b/src/game_logic.c index 3dcd76e..71ac5af 100644 --- a/src/game_logic.c +++ b/src/game_logic.c @@ -50,7 +50,12 @@ uint8_t add_random_tile(void) { return tile_placed; // Return 0 if we were not able to place the tile } -uint8_t *step_game(step_direction dir) { +game_state step_game(step_direction dir) { + game_state state = { + .score = 0, + .done = 0 + }; + uint8_t start_offset; int8_t column_step; int8_t row_step; @@ -100,6 +105,8 @@ uint8_t *step_game(step_direction dir) { if(front_grid[sub_col_offset]) { back_grid[current_offset] = front_grid[sub_col_offset]; front_grid[sub_col_offset] = 0; + + state.score += ((uint16_t)1) << back_grid[current_offset]; break; } } @@ -113,6 +120,9 @@ uint8_t *step_game(step_direction dir) { if(front_grid[sub_col_offset] == back_grid[current_offset]) { back_grid[current_offset]++; // Merge them (by increasing the value of the current square and removing the merged one) front_grid[sub_col_offset] = 0; + + state.score += ((uint16_t)1) << back_grid[current_offset]; + state.done += back_grid[current_offset] == 11 ? 1 : 0; break; } } @@ -121,5 +131,5 @@ uint8_t *step_game(step_direction dir) { swap_grids(); - return front_grid; + return state; } diff --git a/src/game_logic.h b/src/game_logic.h index 4702000..7b4b297 100644 --- a/src/game_logic.h +++ b/src/game_logic.h @@ -12,9 +12,14 @@ typedef enum { RIGHT } step_direction; +typedef struct { + uint16_t score; + uint8_t done; +} game_state; + void reset_game(void); uint8_t *get_front_grid(void); -uint8_t *step_game(step_direction dir); +game_state step_game(step_direction dir); uint8_t add_random_tile(void); #endif /* _GAME_LOGIC_HEADER_ */