Linebreak if the word is too long for one line #14

This commit is contained in:
2017-05-06 22:53:01 +02:00
parent acad4c7495
commit c29a1e914c
3 changed files with 28 additions and 3 deletions

View File

@@ -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();
}