From c703bd17dd2b0abbb34977c63db29b6be1e94637 Mon Sep 17 00:00:00 2001 From: structix Date: Sat, 6 May 2017 23:27:13 +0200 Subject: [PATCH] Guess Word input is now limited to MAXWORDLENGTH; Clean up #14 --- hangman.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/hangman.c b/hangman.c index 1458784..1a565aa 100644 --- a/hangman.c +++ b/hangman.c @@ -139,7 +139,7 @@ void initGuessWord(game_state *gs, char *filename) { if (strlen(filename) == 0) { /* Manual input */ curs_set(1); - getstr(gs->guessWord); + getnstr(gs->guessWord, MAXWORDLENGTH - 1); /* Reads the guessWord with a limit */ curs_set(0); } else { /* Random line from file */ @@ -205,10 +205,11 @@ void drawGuessWord(game_state *gs) { int startpos = gs->centerx - gs->wordLength; int i, wordpos = 0; int switchspace = 0; - int xcounter = startpos; - int ycounter = 0; - int tempstartpos = startpos, deltawordlength = gs->wordLength; - int rows = 1; + int xcounter = startpos; /* counter of the x position on screen */ + int ycounter = 0; /* counter of the y position on sceen (row) */ + int tempstartpos = startpos; /* the calculated start position to draw the characters */ + int rows = 1; /* number of rows */ + if (gs->wordLength * 2 > gs->maxx - LINEBREAK) { /* The word will be longer then the max. linesize with offset. */ rows = 2;