Added winch handler. Alphabet and figure are a buggy

This commit is contained in:
2017-11-27 19:59:26 +01:00
parent 3440226ad3
commit 7adcaf4d72

View File

@@ -13,8 +13,16 @@
#include "prng.h" #include "prng.h"
#include <unistd.h> //usleep #include <unistd.h> //usleep
#include "figures.h" #include "figures.h"
#include <signal.h>
void handle_winch(int sig) {
/* This function handles the console resizing */
endwin();
clear();
refresh();
}
int main(int argc, char **argv) { int main(int argc, char **argv) {
const char *short_options = "w:hf:ct"; const char *short_options = "w:hf:ct";
@@ -35,6 +43,13 @@ int main(int argc, char **argv) {
/* Initialization */ /* Initialization */
initscr(); initscr();
atexit(quitProgram); atexit(quitProgram);
//Windows resize handler
struct sigaction sa;
memset(&sa, 0, sizeof(struct sigaction));
sa.sa_handler = handle_winch;
sigaction(SIGWINCH, &sa, NULL);
start_color(); //Enables multi color mode start_color(); //Enables multi color mode
/* Initialize custom color pairs */ /* Initialize custom color pairs */
@@ -105,6 +120,7 @@ void startGame(game_state *gs, hitfeed *hf) {
noecho(); /* Don't show the player input */ noecho(); /* Don't show the player input */
time(&gs->startTime); time(&gs->startTime);
while (checkWin(gs)) { while (checkWin(gs)) {
initCoordinates(gs); //Necessary for window resizing
updateScreen(gs); updateScreen(gs);
playerInput(gs, hf); playerInput(gs, hf);
printHitFeed(gs, hf); printHitFeed(gs, hf);