diff --git a/src/helpers/Routes.jsx b/src/helpers/Routes.jsx
index 8ad4cfe..4b64022 100644
--- a/src/helpers/Routes.jsx
+++ b/src/helpers/Routes.jsx
@@ -1,10 +1,8 @@
import {createBrowserRouter} from "react-router-dom";
import Frame from "@components/common/Frame";
-import ProtectedRoute from "./ProtectedRoute";
-import PublicRoute from "./PublicRoute";
-import {Home, Map, Wordle, Register, ConfirmEmail, Login, Phrase, Quiz, Memory, NotFoundPage, ErrorPage} from "../pages";
+import {Wordle, ErrorPage} from "../pages";
const routes = createBrowserRouter([
{
@@ -12,27 +10,7 @@ const routes = createBrowserRouter([
element:
,
errorElement:
,
children: [
- {path: "/", element:
},
- {path: "*", element:
},
- {
- element:
,
- children: [
- {path: "/register", element:
},
- {path: "/login", element:
},
- {path: "/confirm-email", element:
}
- ]
- },
-
- {
- element:
,
- children: [
- {path: "/map", element:
},
- {path: "/wordle", element:
},
- {path: "/memory", element:
},
- {path: "/phrase", element:
},
- {path: "/quiz", element:
}
- ]
- }
+ {path: "/", element:
},
]
}
]);
diff --git a/src/pages/Wordle/index.jsx b/src/pages/Wordle/index.jsx
index 9e75511..ed23bd0 100644
--- a/src/pages/Wordle/index.jsx
+++ b/src/pages/Wordle/index.jsx
@@ -1,14 +1,13 @@
-import {useState, useCallback, useEffect} from "react";
+import { useState, useCallback, useEffect } from "react";
import Grid from "@components/Wordle";
import Keyboard from "@components/Wordle/Keyboard";
import GameHeader from "@components/common/GameHeader";
-import {LetterStatusEnum} from "../../constants/wordleConstants";
-import {GameRepository} from "../../repositories/games";
+import { LetterStatusEnum } from "../../constants/wordleConstants";
import FinishModal from "@components/common/FinishModal";
import Help from "@components/Wordle/Help";
-import {useAuthStore} from "@stores/useAuth";
+import words from "./words";
import styles from "./style.module.css"
@@ -18,7 +17,7 @@ const CONFIG = {
SECRET_WORD: "LIVRO"
};
-const getDefaultGuess = () => new Array(CONFIG.WORD_LENGTH).fill({char: ""});
+const getDefaultGuess = () => new Array(CONFIG.WORD_LENGTH).fill({ char: "" });
const filledCharacterCount = (guess) => guess.reduce((count, item) => (item.char === "" ? count - 1 : count), CONFIG.WORD_LENGTH);
@@ -30,6 +29,11 @@ const removeGuessCharacter = (guess, index) => {
return guess.map((item, i) => (i === index ? { ...item, char: "" } : item));
};
+function selectCorrectWord() {
+ const i = Math.floor(Math.random() * words.length);
+ return words[i];
+}
+
export default function Wordle() {
const [activeIndex, setActiveIndex] = useState(0);
@@ -37,24 +41,29 @@ export default function Wordle() {
const [currentGuess, setCurrentGuess] = useState(getDefaultGuess());
const [isGameOver, setIsGameOver] = useState(false);
const [isHelpOpen, setIsHelpOpen] = useState(false);
- const markLastTaskAsPlayed = useAuthStore((state) => state.markLastTaskAsPlayed);
-
- const {getTermData, termGuess} = GameRepository();
-
- useEffect(() => {
- if (isGameOver) {
- markLastTaskAsPlayed();
+ const [correctWord, setCorrectWord] = useState("");
+ const [playerWin, setPlayerWin] = useState(false);
+
+ const checkWord = (word) => {
+ let result = [];
+ const correctArr = correctWord.split("");
+
+ for (let i = 0; i < word.length; i++) {
+ const char = word[i];
+ if (char === correctArr[i]) {
+ result.push({ char, status: LetterStatusEnum.CORRECT });
+ } else if (correctArr.includes(char)) {
+ result.push({ char, status: LetterStatusEnum.INCORRECT_POSITION });
+ } else {
+ result.push({ char, status: LetterStatusEnum.DONT_EXIST });
+ }
}
- }, [isGameOver]);
+ return result;
+ };
useEffect(() => {
- const fetchData = async () => {
- const {tries} = await getTermData();
- setGuesses(tries);
- };
-
- fetchData();
- }, []);
+ setCorrectWord(selectCorrectWord())
+ }, [isGameOver]);
const handleKeyPress = useCallback(
async (key) => {
@@ -66,7 +75,7 @@ export default function Wordle() {
if (filledCharacterCount(currentGuess) === CONFIG.WORD_LENGTH) {
const fullWord = currentGuess.reduce((word, item) => word + item.char, "");
- const guessResult = await termGuess({guess: fullWord});
+ const guessResult = checkWord(fullWord);
const newGuesses = [...guesses, guessResult];
setGuesses(newGuesses);
@@ -76,7 +85,13 @@ export default function Wordle() {
const playerWon = guessResult.every((letter) => letter.status === LetterStatusEnum.CORRECT);
const maxAttemptsReached = newGuesses.length >= CONFIG.MAX_ATTEMPTS;
- if (playerWon || maxAttemptsReached) {
+ if (playerWon) {
+ setPlayerWin(true)
+ setIsGameOver(true);
+ }
+
+ if (maxAttemptsReached) {
+ setPlayerWin(false)
setIsGameOver(true);
}
}
@@ -100,7 +115,7 @@ export default function Wordle() {
return (
-
+
-
+
);
}
diff --git a/src/pages/Wordle/words.js b/src/pages/Wordle/words.js
new file mode 100644
index 0000000..d0c2974
--- /dev/null
+++ b/src/pages/Wordle/words.js
@@ -0,0 +1,4 @@
+export default [
+ "TESTE",
+ "RODAS"
+]
\ No newline at end of file