From 35a05a634ea6298c0899840da1f1ffe2604e1642 Mon Sep 17 00:00:00 2001 From: JirR02 Date: Sun, 6 Oct 2024 22:51:31 +0200 Subject: [PATCH] Project 2 Final --- Projekt_2/main.cpp | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/Projekt_2/main.cpp b/Projekt_2/main.cpp index 9c95cbb..3cb805b 100644 --- a/Projekt_2/main.cpp +++ b/Projekt_2/main.cpp @@ -7,6 +7,7 @@ using std::string; int main() { // Word the player needs to guess (randomly selected) string word = chooseWord(); + //string word = "success"; // Initialise the "uncovered" word that is shown to the player: the uncovered // word is obtained by replacing each letter from the original word (variable @@ -31,18 +32,37 @@ int main() { /** Part 1: input next guess **********************************************/ char guess = '\0'; // 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 *******************************************/ bool found = false; // 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 *********************************************/ // 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;