Last active
December 26, 2015 08:28
-
-
Save bonjourmauko/7122180 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const WORD_LEN = 8; | |
class Hangman { | |
Hangman() { | |
rounds = 0; | |
charsguessed = 0; | |
generateWord(); | |
} | |
private: | |
char word[WORD_LEN]; | |
int rounds; | |
int charsguessed; | |
public: | |
virtual ~Hangman(); | |
generateWord(); | |
bool checkChar(unsigned int index, char input); | |
doPlay(); | |
} | |
Hangman::generateWord() | |
{ | |
size_t wlen = sizeof word; | |
for (int i=0;i<wlen;i++) | |
word[i] = rand() % 220 + 33; | |
} | |
bool Hangman::checkChar(unsigned int index, char input) | |
{ | |
if (index > WORD_LEN - 1) | |
return false; | |
return !!(input == word[index]); | |
} | |
doPlay() | |
{ | |
generateWord(); | |
char input; | |
while(charsguessed < WORD_len -1 || rounds < 17) | |
{ | |
input = getInput(); | |
guesses = 0; | |
for (int i=0;i<wlen;i++) | |
guesses += checkChar(i, input); | |
charsguessed += guesses; | |
rounds++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment