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

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