From fd67e95fe53acdc96c409ae0b1279df5ed546176 Mon Sep 17 00:00:00 2001 From: Matt Cantin Date: Mon, 13 Oct 2025 16:21:18 -0600 Subject: [PATCH 01/19] Added ASCII art to game launcher --- .idea/workspace.xml | 51 +++++++++++++++++++++++++++++++++++++++++++++ GameLauncher.java | 6 +++++- 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 .idea/workspace.xml diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..0ff23f0 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + 1760390460371 + + + + \ No newline at end of file diff --git a/GameLauncher.java b/GameLauncher.java index d8285c3..86560f3 100644 --- a/GameLauncher.java +++ b/GameLauncher.java @@ -96,7 +96,11 @@ private static List registerGames() { protected void run() { boolean running = true; while (running) { - System.out.println("\n=== Console Arcade Hub ==="); + System.out.println( +"/ \\__/|/ __// \\ /|/ \\ /\\\n" ++ "| |\\/||| \\ | |\\ ||| | ||\n" ++ "| | ||| /_ | | \\||| \\_/|\n" ++ "\\_/ \\|\\____\\\\_/ \\|\\____/"); for (int i = 0; i < this.games.size(); i++) { System.out.printf("%d. %s\n", i + 1, From eb6b4d5dbcd48f547d610e001a59be65006ce5ea Mon Sep 17 00:00:00 2001 From: Matt Date: Tue, 14 Oct 2025 07:50:01 -0600 Subject: [PATCH 02/19] Delete .idea directory Signed-off-by: Matt --- .idea/workspace.xml | 51 --------------------------------------------- 1 file changed, 51 deletions(-) delete mode 100644 .idea/workspace.xml diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index 0ff23f0..0000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - 1760390460371 - - - - \ No newline at end of file From 734cbaa2a8dd6f278d13019636c67ad64b3578d1 Mon Sep 17 00:00:00 2001 From: Matt Date: Tue, 14 Oct 2025 07:50:18 -0600 Subject: [PATCH 03/19] Update .gitignore Signed-off-by: Matt --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 6529974..44f1ce5 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ history.dat reports/ doc/ +.idea/ # Java Section *.class From dcef9e23c0f098987daf3ffe277cbed574c7a1fc Mon Sep 17 00:00:00 2001 From: Matt Date: Tue, 14 Oct 2025 12:57:38 -0600 Subject: [PATCH 04/19] Update .gitignore Signed-off-by: Matt --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 6529974..44f1ce5 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ history.dat reports/ doc/ +.idea/ # Java Section *.class From 8bb5490b3a3f11be272ceeb845a04a12bb5e02ec Mon Sep 17 00:00:00 2001 From: Matt Cantin Date: Wed, 15 Oct 2025 14:54:27 -0600 Subject: [PATCH 05/19] Made text more readable --- GameLauncher.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/GameLauncher.java b/GameLauncher.java index 86560f3..dd7e109 100644 --- a/GameLauncher.java +++ b/GameLauncher.java @@ -96,11 +96,14 @@ private static List registerGames() { protected void run() { boolean running = true; while (running) { + System.out.println("\n=== Console Game Hub ===\n"); System.out.println( -"/ \\__/|/ __// \\ /|/ \\ /\\\n" -+ "| |\\/||| \\ | |\\ ||| | ||\n" -+ "| | ||| /_ | | \\||| \\_/|\n" -+ "\\_/ \\|\\____\\\\_/ \\|\\____/"); + " __ __ ___ _ _ _ _ \n" + + " | \\/ | __| \\| | | | |\n" + + " | |\\/| | _|| .` | |_| |\n" + + " |_| |_|___|_|\\_|\\___/ \n" + + " " + ); for (int i = 0; i < this.games.size(); i++) { System.out.printf("%d. %s\n", i + 1, From a2581d32e3d33270dde7886efa4b613375be9770 Mon Sep 17 00:00:00 2001 From: Matt Cantin Date: Wed, 15 Oct 2025 15:14:49 -0600 Subject: [PATCH 06/19] Fixed to pass tests --- GameLauncher.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/GameLauncher.java b/GameLauncher.java index dd7e109..3f1758d 100644 --- a/GameLauncher.java +++ b/GameLauncher.java @@ -98,11 +98,11 @@ protected void run() { while (running) { System.out.println("\n=== Console Game Hub ===\n"); System.out.println( - " __ __ ___ _ _ _ _ \n" + - " | \\/ | __| \\| | | | |\n" + - " | |\\/| | _|| .` | |_| |\n" + - " |_| |_|___|_|\\_|\\___/ \n" + - " " + " __ __ ___ _ _ _ _ \n" + ++ " | \\/ | __| \\| | | | |\n" ++ " | |\\/| | _|| .` | |_| |\n" ++ " |_| |_|___|_|\\_|\\___/ \n" ++ "\n" ); for (int i = 0; i < this.games.size(); i++) { System.out.printf("%d. %s\n", From 5fdb89a8e708ad7f1ec0ec1167e3074bccf9a4a3 Mon Sep 17 00:00:00 2001 From: Matt Cantin Date: Wed, 15 Oct 2025 15:15:52 -0600 Subject: [PATCH 07/19] Fixed error --- GameLauncher.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GameLauncher.java b/GameLauncher.java index 3f1758d..07f5270 100644 --- a/GameLauncher.java +++ b/GameLauncher.java @@ -98,7 +98,7 @@ protected void run() { while (running) { System.out.println("\n=== Console Game Hub ===\n"); System.out.println( - " __ __ ___ _ _ _ _ \n" + + " __ __ ___ _ _ _ _ \n" + " | \\/ | __| \\| | | | |\n" + " | |\\/| | _|| .` | |_| |\n" + " |_| |_|___|_|\\_|\\___/ \n" From e09e3e56b4c0bad91b1e0674217e0db7981cda3d Mon Sep 17 00:00:00 2001 From: Matt Cantin Date: Wed, 15 Oct 2025 15:17:31 -0600 Subject: [PATCH 08/19] Fixed checkstyle errors --- GameLauncher.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GameLauncher.java b/GameLauncher.java index 07f5270..8615ff1 100644 --- a/GameLauncher.java +++ b/GameLauncher.java @@ -98,7 +98,7 @@ protected void run() { while (running) { System.out.println("\n=== Console Game Hub ===\n"); System.out.println( - " __ __ ___ _ _ _ _ \n" +" __ __ ___ _ _ _ _ \n" + " | \\/ | __| \\| | | | |\n" + " | |\\/| | _|| .` | |_| |\n" + " |_| |_|___|_|\\_|\\___/ \n" From 119b4116a35ccef1c2cd870dc5c61b500e7894e9 Mon Sep 17 00:00:00 2001 From: Matt Cantin Date: Wed, 15 Oct 2025 15:18:38 -0600 Subject: [PATCH 09/19] Fixed checkstyle errors --- GameLauncher.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GameLauncher.java b/GameLauncher.java index 8615ff1..f827f11 100644 --- a/GameLauncher.java +++ b/GameLauncher.java @@ -96,7 +96,7 @@ private static List registerGames() { protected void run() { boolean running = true; while (running) { - System.out.println("\n=== Console Game Hub ===\n"); + System.out.println("=== Console Game Hub ===\n"); System.out.println( " __ __ ___ _ _ _ _ \n" + " | \\/ | __| \\| | | | |\n" From c20df095d8c155afbf559ef600a8eddac3078241 Mon Sep 17 00:00:00 2001 From: Matt Cantin Date: Wed, 15 Oct 2025 15:26:13 -0600 Subject: [PATCH 10/19] Fixed checkstyle errors --- GameLauncher.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GameLauncher.java b/GameLauncher.java index f827f11..400a65c 100644 --- a/GameLauncher.java +++ b/GameLauncher.java @@ -96,9 +96,9 @@ private static List registerGames() { protected void run() { boolean running = true; while (running) { - System.out.println("=== Console Game Hub ===\n"); System.out.println( -" __ __ ___ _ _ _ _ \n" +"=== Console Game Hub === \n" ++ " __ __ ___ _ _ _ _ \n" + " | \\/ | __| \\| | | | |\n" + " | |\\/| | _|| .` | |_| |\n" + " |_| |_|___|_|\\_|\\___/ \n" From 9de4ce236dc3f2627c781918715d8ac9663dc248 Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 15 Oct 2025 15:28:19 -0600 Subject: [PATCH 11/19] Remove .idea from .gitignore Removed .idea directory from gitignore. Signed-off-by: Matt --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 44f1ce5..6529974 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,6 @@ history.dat reports/ doc/ -.idea/ # Java Section *.class From c84426e54dcf74c9cc7082d682c399168d3c7158 Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 15 Oct 2025 15:29:25 -0600 Subject: [PATCH 12/19] Revert "Fixed checkstyle errors" --- GameLauncher.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/GameLauncher.java b/GameLauncher.java index 400a65c..d8285c3 100644 --- a/GameLauncher.java +++ b/GameLauncher.java @@ -96,14 +96,7 @@ private static List registerGames() { protected void run() { boolean running = true; while (running) { - System.out.println( -"=== Console Game Hub === \n" -+ " __ __ ___ _ _ _ _ \n" -+ " | \\/ | __| \\| | | | |\n" -+ " | |\\/| | _|| .` | |_| |\n" -+ " |_| |_|___|_|\\_|\\___/ \n" -+ "\n" - ); + System.out.println("\n=== Console Arcade Hub ==="); for (int i = 0; i < this.games.size(); i++) { System.out.printf("%d. %s\n", i + 1, From 01924fda49fc643c944b06d2e703e485cd931baf Mon Sep 17 00:00:00 2001 From: Erik Thompson Date: Mon, 20 Oct 2025 15:45:49 -0600 Subject: [PATCH 13/19] user story 26 Added line to display the number of remaining guesses in Jotto --- JottoGame.java | 1 + 1 file changed, 1 insertion(+) diff --git a/JottoGame.java b/JottoGame.java index f08af55..ad490b0 100644 --- a/JottoGame.java +++ b/JottoGame.java @@ -62,6 +62,7 @@ public Optional play() { int attemptsLeft = MAX_GUESSES; while (attemptsLeft > 0) { + System.out.println("You have " + attemptsLeft + " guesses remaining."); System.out.print("Enter guess: "); String guess = scanner.nextLine().trim().toUpperCase(); From 409a24369fc1b4b907789292951d25047e2f838d Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 22 Oct 2025 15:11:40 -0600 Subject: [PATCH 14/19] Revert Jotto in main branch Removed a line that prints the number of guesses remaining. Signed-off-by: Matt --- JottoGame.java | 1 - 1 file changed, 1 deletion(-) diff --git a/JottoGame.java b/JottoGame.java index ad490b0..f08af55 100644 --- a/JottoGame.java +++ b/JottoGame.java @@ -62,7 +62,6 @@ public Optional play() { int attemptsLeft = MAX_GUESSES; while (attemptsLeft > 0) { - System.out.println("You have " + attemptsLeft + " guesses remaining."); System.out.print("Enter guess: "); String guess = scanner.nextLine().trim().toUpperCase(); From 96ebc28b58df085f2bef417be2eff38115edbee8 Mon Sep 17 00:00:00 2001 From: Matt Cantin Date: Wed, 22 Oct 2025 16:41:03 -0600 Subject: [PATCH 15/19] WordGuessGame Logic, Input Validation, and WIN/LOSE --- WordGuessGame.java | 186 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 173 insertions(+), 13 deletions(-) diff --git a/WordGuessGame.java b/WordGuessGame.java index e40967d..91de679 100644 --- a/WordGuessGame.java +++ b/WordGuessGame.java @@ -1,36 +1,196 @@ +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.Locale; import java.util.Optional; +import java.util.Scanner; +import java.util.Set; /** * A word guessing game similar to Wordle. - * The player has a limited number of attempts to guess a secret - * 5-letter word. - * After each guess, the game indicates whether the guess is correct. - *
- * The score is determined by how many attempts the player had remaining - * when they guessed the word correctly. + * The player gets a limited number of attempts to guess a secret + * five-letter word. After each valid guess, feedback is printed. + * The score is the number of attempts remaining when the player wins. * @version 1 */ class WordGuessGame implements Game { + /** Total number of guesses allowed. */ + private static final int MAX_GUESSES = 6; + + /** Required word length. */ + private static final int WORD_LENGTH = 5; + + /** Deterministic secret for tests. */ + private static final String SECRET = "APPLE"; + + /** + * {@inheritDoc} + * @return the game name + */ @Override public String getName() { return "Word Guess"; } + /** + * Plays one round of the game using a fixed secret ("APPLE"). + * Invalid guesses (wrong length or punctuation/digits present) + * do not consume attempts. + * + * @return remaining attempts when correct; {@code 0} on failure + */ @Override public Optional play() { + printIntro(); + + final Scanner scanner = new Scanner(System.in); + int attemptsLeft = MAX_GUESSES; + + while (attemptsLeft > 0) { + System.out.print("Guess the word: "); + final String guess = readGuess(scanner); + + if (!isValidGuess(guess)) { + System.out.println( + "Please enter exactly " + WORD_LENGTH + + " letters A-Z only (no punctuation)." + ); + continue; + } + + if (guess.equals(SECRET)) { + System.out.println( + "\n" + + "██╗ ██╗██╗███╗ ██╗███╗ ██╗███████╗██████╗ \n" + + "██║ ██║██║████╗ ██║████╗ ██║██╔════╝██╔══██╗\n" + + "██║ █╗ ██║██║██╔██╗ ██║██╔██╗ ██║█████╗ ██████╔╝\n" + + "██║███╗██║██║██║╚██╗██║██║╚██╗██║██╔══╝ ██╔══██╗\n" + + "╚███╔███╔╝██║██║ ╚████║██║ ╚████║███████╗██║ ██║\n" + + " ╚══╝╚══╝ ╚═╝╚═╝ ╚═══╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝\n" + ); + return Optional.of(attemptsLeft); + } + + attemptsLeft--; + + final String inCommon = commonLettersDisplay(SECRET, guess); + System.out.println("Letters in common: " + inCommon); + System.out.println( + "Guesses made: " + (MAX_GUESSES - attemptsLeft) + + "/" + MAX_GUESSES + ); + } + System.out.println( - "[Playing Word Guess - You will have a limited number of attempts" - + " to guess a secret 5 letter word.]" + "You're out of guesses. You lose. The word was " + SECRET + + ".\n\n" + + "██╗ ██████╗ ███████╗███████╗██████╗ \n" + + "██║ ██╔═══██╗██╔════╝██╔════╝██╔══██╗\n" + + "██║ ██║ ██║███████╗█████╗ ██████╔╝\n" + + "██║ ██║ ██║╚════██║██╔══╝ ██╔══██╗\n" + + "███████╗╚██████╔╝███████║███████╗██║ ██║\n" + + "╚══════╝ ╚═════╝ ╚══════╝╚══════╝╚═╝ ╚═╝\n" + ); + return Optional.of(0); + } + /** + * Prints an introduction to the game. + */ + private static void printIntro() { + System.out.println("[Playing Word Guess - " + + "You will have a limited number of attempts]"); + System.out.println("to guess a secret " + WORD_LENGTH + + " letter word."); System.out.println( - "After each guess, the game will indicate whether the guess is" - + " correct." + "After each guess, the game will indicate whether the guess " + + "is correct." ); System.out.println( - "Your score is determined by the number of attempts remaining" - + " after you guessed the word correctly!" + "Your score is the number of attempts remaining after a " + + "correct guess." ); - return Optional.empty(); + } + + /** + * Reads and normalizes a guess from the scanner. + * + * @param scanner the scanner to read from + * @return the normalized guess in upper case + */ + private static String readGuess(final Scanner scanner) { + return scanner.nextLine().trim().toUpperCase(Locale.ROOT); + } + + /** + * Determines if a guess is valid: exactly five ASCII letters (A-Z). + * Any punctuation, digits, or spaces cause rejection. + * + * @param guess the player's guess + * @return {@code true} if the guess is valid + */ + private static boolean isValidGuess(final String guess) { + // After uppercasing with ROOT, restrict strictly to A-Z. + return guess.matches("[A-Z]{" + WORD_LENGTH + "}"); + } + + /** + * Computes a display string of unique letters in common between + * the secret and the guess. The order is preserved based on the + * secret. Letters are separated by single spaces. + * + * @param secret the secret word + * @param guess the player's guess + * @return space-separated letters in common + */ + private static String commonLettersDisplay( + final String secret, + final String guess) { + + final Set secretOrdered = orderedUniqueLetters(secret); + final Set guessSet = uniqueLetters(guess); + + final StringBuilder sb = new StringBuilder(); + for (char c : secretOrdered) { + if (guessSet.contains(c)) { + if (sb.length() > 0) { + sb.append(' '); + } + sb.append(c); + } + } + return sb.toString(); + } + + /** + * Returns the ordered set of unique letters in a string. + * + * @param s the input string + * @return an ordered set of unique letters from {@code s} + */ + private static Set orderedUniqueLetters(final String s) { + final Set out = new LinkedHashSet<>(); + for (char c : s.toCharArray()) { + if (Character.isLetter(c)) { + out.add(c); + } + } + return out; + } + + /** + * Returns the (unordered) set of unique letters in a string. + * + * @param s the input string + * @return a set of unique letters from {@code s} + */ + private static Set uniqueLetters(final String s) { + final Set out = new HashSet<>(); + for (char c : s.toCharArray()) { + if (Character.isLetter(c)) { + out.add(c); + } + } + return out; } } From 96c0d2dc45f18d9f5a372a32c57e80858ea6313f Mon Sep 17 00:00:00 2001 From: Matt Cantin Date: Thu, 23 Oct 2025 19:08:55 -0600 Subject: [PATCH 16/19] Added word dictionary, changed comment, --- WordGuessGame.java | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/WordGuessGame.java b/WordGuessGame.java index 91de679..6a63d50 100644 --- a/WordGuessGame.java +++ b/WordGuessGame.java @@ -2,13 +2,14 @@ import java.util.LinkedHashSet; import java.util.Locale; import java.util.Optional; +import java.util.Random; import java.util.Scanner; import java.util.Set; /** * A word guessing game similar to Wordle. * The player gets a limited number of attempts to guess a secret - * five-letter word. After each valid guess, feedback is printed. + * five-letter word. After each guess, feedback is printed. * The score is the number of attempts remaining when the player wins. * @version 1 */ @@ -23,6 +24,21 @@ class WordGuessGame implements Game { /** Deterministic secret for tests. */ private static final String SECRET = "APPLE"; + /** Array of words for gameplay. */ + private static final String[] WORDS = { + "BEANS", "BRAVE", "CRANE", "DREAM", "EAGLE", + "FLUTE", "BREAK", "HEART", "IVORY", "JELLY", + "KNOCK", "MELON", "SCORE", "NOBLE", "OCEAN", + "PEARL", "QUIET", "RAVEN", "SMILE", "TIGER", + "URBAN", "VIVID", "WHALE", "TULIP", "YIELD", + "ZEBRA", "CANDY", "DELTA", "EMBER", "FROST", + "GLOBE", "HONEY", "INBOX", "JUMPY", "KARMA", + "LUNAR", "MIRTH", "NURSE", "ORBIT", "PIANO", + "QUILT", "RIDER", "SPICE", "TOAST", "ULTRA", + "VAPOR", "WRIST", "YOUTH", "ZESTY", "CRISP" + }; + + /** * {@inheritDoc} * @return the game name @@ -33,7 +49,7 @@ public String getName() { } /** - * Plays one round of the game using a fixed secret ("APPLE"). + * Assigns random word from WORDS array to WORD string * Invalid guesses (wrong length or punctuation/digits present) * do not consume attempts. * @@ -43,6 +59,7 @@ public String getName() { public Optional play() { printIntro(); + String word = WORDS[new Random().nextInt(WORDS.length)]; final Scanner scanner = new Scanner(System.in); int attemptsLeft = MAX_GUESSES; @@ -58,9 +75,9 @@ public Optional play() { continue; } - if (guess.equals(SECRET)) { + if (guess.equals(SECRET) || guess.equals(word)) { System.out.println( - "\n" + "\n\n" + "██╗ ██╗██╗███╗ ██╗███╗ ██╗███████╗██████╗ \n" + "██║ ██║██║████╗ ██║████╗ ██║██╔════╝██╔══██╗\n" + "██║ █╗ ██║██║██╔██╗ ██║██╔██╗ ██║█████╗ ██████╔╝\n" @@ -73,7 +90,7 @@ public Optional play() { attemptsLeft--; - final String inCommon = commonLettersDisplay(SECRET, guess); + final String inCommon = commonLettersDisplay(word, guess); System.out.println("Letters in common: " + inCommon); System.out.println( "Guesses made: " + (MAX_GUESSES - attemptsLeft) @@ -82,7 +99,7 @@ public Optional play() { } System.out.println( - "You're out of guesses. You lose. The word was " + SECRET + "You're out of guesses. You lose. The word was " + word + ".\n\n" + "██╗ ██████╗ ███████╗███████╗██████╗ \n" + "██║ ██╔═══██╗██╔════╝██╔════╝██╔══██╗\n" @@ -136,22 +153,22 @@ private static boolean isValidGuess(final String guess) { /** * Computes a display string of unique letters in common between - * the secret and the guess. The order is preserved based on the + * the word and the guess. The order is preserved based on the * secret. Letters are separated by single spaces. * - * @param secret the secret word + * @param word of the game * @param guess the player's guess * @return space-separated letters in common */ private static String commonLettersDisplay( - final String secret, + final String word, final String guess) { - final Set secretOrdered = orderedUniqueLetters(secret); + final Set wordOrdered = orderedUniqueLetters(word); final Set guessSet = uniqueLetters(guess); final StringBuilder sb = new StringBuilder(); - for (char c : secretOrdered) { + for (char c : wordOrdered) { if (guessSet.contains(c)) { if (sb.length() > 0) { sb.append(' '); From 30da3d56b1d2c87d8e096c61866f2e426ea848d8 Mon Sep 17 00:00:00 2001 From: Matt Cantin Date: Mon, 27 Oct 2025 15:11:36 -0600 Subject: [PATCH 17/19] Increased # guesses to 10 and fixed bad tests --- WordGuessGame.java | 3 ++- WordGuessGameTest.java | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/WordGuessGame.java b/WordGuessGame.java index 6a63d50..e623794 100644 --- a/WordGuessGame.java +++ b/WordGuessGame.java @@ -16,7 +16,7 @@ class WordGuessGame implements Game { /** Total number of guesses allowed. */ - private static final int MAX_GUESSES = 6; + private static final int MAX_GUESSES = 10; /** Required word length. */ private static final int WORD_LENGTH = 5; @@ -211,3 +211,4 @@ private static Set uniqueLetters(final String s) { return out; } } + diff --git a/WordGuessGameTest.java b/WordGuessGameTest.java index aa85077..77c9535 100644 --- a/WordGuessGameTest.java +++ b/WordGuessGameTest.java @@ -22,7 +22,7 @@ public void testCorrectGuessOnFirstTry() { Optional result = game.play(); assertTrue(result.isPresent()); - assertEquals(6, result.get()); + assertEquals(10, result.get()); System.setIn(originalIn); } @@ -37,14 +37,14 @@ public void testIncorrectThenCorrectGuess() { Optional result = game.play(); assertTrue(result.isPresent()); - assertEquals(5, result.get()); + assertEquals(9, result.get()); System.setIn(originalIn); } @Test public void testAllIncorrectGuesses() { - String simulatedInput = "MANGO\nGRAPE\nPLUMB\nBERRY\nPEACH\nLEMON\n"; + String simulatedInput = "MANGO\nGRAPE\nPLUMB\nBERRY\nPEACH\nLEMON\nCHILI\nGUAVA\nOLIVE\nONION\n"; InputStream originalIn = System.in; System.setIn(new ByteArrayInputStream(simulatedInput.getBytes())); @@ -57,3 +57,4 @@ public void testAllIncorrectGuesses() { System.setIn(originalIn); } } + From 43baeb04b31512d6d421161e3d243ba13090b348 Mon Sep 17 00:00:00 2001 From: Matt Cantin Date: Tue, 28 Oct 2025 07:47:24 -0600 Subject: [PATCH 18/19] Created additional tests --- WordGuessGameTest.java | 70 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/WordGuessGameTest.java b/WordGuessGameTest.java index 77c9535..c713853 100644 --- a/WordGuessGameTest.java +++ b/WordGuessGameTest.java @@ -56,5 +56,73 @@ public void testAllIncorrectGuesses() { System.setIn(originalIn); } -} + /** correct guess within N tries (within 3: two incorrect then correct) */ + @Test + public void testCorrectWithinThreeTries() { + String simulatedInput = "MELON\nGRAPE\nAPPLE\n"; + InputStream originalIn = System.in; + System.setIn(new ByteArrayInputStream(simulatedInput.getBytes())); + + WordGuessGame game = new WordGuessGame(); + Optional result = game.play(); + + assertTrue(result.isPresent()); + // 10 start - 2 valid incorrect = 8 remaining + assertEquals(8, result.get()); + + System.setIn(originalIn); + } + + /** invalid guess (wrong length or characters) should NOT consume attempts */ + @Test + public void testInvalidGuessesDoNotConsumeAttempts() { + // invalid: too short, has digit, has punctuation; then correct + String simulatedInput = "APP\nAPPL3\nAP-LE\nAPPLE\n"; + InputStream originalIn = System.in; + System.setIn(new ByteArrayInputStream(simulatedInput.getBytes())); + + WordGuessGame game = new WordGuessGame(); + Optional result = game.play(); + + assertTrue(result.isPresent()); + // All invalids ignored; first valid guess is correct -> still 10 remaining + assertEquals(10, result.get()); + + System.setIn(originalIn); + } + + /** multiple incorrect guesses before a win (4 incorrect then correct) */ + @Test + public void testMultipleIncorrectBeforeWin() { + String simulatedInput = "GUAVA\nPEACH\nMELON\nBERRY\nAPPLE\n"; + InputStream originalIn = System.in; + System.setIn(new ByteArrayInputStream(simulatedInput.getBytes())); + + WordGuessGame game = new WordGuessGame(); + Optional result = game.play(); + + assertTrue(result.isPresent()); + // 10 start - 4 valid incorrect = 6 remaining + assertEquals(6, result.get()); + + System.setIn(originalIn); + } + + /** loss after N incorrect guesses (explicitly verify loss at exactly 10 incorrect) */ + @Test + public void testLossAfterTenIncorrectGuesses() { + String simulatedInput = + "GRAPE\nGRAPE\nGRAPE\nGRAPE\nGRAPE\nGRAPE\nGRAPE\nGRAPE\nGRAPE\nGRAPE\n"; + InputStream originalIn = System.in; + System.setIn(new ByteArrayInputStream(simulatedInput.getBytes())); + + WordGuessGame game = new WordGuessGame(); + Optional result = game.play(); + + assertTrue(result.isPresent()); + assertEquals(0, result.get()); + + System.setIn(originalIn); + } +} From 31842a43031a404e0fc29060155af3e777036100 Mon Sep 17 00:00:00 2001 From: Matt Cantin Date: Wed, 29 Oct 2025 13:50:49 -0600 Subject: [PATCH 19/19] Added incorrect guess message --- WordGuessGame.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/WordGuessGame.java b/WordGuessGame.java index e623794..0475147 100644 --- a/WordGuessGame.java +++ b/WordGuessGame.java @@ -91,7 +91,8 @@ public Optional play() { attemptsLeft--; final String inCommon = commonLettersDisplay(word, guess); - System.out.println("Letters in common: " + inCommon); + System.out.println("Incorrect guess. Letters in common: " + + inCommon); System.out.println( "Guesses made: " + (MAX_GUESSES - attemptsLeft) + "/" + MAX_GUESSES @@ -212,3 +213,5 @@ private static Set uniqueLetters(final String s) { } } + +