Now that you have heard my excuse here is the function I used to check if the user was correct or not. String manipulation is a powerful but hard to follow thing. To understand the code you need to know what the variables are currently storing.
currentProgress looks something like this "*a*a*a*".
currentWord looks something like this "bananas".
and guessedWord is a single character that the user entered that was passed to the function using guessWord(userinput)
// This function checks for every occurance of the guessed character. Returns true if char
// is found even once. returns false if it isn't. This also update current progress and sets the
// stars to the letter they should be if that letter is the guessedWord.
bool hmGame::guessWord(char guessedWord) {
size_t found;
found = gameDict.currentWord.find(guessedWord) ;
if(found!=string::npos){
while(found!=string::npos){
gameDict.currentProgress.replace(found,1,1,guessedWord) ;
found = gameDict.currentWord.find(guessedWord,found+1) ;
}
return true ;
} else {
cout << "Incorrect Guess !" << endl << endl ;
return false ;
}
}
- A. R. McGowan.
learn the code, don't steal it
No comments:
Post a Comment