Skip to content

Instantly share code, notes, and snippets.

@bonjourmauko
Last active December 26, 2015 08:28
Show Gist options
  • Save bonjourmauko/7122180 to your computer and use it in GitHub Desktop.
Save bonjourmauko/7122180 to your computer and use it in GitHub Desktop.
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