From 155a3c5f91c7a3bd89febfeb9927478961f5ee28 Mon Sep 17 00:00:00 2001 From: scratko Date: Sun, 7 Apr 2024 22:40:47 +0300 Subject: Tracking coins eaten The initialization of ncurses parameters and ghosts was put into functions. The order of movements has been changed: now pacman moves first. Accounting for eaten coins. Correct coin erasure. --- field.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'field.c') diff --git a/field.c b/field.c index 5bcb813..a795f8e 100644 --- a/field.c +++ b/field.c @@ -1,5 +1,6 @@ #include "field.h" #include "ghosts.h" +#include "queue.h" #include #include @@ -52,11 +53,11 @@ game_space get_new_field() return field; } -static int is_has_point(int i, int j) +int field_has_coin(int x, int y) { - return !((i == 12 && j == 9) || (i == 12 && j == 18) || - (i == 14 && j == 18) || (i == 15 && j == 9) || - (i == 17 && j == 9) || (i == 17 && j == 18)); + return !((x == 12 && y == 9) || (x == 12 && y == 18) || + (x == 14 && y == 18) || (x == 15 && y == 9) || + (x == 17 && y == 9) || (x == 17 && y == 18)); } void print_field(game_space field) @@ -72,7 +73,7 @@ void print_field(game_space field) case '1': case '2': case '3': - if(is_has_point(i, j)) + if(field_has_coin(i, j)) addch('.'); else addch(' '); @@ -113,18 +114,32 @@ void display_ghosts_on_field(struct ghost_type *red_ghost, ghost_char); } -void eat_or_revert_symbol(game_space field, int y, int x, - enum select_character character) +void clear_or_revert_symbol(game_space field, struct coordinates position, + enum select_character character, + struct queue *eaten_coins) { + int x, y; + x = position.x; + y = position.y; int symbol = field[y][x]; move(y, x); if(character == ghost_char) { switch(symbol) { - case '#': + case one_path: + case two_paths: + case three_paths: + if(field_has_coin(y, x)) + queue_consists_point(eaten_coins, position) ? + addch(' ') : addch('.'); + else + addch(' '); + break; + case door: addch('#'); break; - case '.': - addch('.'); + case coin: + queue_consists_point(eaten_coins, position) ? + addch(' ') : addch('.'); break; case ' ': addch(' '); -- cgit v1.2.3