Skip to content

Instantly share code, notes, and snippets.

@FMudanyali
Last active September 30, 2020 13:06
Show Gist options
  • Save FMudanyali/46a4d69655c48341eeb84ade5cfd9ff1 to your computer and use it in GitHub Desktop.
Save FMudanyali/46a4d69655c48341eeb84ade5cfd9ff1 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <ncurses.h>
void main(){
srand(time(NULL));
int a;
initscr();
noecho();
game:
printw("Enter your word: ");
char word[64];
getstr(word);
char hidden_word[(int)strlen(word)];
memset(hidden_word, '-', sizeof(hidden_word));
hidden_word[strlen(word)] = '\0'; //end the array with NULL terminator.
char decision;
raw();
for(int i = 0; i < strlen(word); ++i){
clear();
refresh();
printw("Current word: %s, %ld characters, %ld points for guessing.\n", hidden_word, strlen(word), (strlen(word) - i) * 100);
printw("1 to get letter, 9 to reveal.\n");
readkey:
decision = getch();
switch(decision){
case '1':
reveal:
a = rand()%strlen(word);
if (hidden_word[a] == word[a]) goto reveal;
hidden_word[a] = word[a];
break;
case '9':
i = strlen(word);
break;
default:
printw("what the hell?\n");
goto readkey;
}
}
clear();
if(decision == '1') printw("The word was %s, you got 0 points.\n", word);
else printw("The word was %s.\n", word);
printw("Wanna play again? Y/N?\n");
endscreen:
decision = getch();
switch(decision){
case 'y':
goto game;
case 'n':
endwin();
break;
default:
printw("what the hell?\n");
goto endscreen;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment