Added start screen; Cursor enabled on Word input
This commit is contained in:
15
hangman.c
15
hangman.c
@@ -2,7 +2,7 @@
|
|||||||
#include "hangman.h"
|
#include "hangman.h"
|
||||||
#include <stdlib.h> //atexit
|
#include <stdlib.h> //atexit
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h> //tolower
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
/* Initialization */
|
/* Initialization */
|
||||||
@@ -14,7 +14,10 @@ int main(void) {
|
|||||||
gs->allowedMoves = DEFAULTTRIES;
|
gs->allowedMoves = DEFAULTTRIES;
|
||||||
gs->moves = 0;
|
gs->moves = 0;
|
||||||
gs->guesses = 0;
|
gs->guesses = 0;
|
||||||
|
|
||||||
|
/* Show the start screen */
|
||||||
curs_set(0);
|
curs_set(0);
|
||||||
|
showStartScreen(gs);
|
||||||
|
|
||||||
/* start game */
|
/* start game */
|
||||||
initGuessWord(gs);
|
initGuessWord(gs);
|
||||||
@@ -32,6 +35,14 @@ void quitProgram(void) {
|
|||||||
endwin();
|
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) {
|
void updateScreen(game_state *gs) {
|
||||||
mvprintw(1, 1, "Remaining wrong guesses: %i", (gs->allowedMoves - gs->moves));
|
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) {
|
void initGuessWord(game_state *gs) {
|
||||||
int i;
|
int i;
|
||||||
mvprintw(1, 1, "Please enter your word: ");
|
mvprintw(1, 1, "Please enter your word: ");
|
||||||
|
curs_set(1);
|
||||||
getstr(gs->guessWord);
|
getstr(gs->guessWord);
|
||||||
|
curs_set(0);
|
||||||
toLowerCase(gs->guessWord);
|
toLowerCase(gs->guessWord);
|
||||||
gs->wordLength = strlen(gs->guessWord);
|
gs->wordLength = strlen(gs->guessWord);
|
||||||
for (i = 0; i < gs->wordLength; i++) {
|
for (i = 0; i < gs->wordLength; i++) {
|
||||||
|
@@ -34,3 +34,4 @@ int stackWrongCharacter(game_state *gs, char wrongchar);
|
|||||||
int checkWin(game_state *gs);
|
int checkWin(game_state *gs);
|
||||||
void printGameStats(game_state *gs);
|
void printGameStats(game_state *gs);
|
||||||
void toLowerCase(char *str);
|
void toLowerCase(char *str);
|
||||||
|
void showStartScreen(game_state *gs);
|
||||||
|
Reference in New Issue
Block a user