Linebreak if the word is too long for one line #14
This commit is contained in:
28
hangman.c
28
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();
|
||||
}
|
||||
|
Reference in New Issue
Block a user