diff --git a/GameHistoryTracker.java b/GameHistoryTracker.java index ffd810e..e4e9faf 100644 --- a/GameHistoryTracker.java +++ b/GameHistoryTracker.java @@ -30,6 +30,9 @@ public void recordPlay(final String gameName, final Integer score) { if (score != null) { stats.totalScore += score; stats.scores.add(score); + } else if (score == null) { + System.out.println("Score is null"); + return; } statsMap.put(gameName, stats); } diff --git a/SudokuGame.java b/SudokuGame.java index caa9ecd..09da87a 100644 --- a/SudokuGame.java +++ b/SudokuGame.java @@ -19,6 +19,16 @@ public String getName() { @Override public Optional play() { 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"); + return Optional.empty(); - } + + } } 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(); + +} + }