From f37af51671e23c67610cc6a33ad1ff88e9abb4ca Mon Sep 17 00:00:00 2001 From: Matti Date: Wed, 13 Nov 2024 22:49:44 +0100 Subject: [PATCH] Bugfix, 0 correct doesnt end the game --- Aufg5/Mastermind.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/Aufg5/Mastermind.cpp b/Aufg5/Mastermind.cpp index 2f4ec96..4fb0f72 100644 --- a/Aufg5/Mastermind.cpp +++ b/Aufg5/Mastermind.cpp @@ -40,8 +40,9 @@ std::vector generateSecretCode(int digits, int optionsPerDigit) { return secretCode; } -std::vector getCodeGuessFromConsole(int codeLength) { +std::vector getCodeGuessFromConsole(int codeLength, int livesRemaining) { std::cout << "Have a Guess!" << std::endl; + std::cout << "You have " << livesRemaining << " more Attempts before you will be roasted" << std::endl; std::vector guess; @@ -104,25 +105,25 @@ int countMatches(std::vector &v1, std::vector &v2) { } void Aufg5Main() { - int optionsPerDigit = 4; - int codeLength = 4; - int livesRemaining = 5; + int optionsPerDigit = 99; + int codeLength = 1; + int livesRemaining = 2; std::cout << optionsPerDigit << " options per Digit" << std::endl; std::cout << codeLength << " Code Length" << std::endl; std::cout << livesRemaining << " Lives Remaining" << std::endl; + std::cout << "======================================" << std::endl; std::vector SecretCode = generateSecretCode(codeLength, optionsPerDigit); std::cout << "I have locked the door with a secret Code, you will never be able to figure it out!!" << std::endl; // printAllStringsInVector(SecretCode); - int perfectCounter = 1; - while (perfectCounter && livesRemaining) { - std::vector guess = getCodeGuessFromConsole(codeLength); + while (livesRemaining) { + std::vector guess = getCodeGuessFromConsole(codeLength, livesRemaining); - perfectCounter = countPefectMatches(guess, SecretCode); + int perfectCounter = countPefectMatches(guess, SecretCode); std::cout << "correct were: " << countMatches(guess, SecretCode) << std::endl; - std::cout << "perfect were: " << perfectCounter << std::endl; + std::cout << "perfect were: " << perfectCounter << std::endl << std::endl; livesRemaining--;