From c730ea203f6e83f1151762f6c4b7061c26a6b9f1 Mon Sep 17 00:00:00 2001 From: bfcortesss Date: Mon, 13 Oct 2025 23:50:34 -0400 Subject: [PATCH 1/3] Added short SudokuGame introduction --- SudokuGame.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/SudokuGame.java b/SudokuGame.java index caa9ecd..ccc00aa 100644 --- a/SudokuGame.java +++ b/SudokuGame.java @@ -18,7 +18,23 @@ public String getName() { @Override public Optional play() { - System.out.println("[Playing Sudoku - Placeholder]"); + printIntro(); + + System.out.println(""); return Optional.empty(); } + + private void printIntro() { + System.out.println( + "Sudoku is a 9x9 number puzzle. Fill the grid so each row, column, and 3x3 box " + + "contains the digits 1-9 exactly once. Use logic to complete the board."); + } + + +public static void main(String[] args) { + SudokuGame game = new SudokuGame(); + game.play(); + + } +} From ac9fe2060a146c35991645cfc3f1406c24867b06 Mon Sep 17 00:00:00 2001 From: bfcortesss Date: Wed, 15 Oct 2025 16:34:53 -0400 Subject: [PATCH 2/3] Adding description to SudokuGame.java --- SudokuGame.java | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/SudokuGame.java b/SudokuGame.java index ccc00aa..09da87a 100644 --- a/SudokuGame.java +++ b/SudokuGame.java @@ -18,23 +18,17 @@ public String getName() { @Override public Optional play() { - printIntro(); + System.out.println("[Playing Sudoku - Placeholder]"); + System.out.println("Welcome to Sudoku! You will be presented with" + + " a 9x9 grid split into 9 different 3x3 grids." + + " Some of the cells will already be filled in" + + " with numbers. Each digit from 1-9 must" + + " appear exactly once in every" + + " row, column, and 3x3 grid. To solve the puzzle," + + " each cell must be filled in according to the" + + " following conditions"); - System.out.println(""); return Optional.empty(); - } - - private void printIntro() { - System.out.println( - "Sudoku is a 9x9 number puzzle. Fill the grid so each row, column, and 3x3 box " + - "contains the digits 1-9 exactly once. Use logic to complete the board."); - -} - - -public static void main(String[] args) { - SudokuGame game = new SudokuGame(); - game.play(); } -} +} From ac6633b8d10f7536d4c9398b6f7f86f8c50aa1e9 Mon Sep 17 00:00:00 2001 From: bfcortesss Date: Tue, 28 Oct 2025 00:08:02 -0400 Subject: [PATCH 3/3] Validate 5-letter alphabetic guess. So that invalid input does not consume attempts. --- WordGuessGame.java | 55 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 4 deletions(-) diff --git a/WordGuessGame.java b/WordGuessGame.java index e40967d..f9dec4d 100644 --- a/WordGuessGame.java +++ b/WordGuessGame.java @@ -1,5 +1,5 @@ import java.util.Optional; - +import java.util.Scanner; /** * A word guessing game similar to Wordle. * The player has a limited number of attempts to guess a secret @@ -12,7 +12,21 @@ */ class WordGuessGame implements Game { - @Override +// Acceots 5 Alphabetic letters ASCII A-Z or a-z.// +public String GuessCondition = "^[A-Za-z]{5}$"; +// Maximum number of attempts a player gets // +public int MaxAttempts = 6; + +/** +*Checks if a guess is valid, non-null, and alphabetic +* +*@param guess The user's guess. +*@return true if valid, false otherwise, +*/ +boolean isValidGuess(String guess) { + return guess != null && guess.matches(GuessCondition); +} + @Override public String getName() { return "Word Guess"; } @@ -31,6 +45,39 @@ public Optional play() { "Your score is determined by the number of attempts remaining" + " after you guessed the word correctly!" ); - return Optional.empty(); - } + +//Remaining attempts and user input// +int attemptsLeft = MaxAttempts; +Scanner scanner = new Scanner(System.in); + +//Loop will continue while player has attempts remaining// +while (attemptsLeft > 0) { +String guess; + +//Loop prompts until a valid guess is entered// +while (true) { + System.out.print +("Enter a 5-Letter Word: "); + guess = scanner.nextLine(); + + if (!isValidGuess(guess)) { + System.out.println("Inavlid Input: Please enter 5 alphabetic letters (A-Z)."); + continue; +} + guess = guess.toUpperCase(); + break; +} + +//Valid input consumes one attempt// +attemptsLeft--; +System.out.println("Guess Accepted. Attempts Left: " + attemptsLeft); + +break; + +} + +return Optional.empty(); + +} + }