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 startpos = gs->centerx - gs->wordLength;
|
||||||
int i, wordpos = 0;
|
int i, wordpos = 0;
|
||||||
int switchspace = 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++) {
|
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) {
|
if (switchspace) {
|
||||||
/* this will place a space */
|
/* this will place a space */
|
||||||
mvprintw(gs->centery, i, " ");
|
mvprintw(gs->centery + ycounter, xcounter, " ");
|
||||||
switchspace = 0;
|
switchspace = 0;
|
||||||
} else {
|
} else {
|
||||||
mvprintw(gs->centery, i, "%c", gs->currentWord[wordpos++]);
|
mvprintw(gs->centery + ycounter, xcounter, "%c", gs->currentWord[wordpos++]);
|
||||||
switchspace = 1;
|
switchspace = 1;
|
||||||
}
|
}
|
||||||
|
xcounter++;
|
||||||
}
|
}
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
@@ -4,6 +4,7 @@
|
|||||||
#define ALPHABET 26
|
#define ALPHABET 26
|
||||||
#define ALPHABET_NUM 36
|
#define ALPHABET_NUM 36
|
||||||
#define ANIM_DURATION 1
|
#define ANIM_DURATION 1
|
||||||
|
#define LINEBREAK 8 //Linebreak offset
|
||||||
|
|
||||||
/* Data structures */
|
/* Data structures */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
2
makefile
2
makefile
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
VERSION = 1.0
|
VERSION = 1.0
|
||||||
CC = gcc
|
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 = -lm -lpthread `gtk-config --cflags` `gtk-config --libs` -lgthread
|
||||||
LDFLAGS = -lncurses
|
LDFLAGS = -lncurses
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user