diff options
author | scratko <m@scratko.xyz> | 2024-04-07 03:07:42 +0300 |
---|---|---|
committer | scratko <m@scratko.xyz> | 2024-04-07 03:07:42 +0300 |
commit | 2c2448cc94b8f17ac699814a75110411d57f3bea (patch) | |
tree | 4107fa66264cda94dd01c3bb00da29945c8d6131 /pacman.c | |
parent | bdee2852c13f6b02ec5207ded584839a3118233e (diff) | |
download | pacman-2c2448cc94b8f17ac699814a75110411d57f3bea.tar.gz pacman-2c2448cc94b8f17ac699814a75110411d57f3bea.tar.bz2 pacman-2c2448cc94b8f17ac699814a75110411d57f3bea.zip |
BFS, queue files
Fixed remaining direction check for pacman (old version was commented out).
Breadth First Search for red ghost.
Changed switch style.
Diffstat (limited to 'pacman.c')
-rw-r--r-- | pacman.c | 35 |
1 files changed, 17 insertions, 18 deletions
@@ -1,26 +1,28 @@ #include "field.h" #include "ghosts.h" #include "pac.h" +#include "queue.h" #include <ncurses.h> #include <stdlib.h> #include <unistd.h> -enum { +enum { timeout_duration = 0, sleep_duration = 190000, key_escape = 27, count_get_out_moves = 5 }; -static void pathfinder_stage(game_space field, struct ghost_type *red_ghost, - struct ghost_type *pink_ghost, +static void pathfinder_stage(game_space field, struct pacman pac, + struct ghost_type *red_ghost, + struct ghost_type *pink_ghost, struct ghost_type *blue_ghost, struct ghost_type *orange_ghost) { enum intersection_type intersection; intersection = get_intersection(field, red_ghost); if(intersection != direct_path) - redirect(field, intersection, red_ghost, breadth_first_search); + redirect(field, intersection, red_ghost, pac, breadth_first_search); } int main() @@ -33,6 +35,7 @@ int main() stored_direction = none; get_out_stage = count_get_out_moves; initscr(); + start_color(); cbreak(); noecho(); curs_set(0); @@ -46,31 +49,27 @@ int main() initialize_ghost(&blue_ghost, blue); initialize_ghost(&orange_ghost, orange); initialize_pac(&pac); - display_ghosts_on_field(&red_ghost, &pink_ghost, &blue_ghost, + display_ghosts_on_field(&red_ghost, &pink_ghost, &blue_ghost, &orange_ghost); - display_character(pac.position.y, pac.position.x, 'C'); + display_character(pac.position.y, pac.position.x, pac_char); usleep(sleep_duration); while((key = getch()) != key_escape) { if(get_out_stage) - pull_out_ghosts(&get_out_stage, &red_ghost, &pink_ghost, + pull_out_ghosts(&get_out_stage, &red_ghost, &pink_ghost, &blue_ghost, &orange_ghost); else - pathfinder_stage(field, &red_ghost, &pink_ghost, &blue_ghost, + pathfinder_stage(field, pac, &red_ghost, &pink_ghost, &blue_ghost, &orange_ghost); - if(key != ERR) + if(key != ERR) change_pac_direction(field, &pac, key, &stored_direction); - else { - if(stored_direction != none) - check_remaining_direction(field, &pac, &stored_direction); - else - check_remaining_direction(field, &pac, NULL); - } - make_ghost_moves(field, &red_ghost, &pink_ghost, &blue_ghost, + else + check_remaining_direction(field, &pac, &stored_direction); + make_ghost_moves(field, &red_ghost, &pink_ghost, &blue_ghost, &orange_ghost); make_pac_move(field, &pac); - display_ghosts_on_field(&red_ghost, &pink_ghost, &blue_ghost, + display_ghosts_on_field(&red_ghost, &pink_ghost, &blue_ghost, &orange_ghost); - display_character(pac.position.y, pac.position.x, 'C'); + display_character(pac.position.y, pac.position.x, pac_char); usleep(sleep_duration); } endwin(); |