Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,19 +47,16 @@ EGuessStatus FBullCowGame::CheckGuessValidity(FString Guess) const | |
|
||
|
||
// receives a VALID guess, incriments turn, and returns count | ||
FBullCowCount FBullCowGame::SubmitGuess(FString Guess) | ||
FBullCowCount FBullCowGame::SubmitValidGuess(FString Guess) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
SuperWig
|
||
{ | ||
// incriment the turn number | ||
MyCurrentTry++; | ||
|
||
// setup a return variable | ||
FBullCowCount BullCowCount; | ||
|
||
// loop through all letters in the guess | ||
int32 HiddenWordLength = MyHiddenWord.length(); | ||
for (int32 MHWChar = 0; MHWChar < HiddenWordLength; MHWChar++) { | ||
// compare letters against the hidden word | ||
for (int32 GChar = 0; GChar < HiddenWordLength; GChar++) { | ||
int32 WordLength = MyHiddenWord.length(); // assuming same length as guess | ||
|
||
// loop through all letters in the hidden word | ||
for (int32 MHWChar = 0; MHWChar < WordLength; MHWChar++) { | ||
// compare letters against the guess | ||
for (int32 GChar = 0; GChar < WordLength; GChar++) { | ||
// if they match then | ||
if (Guess[GChar] == MyHiddenWord[MHWChar]) { | ||
if (MHWChar == GChar) { // if they're in the same place | ||
|
6 comments
on commit 775f950
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for including this :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Edit: my fault! I had a scoping mistake.. and didn't remove the declaration of "Status" in the do while loop of GetValidGuess... so I always had a "Invalid_Status" while returning Guess at the bottom of the function.
If I just make a break on default I won't get out of the loop when I enter a correct isogram. It will always ask me for "Please enter Try 1...". And yes I added "return Guess" on and the bottom of the function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, I made a mistake and I don't understand what it wants me to change, is is saying that it is missing a definition of Guess. The Guess at the bottom is underlined in red. The only thing I had to change was transfer the return Guess; to the bottom.
FText GetValidGuess()
{
EGuessStatus Status = EGuessStatus::Invalid_Status;
do {
FText Guess = "";
// get a guess from the player
int32 CurrentTry = BCGame.GetCurrentTry();
std::cout << "Try "<< CurrentTry << ". Enter your guess ";
std::getline(std::cin, Guess);
// check status and give feedback
Status = BCGame.CheckGuessValidity(Guess);
switch (Status) {
case EGuessStatus::Wrong_Length:
std::cout << "Plaease enter a " << BCGame.GetHiddenWordLenght() << " letter word.\n";
break;
case EGuessStatus::Not_Isogram:
std::cout << "Please enter a word without repeating letters. \n";
break;
case EGuessStatus::Not_Lowercase:
std::cout << "Please enter all lowercase letters.\n";
break;
default:
//assume the guess is valid
break;
}
std::cout << std::endl;
} while (Status != EGuessStatus::OK); //keep looping until we get no errors
return Guess;
}
Help!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Cloyde
Try to declarate Guess outside the do while loop, because you declarated it inside, so it's not valid outside the loop where you try to return its value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jeah I found the conclusion, it was all about the hierarchy, just what you mean I think.
Thx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have not made any changes to the code other than what has been in the videos. When I renamed SubmitGuess to SubmitValidGuess, that somehow made the try number stop incrementing. I'm extremely confused as the cause and effect have little to no correlation?
`// receives a VALID guess, increments turn, and returns cout
FBullCowCount FBullCowGame::SubmitValidGuess(FString Guess)
{
// increment the try number
MyCurrentTry++;
// setup a return variable
FBullCowCount BullCowCount;
// loop through all letters in the guess
int32 WordLength = MyHiddenWord.length();
for (int32 MHWChar = 0; MHWChar < WordLength; MHWChar++){
// compare letters against the hidden guess
for (int32 GChar = 0; GChar < WordLength; GChar++) {
// if they match then
if (Guess[GChar] == MyHiddenWord[MHWChar]) {
if (MHWChar == GChar) { //if they're in the same place
BullCowCount.Bulls++; //increment bulls
}
else {
BullCowCount.Cows++; //increment cows
}
}
}
}
return BullCowCount;
}
`
This is the code for submitting a valid guess.
I do not understand how to do the conection between the (Fstring Guess) and the MyHiddenWord.
here we have :
Guess[GChar]
how does the program knows that we are refering to the MyHiddenWord.??