Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions GameHistoryTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
12 changes: 11 additions & 1 deletion SudokuGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ public String getName() {
@Override
public Optional<Integer> 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();
}

}
}
55 changes: 51 additions & 4 deletions WordGuessGame.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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";
}
Expand All @@ -31,6 +45,39 @@ public Optional<Integer> 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();

}

}