mirror of
https://github.com/FranP-code/Hangman-game-with-React.git
synced 2025-10-13 00:42:32 +00:00
Counter logic done
This commit is contained in:
13
src/App.js
13
src/App.js
@@ -6,6 +6,7 @@ import PuzzleWord from "./components/Hangman/PuzzleWord/PuzzleWord";
|
||||
import Victory from "./components/Hangman/PuzzleWord/Victory";
|
||||
import Defeat from "./components/Hangman/PuzzleWord/Defeat";
|
||||
import Loading from "./components/Loading";
|
||||
import AlmacenateCurrentScore from "./components/Scripts/AlmacenateCurrentScore";
|
||||
|
||||
function App() {
|
||||
|
||||
@@ -19,10 +20,22 @@ function App() {
|
||||
|
||||
const [displayApp, setDisplayApp] = useState(false)
|
||||
|
||||
React.useEffect(() => {
|
||||
|
||||
if (localStorage.getItem('currentScore')) {
|
||||
|
||||
setCurrentScore(localStorage.getItem('currentScore'))
|
||||
localStorage.removeItem('currentScore')
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
if (isVictory || isDefeat) {
|
||||
|
||||
|
||||
setTimeout(() => {
|
||||
AlmacenateCurrentScore(currentScore)
|
||||
|
||||
window.location.reload(true);
|
||||
}, 3000)
|
||||
}
|
||||
|
||||
@@ -4,7 +4,8 @@ const Victory = ({currentScore, setCurrentScore}) => {
|
||||
|
||||
React.useEffect(() => {
|
||||
|
||||
setCurrentScore(currentScore + 1)
|
||||
setCurrentScore(parseInt(currentScore) + 1)
|
||||
|
||||
}, [])
|
||||
|
||||
return (
|
||||
|
||||
6
src/components/Scripts/AlmacenateCurrentScore.js
Normal file
6
src/components/Scripts/AlmacenateCurrentScore.js
Normal file
@@ -0,0 +1,6 @@
|
||||
const AlmacenateCurrentScore = (currentScore) => {
|
||||
|
||||
localStorage.setItem('currentScore', currentScore)
|
||||
}
|
||||
|
||||
export default AlmacenateCurrentScore
|
||||
Reference in New Issue
Block a user