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. --- pac.c | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) (limited to 'pac.c') diff --git a/pac.c b/pac.c index 1fd4b73..241609b 100644 --- a/pac.c +++ b/pac.c @@ -1,10 +1,11 @@ #include "pac.h" #include "ncurses.h" +#include "queue.h" void initialize_pac(struct pacman *pac) { pac->lives = max_live; - pac->points_eaten = 0; + pac->coins_eaten = 0; pac->position.y = pac_y; pac->position.x = pac_x; pac->direction = none; @@ -120,23 +121,44 @@ void change_pac_direction(game_space field, struct pacman *pac, int key, check_remaining_direction_after_pressed_key(field, pac); } -void make_pac_move(game_space field, struct pacman *pac) +static int is_coin_symbol(int symbol) { - eat_or_revert_symbol(field, pac->position.y, pac->position.x, pac_char); + return + symbol == coin || symbol == one_path || symbol == two_paths || + symbol == three_paths; +} + +static int check_coin(game_space field, struct coordinates position, + struct queue *eaten_coins) +{ + int x, y; + x = position.x; + y = position.y; + return + is_coin_symbol(field[y][x]) && field_has_coin(x, y) && + !queue_consists_point(eaten_coins, position); +} + +void make_pac_move(game_space field, struct pacman *pac, + struct queue *eaten_coins) +{ + clear_or_revert_symbol(field, pac->position, pac_char, eaten_coins); switch(pac->direction) { case left: --pac->position.x; - return; + break; case right: ++pac->position.x; - return; + break; case up: --pac->position.y; - return; + break; case down: ++pac->position.y; - return; + break; default: return; } + if(check_coin(field, pac->position, eaten_coins)) + queue_push(eaten_coins, &pac->position); } -- cgit v1.2.3