added some error handling

master
NetherEran 2020-09-10 15:44:51 +02:00
parent f8c92fbd75
commit 50df5e1896
2 changed files with 11 additions and 3 deletions

8
game.c
View File

@ -41,11 +41,15 @@ void play_game(GAME_STATE* state) {
state -> status = 0;
FIELD* f = malloc(sizeof(FIELD));
if (2 * 40 > COLS || 20 > LINES) {
endwin();
fprintf(stderr, "Snek: Terminal is to small, must be 80x20 at least\n");
exit(1);
}
init_field(f, 40, 20, state);
init_player(f -> player , f -> width / 2, f -> height / 2);
add_ball(f, 1);
redraw_field(f);
fd_set inputs, test_fds;
@ -59,7 +63,7 @@ void play_game(GAME_STATE* state) {
while(1) {
if (state -> status) {
destroy_field(f);
return;
break;
}

6
main.c
View File

@ -11,7 +11,11 @@
int main(int argc, char** argv) {
initscr();
if (! initscr()) {
endwin();
fprintf(stderr, "Snek: Error initializing ncurses\n");
exit(1);
}
start_color();
init_pair(1, COLOR_WHITE, COLOR_WHITE);