diff --git a/figures.h b/figures.h new file mode 100644 index 0000000..d68bfba --- /dev/null +++ b/figures.h @@ -0,0 +1,18 @@ +const char base_figure[6][8] = {{"======="},\ + {"I "},\ + {"I "},\ + {"I "},\ + {"I "},\ + {"I\\ "}}; + +const char figure[6][5] = {{" O "},\ + {" I "},\ + {"\\I "},\ + {"\\I/"},\ + {"/ "},\ + {"/ \\"}}; + + +/* This array represents the layers where the strings + of the current stage(array index) should be printed*/ +const int stages[] = {0, 1, 1, 1, 2, 2}; \ No newline at end of file diff --git a/hangman.c b/hangman.c index 068c4d4..6e37146 100644 --- a/hangman.c +++ b/hangman.c @@ -1,4 +1,10 @@ -#include +#ifdef _WIN32 //For 32 and 64 bits + /* pdcurses include */ + #include +#else + /* Linux ncurses include */ + #include +#endif #include "hangman.h" #include //atexit #include @@ -7,6 +13,11 @@ #include //time(null) #include "prng.h" #include //usleep +#include "figures.h" + + + + int main(int argc, char **argv) { @@ -72,9 +83,9 @@ int main(int argc, char **argv) { /* start game */ initGuessWord(gs, filename); initAlphabet(gs); - drawAlphabet(gs); + drawAlphabet(gs, 0); + drawFigure(gs); startGame(gs); - getch(); free(gs); @@ -152,30 +163,32 @@ void initGuessWord(game_state *gs, char *filename) { void initAlphabet(game_state *gs) { int hasNumber = 0; - int i, j; + int i; for (i = 0; i < MAXWORDLENGTH; i++) { - if (isdigit(gs->guessWord[i]) == 0) { + if (isdigit(gs->guessWord[i]) == 1) { hasNumber = 1; break; } } - gs->alphabet = malloc(sizeof(char) * hasNumber ? ALPHABET : ALPHABET_NUM); - - for (i = 'a', j = 0; i <= 'z'; i++, j++) { - gs->alphabet[j] = i; - } + strcpy(gs->alphabet, "abcdefghijklmnopqrstuvwxyz"); + if (hasNumber) { - j++; - for (i = 0; i < 10; i++, j++) { - gs->alphabet[j] = i; - } + strcat(gs->alphabet, "1234567890"); } - } -void drawAlphabet(game_state *gs) { +void drawAlphabet(game_state *gs, char usedchar) { int start = centerDiff(gs->centerx, gs->alphabet); + int i; + if (usedchar != 0) { /* 0 is used for initialization */ + for (i = 0; i < (int)strlen(gs->alphabet); i++) { + if (gs->alphabet[i] == usedchar) { + gs->alphabet[i] = '_'; + break; + } + } + } mvprintw(1, start, "%s", gs->alphabet); } @@ -247,6 +260,7 @@ int fillCurrentWord(game_state *gs, char validchar) { gs->currentWord[i] = validchar; } } + drawAlphabet(gs, validchar); return 1; } else { return 0; @@ -263,7 +277,8 @@ int stackWrongCharacter(game_state *gs, char wrongchar) { if (!alreadyUsed) { gs->wrongCharacters[strlen(gs->wrongCharacters)] = wrongchar; - return 1; + drawAlphabet(gs, wrongchar); + return 1; } else { return 0; } @@ -373,5 +388,18 @@ void trollHitScreen(game_state *gs, int hits) { } } +void drawFigure(game_state *gs) { + int row = 6; + int length = 10; + int i; + static init = 0; + if (init) { + for (i = 0; i < row; i++) { + mvprintw(i, gs->maxx - length - 1, "%s", base_figure[i]); + } + init = 1; + } + +} diff --git a/hangman.h b/hangman.h index 823b602..a11125b 100644 --- a/hangman.h +++ b/hangman.h @@ -33,7 +33,7 @@ void updateScreen(game_state *gs); void initCoordinates(game_state *gs); void initGuessWord(game_state *gs, char *filename); void initAlphabet(game_state *gs); -void drawAlphabet(game_state *gs); +void drawAlphabet(game_state *gs, char usedchar); void drawGuessWord(game_state *gs); int playerInput(game_state *gs); int fillCurrentWord(game_state *gs, char validchar); @@ -47,3 +47,4 @@ void showHelp(game_state *gs); int centerDiff(int coordinate, char *str); void readRandomLine(char *file, char *result); void trollHitScreen(game_state *gs, int hits); +void drawFigure(game_state *gs); \ No newline at end of file diff --git a/makefile_mingw b/makefile_mingw new file mode 100644 index 0000000..0437390 --- /dev/null +++ b/makefile_mingw @@ -0,0 +1,20 @@ +#Infos: http://www.ijon.de/comp/tutorials/makefile.html + + +VERSION = 1.0 +CC = gcc +CFLAGS = -Wall -Wextra -O3 -D_REENTRANT -DVERSION=\"$(VERSION)\" +#LDFLAGS = -lm -lpthread `gtk-config --cflags` `gtk-config --libs` -lgthread +LDFLAGS = -lpdcurses + +OBJ = hangman.o prng.o + +all: $(OBJ) + $(CC) $(CFLAGS) -o hangman $(OBJ) $(LDFLAGS) + +%.o: %.c + $(CC) $(CFLAGS) -c $< + +.PHONY: clean +clean: + rm -r *.o