diff --git a/code-samples/frogger/inc/frog_frontend.h b/code-samples/frogger/inc/frog_frontend.h index 4bc12b8..fa079df 100644 --- a/code-samples/frogger/inc/frog_frontend.h +++ b/code-samples/frogger/inc/frog_frontend.h @@ -6,6 +6,7 @@ #include "objects.h" void print_overlay(void); +void print_levelerror(void); void print_rectangle(int top_y, int bottom_y, int left_x, int right_x); void print_stats(game_stats_t *stats); void print_board(board_t *game, player_pos *frog); diff --git a/code-samples/frogger/inc/fsm.h b/code-samples/frogger/inc/fsm.h index ac4286e..794b7db 100644 --- a/code-samples/frogger/inc/fsm.h +++ b/code-samples/frogger/inc/fsm.h @@ -15,7 +15,8 @@ typedef enum REACH, COLLIDE, GAMEOVER, - EXIT_STATE + EXIT_STATE, + FILE_ERROR_STATE } frog_state; typedef enum diff --git a/code-samples/frogger/src/backend.c b/code-samples/frogger/src/backend.c index 4f35f0c..26db790 100644 --- a/code-samples/frogger/src/backend.c +++ b/code-samples/frogger/src/backend.c @@ -21,9 +21,10 @@ int lvlproc(board_t *map, game_stats_t *stats) else map->ways[i][strcspn(map->ways[i], "\n")] = '\0'; } + fclose(level); } - - fclose(level); + else + rc = ERROR; return rc; } diff --git a/code-samples/frogger/src/frogger.c b/code-samples/frogger/src/frogger.c index bef1550..03727e1 100644 --- a/code-samples/frogger/src/frogger.c +++ b/code-samples/frogger/src/frogger.c @@ -24,8 +24,8 @@ void game_loop() stats_init(&stats); while (break_flag) - { - if (state == GAMEOVER || state == EXIT_STATE) + { + if (state == GAMEOVER || state == EXIT_STATE || state == FILE_ERROR_STATE) break_flag = FALSE; sigact(get_signal(signal), &state, &stats, &map, &frog); @@ -33,4 +33,11 @@ void game_loop() if (state == MOVING || state == START) signal = GET_USER_INPUT; } + + if (state == FILE_ERROR_STATE) + { + print_levelerror(); + nodelay(stdscr, FALSE); + getch(); + } } \ No newline at end of file diff --git a/code-samples/frogger/src/frontend.c b/code-samples/frogger/src/frontend.c index 309b067..ae8ed5d 100644 --- a/code-samples/frogger/src/frontend.c +++ b/code-samples/frogger/src/frontend.c @@ -18,6 +18,16 @@ void print_overlay(void) MVPRINTW(BOARD_N / 2, (BOARD_M - INTRO_MESSAGE_LEN) / 2 + 1, INTRO_MESSAGE); } +void print_levelerror(void) +{ + clear(); + MVPRINTW(0, 0, "An error occured openning level file!"); + MVPRINTW(2, 0, "Please check ./tests/ directory."); + MVPRINTW(3, 0, "There should be 5 level files named level_(1-5).txt."); + MVPRINTW(4, 0, "Also try to open the game nearby ./tests/ directory."); + MVPRINTW(6, 0, "Press any key to exit."); +} + void print_rectangle(int top_y, int bottom_y, int left_x, int right_x) { MVADDCH(top_y, left_x, ACS_ULCORNER); diff --git a/code-samples/frogger/src/fsm.c b/code-samples/frogger/src/fsm.c index db4b6af..2fc6d76 100644 --- a/code-samples/frogger/src/fsm.c +++ b/code-samples/frogger/src/fsm.c @@ -101,7 +101,7 @@ void sigact(signals sig, frog_state *state, game_stats_t *stats, board_t *map, p *state = MOVING; } else - *state = EXIT_STATE; + *state = FILE_ERROR_STATE; break; case MOVING: diff --git a/code-samples/frogger/src/fsm_matrix.c b/code-samples/frogger/src/fsm_matrix.c index 634306b..ec6367b 100644 --- a/code-samples/frogger/src/fsm_matrix.c +++ b/code-samples/frogger/src/fsm_matrix.c @@ -50,13 +50,15 @@ action fsm_table[8][7] = { void sigact(signals sig, frog_state *state, game_stats_t *stats, board_t *map, player_pos *frog_pos) { + action act = NULL; params_t prms; prms.stats = stats; prms.state = state; prms.map = map; prms.frog_pos = frog_pos; - action act = fsm_table[*state][sig]; + if (*state != FILE_ERROR_STATE) + act = fsm_table[*state][sig]; if (act) act(&prms); @@ -120,7 +122,7 @@ void spawn(params_t *prms) *prms->state = MOVING; } else - *prms->state = EXIT_STATE; + *prms->state = FILE_ERROR_STATE; } }