Project 2 Final
This commit is contained in:
@@ -7,6 +7,7 @@ using std::string;
|
|||||||
int main() {
|
int main() {
|
||||||
// Word the player needs to guess (randomly selected)
|
// Word the player needs to guess (randomly selected)
|
||||||
string word = chooseWord();
|
string word = chooseWord();
|
||||||
|
//string word = "success";
|
||||||
|
|
||||||
// Initialise the "uncovered" word that is shown to the player: the uncovered
|
// Initialise the "uncovered" word that is shown to the player: the uncovered
|
||||||
// word is obtained by replacing each letter from the original word (variable
|
// word is obtained by replacing each letter from the original word (variable
|
||||||
@@ -31,18 +32,37 @@ int main() {
|
|||||||
/** Part 1: input next guess **********************************************/
|
/** Part 1: input next guess **********************************************/
|
||||||
char guess = '\0';
|
char guess = '\0';
|
||||||
// TODO: replace the following line with your implementation
|
// TODO: replace the following line with your implementation
|
||||||
PART1_readCharacter(guess);
|
//PART1_readCharacter(guess);
|
||||||
|
std::cout << "Your guess: ";
|
||||||
|
std::cin >> guess;
|
||||||
|
|
||||||
|
|
||||||
/** Part 2: update working copy *******************************************/
|
/** Part 2: update working copy *******************************************/
|
||||||
bool found = false;
|
bool found = false;
|
||||||
// TODO: replace the following line with your implementation
|
// TODO: replace the following line with your implementation
|
||||||
PART2_updateWorkingCopy(word, guess, workingCopy, found);
|
//PART2_updateWorkingCopy(word, guess, workingCopy, found);
|
||||||
|
for (int i = 0; i != word.length(); i++) {
|
||||||
|
if (guess == word.at(i)) {
|
||||||
|
found = true;
|
||||||
|
workingCopy.at(i) = guess;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** Part 3: update game state *********************************************/
|
/** Part 3: update game state *********************************************/
|
||||||
// TODO: replace the following line with your implementation
|
// TODO: replace the following line with your implementation
|
||||||
PART3_updateGameState(word, workingCopy, found, maxWrongGuesses, done, wrongGuesses);
|
//PART3_updateGameState(word, workingCopy, found, maxWrongGuesses, done, wrongGuesses);
|
||||||
|
if (workingCopy == word) {
|
||||||
|
done = true;
|
||||||
|
printYouWon(word);
|
||||||
|
} else if (found == false) {
|
||||||
|
wrongGuesses += 1;
|
||||||
|
}
|
||||||
|
if (wrongGuesses == maxWrongGuesses) {
|
||||||
|
done = true;
|
||||||
|
printYouLost(word);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Reference in New Issue
Block a user