diff --git a/hangman.c b/hangman.c index 07385d0..1458784 100644 --- a/hangman.c +++ b/hangman.c @@ -205,15 +205,39 @@ 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; + if (gs->wordLength * 2 > gs->maxx - LINEBREAK) { + /* The word will be longer then the max. linesize with offset. */ + rows = 2; + while (1) { + if ((gs->wordLength * 2) / rows < gs->maxx - LINEBREAK) { + /* splitted the word into equal sizes and found + the right amount of rows. */ + break; + } + rows++; + } + tempstartpos = xcounter = gs->centerx - (gs->wordLength / rows); + + } for (i = startpos; i < startpos + (gs->wordLength * 2); i++) { + if (xcounter >= gs->centerx + (gs->wordLength / rows)) { + /* end of the current row. Next line and revert the x to start */ + ycounter++; + xcounter = tempstartpos; + } if (switchspace) { /* this will place a space */ - mvprintw(gs->centery, i, " "); + mvprintw(gs->centery + ycounter, xcounter, " "); switchspace = 0; } else { - mvprintw(gs->centery, i, "%c", gs->currentWord[wordpos++]); + mvprintw(gs->centery + ycounter, xcounter, "%c", gs->currentWord[wordpos++]); switchspace = 1; } + xcounter++; } refresh(); } diff --git a/hangman.h b/hangman.h index 75e42fe..abe4965 100644 --- a/hangman.h +++ b/hangman.h @@ -4,6 +4,7 @@ #define ALPHABET 26 #define ALPHABET_NUM 36 #define ANIM_DURATION 1 +#define LINEBREAK 8 //Linebreak offset /* Data structures */ typedef struct { diff --git a/makefile b/makefile index c112925..1f9bdf0 100644 --- a/makefile +++ b/makefile @@ -3,7 +3,7 @@ VERSION = 1.0 CC = gcc -CFLAGS = -Wall -g -D_REENTRANT -DVERSION=\"$(VERSION)\" +CFLAGS = -Wall -g -O3 -D_REENTRANT -DVERSION=\"$(VERSION)\" #LDFLAGS = -lm -lpthread `gtk-config --cflags` `gtk-config --libs` -lgthread LDFLAGS = -lncurses