mirror of
https://github.com/FranP-code/Hangman-game-with-React.git
synced 2025-10-13 00:42:32 +00:00
Logic for bring the words from Firebase done
This commit is contained in:
@@ -14,8 +14,6 @@ const CheckVictory = (setIsVictory) => {
|
||||
}
|
||||
});
|
||||
|
||||
console.log(allChildrenHaveText)
|
||||
|
||||
if (allChildrenHaveText) {
|
||||
|
||||
setIsVictory(true)
|
||||
|
||||
@@ -2,13 +2,11 @@ import CheckVictory from "./CheckVictory";
|
||||
|
||||
const Register_Input = (actualWord, hangmanFrame, setHangmanFrame, setIsVictory, setIsDefeat) => {
|
||||
|
||||
const alphabet = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n", "ñ","o","p","q","r","s","t","u","v","w","x","y","z"];
|
||||
const alphabet = ["a", "á", "b","c","d","e", "é", "f","g","h","i", "í", "j","k","l","m","n", "ñ","o", "ó","p","q","r","s","t","u","ú","v","w","x","y","z"];
|
||||
|
||||
const keyRegister = (event) => {
|
||||
|
||||
const currentKey = event.key.toLowerCase()
|
||||
|
||||
console.log(hangmanFrame)
|
||||
|
||||
if (hangmanFrame <= 5 && alphabet.includes(currentKey) ) {
|
||||
|
||||
@@ -18,8 +16,6 @@ const Register_Input = (actualWord, hangmanFrame, setHangmanFrame, setIsVictory,
|
||||
|
||||
const letters = []
|
||||
|
||||
console.log(event.key)
|
||||
|
||||
if (actualWord.search(currentKey) + 1) {
|
||||
|
||||
for (let i = 0; i < actualWord.length; i++) {
|
||||
@@ -53,6 +49,24 @@ const Register_Input = (actualWord, hangmanFrame, setHangmanFrame, setIsVictory,
|
||||
setHangmanFrame(quantity)
|
||||
|
||||
if (hangmanFrame === 5) {
|
||||
|
||||
for (let i = 0; i < actualWord.length; i++) {
|
||||
|
||||
let letter = document.createElement('span')
|
||||
|
||||
letter.className = 'letter'
|
||||
|
||||
letter.textContent = actualWord[i]
|
||||
|
||||
if (i === 0) {
|
||||
|
||||
letter.textContent = letter.textContent.toUpperCase()
|
||||
}
|
||||
|
||||
|
||||
puzzleWord.replaceChild(letter, puzzleWord.children[i])
|
||||
}
|
||||
|
||||
setIsDefeat(true)
|
||||
|
||||
}
|
||||
|
||||
11
src/components/Scripts/SelectRandomWord.js
Normal file
11
src/components/Scripts/SelectRandomWord.js
Normal file
@@ -0,0 +1,11 @@
|
||||
const SelectRandomWord = (arrayWords) => {
|
||||
|
||||
const randomWord = Math.trunc(
|
||||
|
||||
Math.random() * (arrayWords.length - 0) + 0
|
||||
)
|
||||
|
||||
return randomWord
|
||||
}
|
||||
|
||||
export default SelectRandomWord
|
||||
Reference in New Issue
Block a user