From 75135a2a51a0f6f2b7cf9bf7e646ef4c274181a0 Mon Sep 17 00:00:00 2001 From: "zeon-neon[bot]" <136533918+zeon-neon[bot]@users.noreply.github.com> Date: Mon, 2 Dec 2024 18:31:08 +0000 Subject: [PATCH 1/2] enhancement(lint): Fix lint errors for projects/wordle/src/main/java/com/saahild/Main.java Co-authored-by: NeonGamerBot-QK Signed-off-by: zeon-neon[bot] <136533918+zeon-neon[bot]@users.noreply.github.com> --- projects/wordle/src/main/java/com/saahild/Main.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/projects/wordle/src/main/java/com/saahild/Main.java b/projects/wordle/src/main/java/com/saahild/Main.java index 6ce767b..60b577f 100644 --- a/projects/wordle/src/main/java/com/saahild/Main.java +++ b/projects/wordle/src/main/java/com/saahild/Main.java @@ -1,7 +1,8 @@ package com.saahild; public class Main { - public static void main(String[] args) { - new Wordle("Tasco").playWordle(); - } -} \ No newline at end of file + + public static void main(String[] args) { + new Wordle("Tasco").playWordle(); + } +} From 22a98510f306002240b2967807da6740032437a2 Mon Sep 17 00:00:00 2001 From: "zeon-neon[bot]" <136533918+zeon-neon[bot]@users.noreply.github.com> Date: Mon, 2 Dec 2024 18:31:09 +0000 Subject: [PATCH 2/2] enhancement(lint): Fix lint errors for projects/wordle/src/main/java/com/saahild/Wordle.java Co-authored-by: NeonGamerBot-QK Signed-off-by: zeon-neon[bot] <136533918+zeon-neon[bot]@users.noreply.github.com> --- .../src/main/java/com/saahild/Wordle.java | 134 +++++++++++------- 1 file changed, 83 insertions(+), 51 deletions(-) diff --git a/projects/wordle/src/main/java/com/saahild/Wordle.java b/projects/wordle/src/main/java/com/saahild/Wordle.java index 23c8205..b0aba64 100644 --- a/projects/wordle/src/main/java/com/saahild/Wordle.java +++ b/projects/wordle/src/main/java/com/saahild/Wordle.java @@ -4,79 +4,111 @@ import java.util.Scanner; public class Wordle { - private String word; - public Wordle(String word) { - this.word = word; - } - private String[] getWordList() { - return new String[] { "rossa","jetty","wizzo","cuppa","cohoe","gurks","squad","beisa","shrug","fossa","fluyt","camus","speed","mamil","array","polio","barns","panes","souts","limas","fetch","queck","twink"}; - } - private String pickRandomWord(String[] list) { - return list[Math.round((float) (Math.random() * list.length))]; - } - private String colorLetter(String letter, String color) { - return color + letter + Reset; - } - private String[] evaluateGuess(String guess, String secretWord) { - String[] words = new String[guess.length()]; - for (int i = 0; i < guess.length(); i++) { + + private String word; + + public Wordle(String word) { + this.word = word; + } + + private String[] getWordList() { + return new String[] { + "rossa", + "jetty", + "wizzo", + "cuppa", + "cohoe", + "gurks", + "squad", + "beisa", + "shrug", + "fossa", + "fluyt", + "camus", + "speed", + "mamil", + "array", + "polio", + "barns", + "panes", + "souts", + "limas", + "fetch", + "queck", + "twink", + }; + } + + private String pickRandomWord(String[] list) { + return list[Math.round((float) (Math.random() * list.length))]; + } + + private String colorLetter(String letter, String color) { + return color + letter + Reset; + } + + private String[] evaluateGuess(String guess, String secretWord) { + String[] words = new String[guess.length()]; + for (int i = 0; i < guess.length(); i++) { char letter = guess.charAt(i); int lIndex = secretWord.indexOf(letter); if (lIndex >= 0) { - if (lIndex == guess.indexOf(letter)) { - words[i] = colorLetter(String.valueOf(letter), FgGreen); - } else { - words[i] = colorLetter(String.valueOf(letter), FgYellow); - } + if (lIndex == guess.indexOf(letter)) { + words[i] = colorLetter(String.valueOf(letter), FgGreen); + } else { + words[i] = colorLetter(String.valueOf(letter), FgYellow); + } } else { - words[i] = colorLetter(String.valueOf(letter), FgGray); + words[i] = colorLetter(String.valueOf(letter), FgGray); } - } - return words; } - public void playWordle() { - System.out.println("Starting wordle..."); - String word = pickRandomWord(getWordList()); - if (System.getenv("REVEAL_WORD") != null) { + return words; + } + + public void playWordle() { + System.out.println("Starting wordle..."); + String word = pickRandomWord(getWordList()); + if (System.getenv("REVEAL_WORD") != null) { System.out.println("Cheater: " + word); - } - String[][] board = new String[5][5]; - run(board, word); } - private void run(String[][] board, String word) { - System.out.println("========================================"); - if (board.length > 0) { + String[][] board = new String[5][5]; + run(board, word); + } + + private void run(String[][] board, String word) { + System.out.println("========================================"); + if (board.length > 0) { for (String[] row : board) { - System.out.println(String.join(" ", row)); + System.out.println(String.join(" ", row)); } - } else { + } else { System.out.println(""); - } - System.out.println("========================================"); - String input = ""; // Initialize the input variable + } + System.out.println("========================================"); + String input = ""; // Initialize the input variable System.out.print("Enter your guess: "); Scanner scanner = new Scanner(System.in); - input = scanner.nextLine().substring(0,5); + input = scanner.nextLine().substring(0, 5); // if (input.length() < 5) { // System.out.println("Invalid input. Please enter a 5 letter word."); // run(board, word); // }else { - String[] guess = evaluateGuess(input, word); - if (Arrays.toString(guess).equals(word)) { + String[] guess = evaluateGuess(input, word); + if (Arrays.toString(guess).equals(word)) { System.out.println("You win!"); - } else { + } else { board[board.length] = guess; run(board, word); - } - // } } - private static final String FgGreen = "\u001B[32m"; - private static final String FgYellow = "\u001B[33m"; - private static final String FgGray = "\u001B[37m"; - private static final String Reset = "\u001B[0m"; - // public static void main(String[] args) { - // new Wordle("Tasco").playWordle(); // } + } + private static final String FgGreen = "\u001B[32m"; + private static final String FgYellow = "\u001B[33m"; + private static final String FgGray = "\u001B[37m"; + private static final String Reset = "\u001B[0m"; + // public static void main(String[] args) { + // new Wordle("Tasco").playWordle(); + // } }