Init commit
This commit is contained in:
parent
8bd653d363
commit
8c138fe3fe
7 changed files with 30 additions and 8 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -15,7 +15,8 @@ typedef enum
|
|||
REACH,
|
||||
COLLIDE,
|
||||
GAMEOVER,
|
||||
EXIT_STATE
|
||||
EXIT_STATE,
|
||||
FILE_ERROR_STATE
|
||||
} frog_state;
|
||||
|
||||
typedef enum
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue