Victory and defeat logic done

This commit is contained in:
2021-10-14 12:56:08 -03:00
parent fac1305cfc
commit 84dcff99a7
9 changed files with 62 additions and 20 deletions

View File

@@ -5,6 +5,7 @@ import Header from "./components/Header";
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";
function App() {
@@ -16,18 +17,13 @@ function App() {
const [isVictory, setIsVictory] = useState(false)
const [isDefeat, setIsDefeat] = useState(false)
const [keyPuzzleWord, setKeyPuzzleWord] = useState(1)
const [displayApp, setDisplayApp] = useState(false)
if (isVictory || isDefeat) {
setTimeout(() => {
setHangmanFrame(0)
setIsVictory(false)
setIsDefeat(false)
setKeyPuzzleWord(keyPuzzleWord + 1)
window.location.reload(true);
}, 3000)
}
@@ -40,18 +36,18 @@ function App() {
<div className='column-1'>
<Hangman
hangmanFrame={hangmanFrame}
/>
/>
</div>
<div className='column-2'>
<CurrentScore currentScore={currentScore} />
{ isVictory || isDefeat ? null :
{!displayApp ? <Loading /> : null }
<PuzzleWord
key={keyPuzzleWord}
hangmanFrame={hangmanFrame}
setHangmanFrame={setHangmanFrame}
@@ -63,10 +59,9 @@ function App() {
isDefeat={isDefeat}
setIsDefeat={setIsDefeat}
/>
}
setDisplayApp={setDisplayApp}
/>
{isVictory ? <Victory currentScore={currentScore} setCurrentScore={setCurrentScore} /> : null}
{isDefeat ? <Defeat /> : null}

View File

@@ -3,11 +3,10 @@ import Register_Input from '../../Scripts/Register input'
import Defeat from './Defeat'
import Victory from './Victory'
const PuzzleWord = ({hangmanFrame, setHangmanFrame, currentScore, setCurrentScore, setIsVictory, setIsDefeat}) => {
const PuzzleWord = ({hangmanFrame, setHangmanFrame, currentScore, setCurrentScore, setIsVictory, setIsDefeat, setDisplayApp}) => {
const [actualWord, setActualWord] = useState('papa')
const generatePuzzleWord = () => {
const puzzleWord = document.getElementById('puzzleWord')
@@ -27,12 +26,12 @@ const PuzzleWord = ({hangmanFrame, setHangmanFrame, currentScore, setCurrentScor
counter.textContent = '(' + actualWord.length + ')'
puzzleWord.appendChild(counter)
}
}
React.useEffect(() => {
generatePuzzleWord()
setDisplayApp(true)
}, [])

View File

@@ -0,0 +1,12 @@
import React from 'react'
import loadingGifLightTheme from './img/loading-light-theme.png'
const Loading = () => {
return (
<div className='loading'>
<img src={loadingGifLightTheme} alt="" />
</div>
)
}
export default Loading

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB