-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Re-organised the flow of logic from parent to child comopnents 2. Correction done for the complete state to show success or hide 3. Created the roll dice logic/effect to get new cards for display update
- Loading branch information
1 parent
8faaa31
commit 22f7a16
Showing
8 changed files
with
113 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export const checkIfGameComplete = (setIsGameComplete) => { | ||
/* get, iterate and check */ | ||
const currentSelection = JSON.parse(window.localStorage.getItem("tenzies_deck")); | ||
const allSetAsLocked = currentSelection.every((card) => { | ||
return card.isLocked === true; | ||
}); | ||
|
||
/* set state */ | ||
if (allSetAsLocked) { | ||
setIsGameComplete(true); | ||
} | ||
else { | ||
setIsGameComplete(false); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* npm imports */ | ||
import uuid from "react-uuid"; | ||
|
||
/* app imports */ | ||
import { generateRandomNumbers } from "./generate-random-numbers.js"; | ||
import { getCardMap } from "./card-map.js"; | ||
|
||
export default function generateDeckOnRoll(setDeckOfCards, setIsLoading) { | ||
const cardMap = getCardMap(); | ||
|
||
return () => { | ||
setIsLoading(true); | ||
const currentDeck = JSON.parse(window.localStorage.getItem("tenzies_deck")); | ||
const updatedDeck = currentDeck.reduce((composed, cardObject) => { | ||
let card = null; | ||
|
||
if (cardObject.isLocked) { | ||
card = Object.assign({}, cardObject); | ||
} | ||
else { | ||
let key = String(generateRandomNumbers(1, 13)); | ||
card = { | ||
id: uuid(), | ||
isLocked: false, | ||
name: cardMap[key].name, | ||
icon: cardMap[key].src | ||
}; | ||
} | ||
|
||
composed.push(card); | ||
return composed; | ||
}, []); | ||
|
||
setTimeout(() => { | ||
setIsLoading(false); | ||
setDeckOfCards(updatedDeck); | ||
window.localStorage.setItem("tenzies_deck", JSON.stringify(updatedDeck)); | ||
}, 2000); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters