From 91583d5699503e981105beecc51d37b59dc1842e Mon Sep 17 00:00:00 2001 From: scratko Date: Fri, 12 Apr 2024 16:33:07 +0300 Subject: Coin checks Coin checks in yellow blocks and stars. Fixed arguments of find_free_directions function. --- field.c | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) (limited to 'field.c') diff --git a/field.c b/field.c index 37a5be1..2dcd783 100644 --- a/field.c +++ b/field.c @@ -60,6 +60,16 @@ int field_has_coin(int x, int y) (x == 17 && y == 9) || (x == 17 && y == 18)); } +int field_has_energizer(const game_space field, int x, int y) +{ + return field[y][x] = energizer; +} + +static int yellow_block_contains_coin(int x, int y) +{ + return (x == 12 && y == 22) || (x == 15 && y == 22); +} + void print_field(game_space field) { int i; @@ -73,7 +83,13 @@ void print_field(game_space field) case one_path: case two_paths: case three_paths: - if(field_has_coin(i, j)) + if(field_has_coin(j, i)) + addch('.'); + else + addch(' '); + break; + case yellow_block: + if(yellow_block_contains_coin(j, i)) addch('.'); else addch(' '); @@ -117,7 +133,7 @@ void display_ghosts_on_field(struct ghost_type *red_ghost, ghost_char); } -void clear_or_revert_symbol(game_space field, struct coordinates position, +void clear_or_revert_symbol(const game_space field, struct coordinates position, enum select_character character, struct queue *eaten_coins) { @@ -131,8 +147,14 @@ void clear_or_revert_symbol(game_space field, struct coordinates position, case one_path: case two_paths: case three_paths: + if(field_has_coin(x, y)) + queue_consists_point(eaten_coins, position) ? + addch(' ') : addch('.'); + else + addch(' '); + break; case yellow_block: - if(field_has_coin(y, x)) + if(yellow_block_contains_coin(x, y)) queue_consists_point(eaten_coins, position) ? addch(' ') : addch('.'); else @@ -142,6 +164,8 @@ void clear_or_revert_symbol(game_space field, struct coordinates position, addch('#'); break; case energizer: + field_has_energizer(field, x, y) ? addch('*') : addch(' '); + break; case coin: queue_consists_point(eaten_coins, position) ? addch(' ') : addch('.'); @@ -182,8 +206,8 @@ enum intersection_type get_intersection(const game_space field, * x+1 == right_outside_tunnel_x are used by only pacman (while * cheking remaining direction) */ -struct free_directions find_free_directions(const game_space field, int y, - int x) +struct free_directions find_free_directions(const game_space field, int x, + int y) { struct free_directions found_paths; found_paths.left = (field[y][x-1] != '/' && field[y][x-1] != '#') || @@ -210,3 +234,11 @@ void change_point_if_outside_tunnel(struct coordinates *point) if(point->x == right_outside_tunnel_x) point->x = left_outside_tunnel_x + 1; } + +void clear_energizer(game_space field, struct coordinates point) +{ + int x, y; + x = point.x; + y = point.y; + field[y][x] = ' '; +} -- cgit v1.2.3