makefile for mingw #10; drawAlphabet #8

This commit is contained in:
2017-05-05 17:09:53 +02:00
parent c664c70a37
commit 1a24486ec3
4 changed files with 85 additions and 18 deletions

18
figures.h Normal file
View File

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

View File

@@ -1,4 +1,10 @@
#include <ncurses.h>
#ifdef _WIN32 //For 32 and 64 bits
/* pdcurses include */
#include <curses.h>
#else
/* Linux ncurses include */
#include <ncurses.h>
#endif
#include "hangman.h"
#include <stdlib.h> //atexit
#include <string.h>
@@ -7,6 +13,11 @@
#include <time.h> //time(null)
#include "prng.h"
#include <unistd.h> //usleep
#include "figures.h"
int main(int argc, char **argv) {
@@ -72,10 +83,10 @@ 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);
return 0;
@@ -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);
strcpy(gs->alphabet, "abcdefghijklmnopqrstuvwxyz");
for (i = 'a', j = 0; i <= 'z'; i++, j++) {
gs->alphabet[j] = i;
}
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,6 +277,7 @@ int stackWrongCharacter(game_state *gs, char wrongchar) {
if (!alreadyUsed) {
gs->wrongCharacters[strlen(gs->wrongCharacters)] = wrongchar;
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;
}
}

View File

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

20
makefile_mingw Normal file
View File

@@ -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