back to scratko.xyz
aboutsummaryrefslogtreecommitdiff
path: root/pacman.c
diff options
context:
space:
mode:
authorscratko <m@scratko.xyz>2024-04-07 22:40:47 +0300
committerscratko <m@scratko.xyz>2024-04-07 22:40:47 +0300
commit155a3c5f91c7a3bd89febfeb9927478961f5ee28 (patch)
tree1953cd610d4a06c51aaedb728edd6131a4fa426a /pacman.c
parent2c2448cc94b8f17ac699814a75110411d57f3bea (diff)
downloadpacman-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 'pacman.c')
-rw-r--r--pacman.c54
1 files changed, 35 insertions, 19 deletions
diff --git a/pacman.c b/pacman.c
index 5b5b50a..9346055 100644
--- a/pacman.c
+++ b/pacman.c
@@ -25,15 +25,19 @@ static void pathfinder_stage(game_space field, struct pacman pac,
redirect(field, intersection, red_ghost, pac, breadth_first_search);
}
-int main()
+static void initialize_ghosts(struct ghost_type *red_ghost,
+ struct ghost_type *pink_ghost,
+ struct ghost_type *blue_ghost,
+ struct ghost_type *orange_ghost)
+{
+ initialize_ghost(red_ghost, red);
+ initialize_ghost(pink_ghost, pink);
+ initialize_ghost(blue_ghost, blue);
+ initialize_ghost(orange_ghost, orange);
+}
+
+static void ncurses_params()
{
- game_space field = NULL;
- struct ghost_type red_ghost, pink_ghost, blue_ghost, orange_ghost;
- struct pacman pac;
- int key, get_out_stage;
- enum movement_direction stored_direction;
- stored_direction = none;
- get_out_stage = count_get_out_moves;
initscr();
start_color();
cbreak();
@@ -42,36 +46,48 @@ int main()
keypad(stdscr, 1);
timeout(timeout_duration);
start_color();
+}
+
+int main()
+{
+ game_space field = NULL;
+ struct ghost_type red_ghost, pink_ghost, blue_ghost, orange_ghost;
+ struct pacman pac;
+ struct queue eaten_coins;
+ int key, get_out_stage;
+ enum movement_direction stored_direction;
+ stored_direction = none;
+ get_out_stage = count_get_out_moves;
+ ncurses_params();
field = get_new_field();
print_field(field);
- initialize_ghost(&red_ghost, red);
- initialize_ghost(&pink_ghost, pink);
- initialize_ghost(&blue_ghost, blue);
- initialize_ghost(&orange_ghost, orange);
+ initialize_ghosts(&red_ghost, &pink_ghost, &blue_ghost, &orange_ghost);
initialize_pac(&pac);
+ queue_init(&eaten_coins);
display_ghosts_on_field(&red_ghost, &pink_ghost, &blue_ghost,
&orange_ghost);
display_character(pac.position.y, pac.position.x, pac_char);
usleep(sleep_duration);
while((key = getch()) != key_escape) {
+ if(key != ERR)
+ change_pac_direction(field, &pac, key, &stored_direction);
+ else
+ check_remaining_direction(field, &pac, &stored_direction);
if(get_out_stage)
pull_out_ghosts(&get_out_stage, &red_ghost, &pink_ghost,
&blue_ghost, &orange_ghost);
else
pathfinder_stage(field, pac, &red_ghost, &pink_ghost, &blue_ghost,
&orange_ghost);
- if(key != ERR)
- change_pac_direction(field, &pac, key, &stored_direction);
- else
- check_remaining_direction(field, &pac, &stored_direction);
+ make_pac_move(field, &pac, &eaten_coins);
make_ghost_moves(field, &red_ghost, &pink_ghost, &blue_ghost,
- &orange_ghost);
- make_pac_move(field, &pac);
+ &orange_ghost, &eaten_coins);
+ display_character(pac.position.y, pac.position.x, pac_char);
display_ghosts_on_field(&red_ghost, &pink_ghost, &blue_ghost,
&orange_ghost);
- display_character(pac.position.y, pac.position.x, pac_char);
usleep(sleep_duration);
}
+ queue_clear(&eaten_coins);
endwin();
return 0;
}