Updated: added terminal window size validation
This commit is contained in:
parent
957d2c6fbe
commit
3942bc03e1
1 changed files with 11 additions and 4 deletions
15
serpent.c
15
serpent.c
|
@ -60,7 +60,7 @@ bool snakeCollision(int x, int y, bool excludeHead);
|
||||||
bool appleCollision(int x, int y);
|
bool appleCollision(int x, int y);
|
||||||
void handleInput(int key);
|
void handleInput(int key);
|
||||||
void drawGame();
|
void drawGame();
|
||||||
void initializeGame();
|
int initializeGame();
|
||||||
void gameLoop();
|
void gameLoop();
|
||||||
void run();
|
void run();
|
||||||
void mainMenu(WINDOW *menuScreen, int menuType);
|
void mainMenu(WINDOW *menuScreen, int menuType);
|
||||||
|
@ -99,7 +99,7 @@ int main (int argc, char **argv) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
initializeGame();
|
if ((initializeGame()) == 1) return 1;
|
||||||
|
|
||||||
cleanup();
|
cleanup();
|
||||||
|
|
||||||
|
@ -450,16 +450,22 @@ void gameLoop() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Function responsible of initializing the game */
|
/* Function responsible of initializing the game */
|
||||||
void initializeGame() {
|
int initializeGame() {
|
||||||
/* Initialize window settings with ncurses */
|
/* Initialize window settings with ncurses */
|
||||||
initscr();
|
initscr();
|
||||||
cbreak();
|
cbreak();
|
||||||
noecho();
|
noecho();
|
||||||
keypad(stdscr, TRUE);
|
keypad(stdscr, TRUE);
|
||||||
curs_set(0);
|
curs_set(0);
|
||||||
|
|
||||||
|
if (SCREEN_HEIGHT > LINES || SCREEN_WIDTH > COLS) {
|
||||||
|
endwin();
|
||||||
|
fprintf(stderr, "ERROR: The terminal window needs to be larger.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
nodelay(stdscr, TRUE);
|
nodelay(stdscr, TRUE);
|
||||||
getmaxyx(stdscr, terminalRows, terminalCols);
|
getmaxyx(stdscr, terminalRows, terminalCols);
|
||||||
|
|
||||||
startY = (terminalRows - SCREEN_HEIGHT) / 2;
|
startY = (terminalRows - SCREEN_HEIGHT) / 2;
|
||||||
startX = (terminalCols - SCREEN_WIDTH) / 2;
|
startX = (terminalCols - SCREEN_WIDTH) / 2;
|
||||||
|
|
||||||
|
@ -470,6 +476,7 @@ void initializeGame() {
|
||||||
apple = startApple();
|
apple = startApple();
|
||||||
|
|
||||||
run();
|
run();
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Starting point of the game */
|
/* Starting point of the game */
|
||||||
|
|
Loading…
Reference in a new issue