diff options
author | scratko <m@scratko.xyz> | 2024-04-07 22:40:47 +0300 |
---|---|---|
committer | scratko <m@scratko.xyz> | 2024-04-07 22:40:47 +0300 |
commit | 155a3c5f91c7a3bd89febfeb9927478961f5ee28 (patch) | |
tree | 1953cd610d4a06c51aaedb728edd6131a4fa426a /field.c | |
parent | 2c2448cc94b8f17ac699814a75110411d57f3bea (diff) | |
download | pacman-155a3c5f91c7a3bd89febfeb9927478961f5ee28.tar.gz pacman-155a3c5f91c7a3bd89febfeb9927478961f5ee28.tar.bz2 pacman-155a3c5f91c7a3bd89febfeb9927478961f5ee28.zip |
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.
Diffstat (limited to 'field.c')
-rw-r--r-- | field.c | 35 |
1 files changed, 25 insertions, 10 deletions
@@ -1,5 +1,6 @@ #include "field.h" #include "ghosts.h" +#include "queue.h" #include <ncurses.h> #include <stdlib.h> @@ -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(' '); |