From 6df0af4c2f31ff8c790d122164e89a5ba10e373d Mon Sep 17 00:00:00 2001 From: structix Date: Mon, 1 May 2017 20:15:30 +0200 Subject: [PATCH] Added start screen; Cursor enabled on Word input --- hangman.c | 17 +++++++++++++++-- hangman.h | 1 + 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/hangman.c b/hangman.c index cfbd046..78c88ea 100644 --- a/hangman.c +++ b/hangman.c @@ -2,7 +2,7 @@ #include "hangman.h" #include //atexit #include -#include +#include //tolower int main(void) { /* Initialization */ @@ -14,8 +14,11 @@ int main(void) { gs->allowedMoves = DEFAULTTRIES; gs->moves = 0; gs->guesses = 0; - curs_set(0); + /* Show the start screen */ + curs_set(0); + showStartScreen(gs); + /* start game */ initGuessWord(gs); noecho(); /* Don't show the player input */ @@ -32,6 +35,14 @@ void quitProgram(void) { endwin(); } +void showStartScreen(game_state *gs) { + mvprintw(gs->centery - 1, gs->centerx - 15, "Welcome to hangman in ncurses."); + mvprintw(gs->centery, gs->centerx - 5, "Have fun!"); + mvprintw(gs->centery + 1, gs->centerx - 17, "https://gitlab.com/STRUCTiX/hangman"); + refresh(); + getch(); + clear(); +} void updateScreen(game_state *gs) { mvprintw(1, 1, "Remaining wrong guesses: %i", (gs->allowedMoves - gs->moves)); @@ -50,7 +61,9 @@ void initCoordinates(game_state *gs) { void initGuessWord(game_state *gs) { int i; mvprintw(1, 1, "Please enter your word: "); + curs_set(1); getstr(gs->guessWord); + curs_set(0); toLowerCase(gs->guessWord); gs->wordLength = strlen(gs->guessWord); for (i = 0; i < gs->wordLength; i++) { diff --git a/hangman.h b/hangman.h index 5c56182..a03e66a 100644 --- a/hangman.h +++ b/hangman.h @@ -34,3 +34,4 @@ int stackWrongCharacter(game_state *gs, char wrongchar); int checkWin(game_state *gs); void printGameStats(game_state *gs); void toLowerCase(char *str); +void showStartScreen(game_state *gs);