Working
This commit is contained in:
parent
e2727d343d
commit
87d896049d
@ -151,9 +151,8 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
std::vector<std::string> dictionary = readDictionary(wordLength);
|
||||
std::vector<char> guessProgress(wordLength, '-');
|
||||
std::cout << "So far: ";
|
||||
printContainer(guessProgress);
|
||||
std::string guessProgress(wordLength, '-');
|
||||
std::cout << "Word: " << guessProgress << std::endl;
|
||||
|
||||
std::vector<char> guessedChars;
|
||||
size_t wrongAttempts = 0;
|
||||
@ -186,6 +185,14 @@ int main(int argc, char *argv[]) {
|
||||
});
|
||||
currentlyThinkingOf = biggestEntry->first;
|
||||
dictionary = biggestEntry->second;
|
||||
}else{
|
||||
std::string &word = dictionary[0];
|
||||
|
||||
for (size_t i = 0; i < word.size(); i++) {
|
||||
if (word[i] != guess)
|
||||
continue;
|
||||
currentlyThinkingOf[i] = guess;
|
||||
}
|
||||
}
|
||||
|
||||
if (showRemainingWords) {
|
||||
@ -208,11 +215,12 @@ int main(int argc, char *argv[]) {
|
||||
wrongAttempts++;
|
||||
}
|
||||
|
||||
std::cout << "So far: ";
|
||||
printContainer(guessProgress); // Display the current guessed word state
|
||||
|
||||
guessedChars.push_back(guess);
|
||||
|
||||
std::cout << "Used letters: ";
|
||||
printContainer(guessedChars, " ");
|
||||
std::cout << "Word: " << currentlyThinkingOf << std::endl;
|
||||
|
||||
// Check if all the characters in the final word have been guessed
|
||||
hasWon = std::all_of(guessProgress.begin(), guessProgress.end(),
|
||||
[](char c) { return c != '-'; });
|
||||
@ -221,7 +229,7 @@ int main(int argc, char *argv[]) {
|
||||
} while (!hasWon && !hasLost);
|
||||
|
||||
const char *out = hasWon ? "congratulations! You've won! 🎉" : "you lost.";
|
||||
std::cout << "Well, the word was '" << dictionary[0] << "', " << out
|
||||
std::cout << "The word was '" << dictionary[0] << "', " << out
|
||||
<< std::endl;
|
||||
|
||||
return 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user