fix: copilot issues

pull/1500/head
prathoseraaj 1 year ago
parent 163c9f8a60
commit dadef520ba

@ -12,7 +12,7 @@
--font-mono: var(--font-geist-mono); --font-mono: var(--font-geist-mono);
} }
@media (prefers-color-scheme: light) { @media (prefers-color-scheme: dark) {
:root { :root {
--background: #0a0a0a; --background: #0a0a0a;
--foreground: #ededed; --foreground: #ededed;

@ -7,20 +7,19 @@ const MemoryGame = () => {
const [array, setArray] = useState([]); const [array, setArray] = useState([]);
const [flipped, setFlipped] = useState([]); const [flipped, setFlipped] = useState([]);
const [slectedPairs, setSelectedPairs] = useState([]); const [selectedPairs, setSelectedPairs] = useState([]);
const [disabled, setDisabled] = useState(false); const [disabled, setDisabled] = useState(false);
const [won, setWon] = useState(false); const [won, setWon] = useState(false);
const handleGridSize = (e) => { const handleGridSize = (e) => {
const size = parseInt(e.target.value); const size = parseInt(e.target.value);
//console.log(size)
if (2 <= size && size <= 10) { if (2 <= size && size <= 10) {
setGridSize(size); setGridSize(size);
} }
}; };
const initalizeGame = () => { const initializeGame = () => {
const totalCards = gridSize * gridSize; const totalCards = gridSize * gridSize;
const pairCount = Math.floor(totalCards / 2); const pairCount = Math.floor(totalCards / 2);
@ -55,7 +54,7 @@ const MemoryGame = () => {
}; };
useEffect(() => { useEffect(() => {
initalizeGame(); initializeGame();
}, [gridSize]); }, [gridSize]);
const handleClick = (id) => { const handleClick = (id) => {
@ -67,10 +66,9 @@ const MemoryGame = () => {
} }
if (flipped.length === 1) { if (flipped.length === 1) {
setDisabled(true); //so we cant choose another one setDisabled(true);
if (id !== flipped[0]) { if (id !== flipped[0]) {
setFlipped([...flipped, id]); setFlipped([...flipped, id]);
//check match logic
handleMatch(id); handleMatch(id);
} else { } else {
setFlipped([]); setFlipped([]);
@ -79,14 +77,14 @@ const MemoryGame = () => {
} }
}; };
const isFlipped = (id) => flipped.includes(id) || slectedPairs.includes(id); const isFlipped = (id) => flipped.includes(id) || selectedPairs.includes(id);
const isselectedpairs = (id) => slectedPairs.includes(id); const isSelectedPairs = (id) => selectedPairs.includes(id);
useEffect(() => { useEffect(() => {
if (slectedPairs.length === array.length && array.length > 0) { if (selectedPairs.length === array.length && array.length > 0) {
setWon(true); setWon(true);
} }
}, [slectedPairs, array]); }, [selectedPairs, array]);
return ( return (
<div className="h-[100vh] flex flex-col justify-center items-center p-4 bg-gray-100 "> <div className="h-[100vh] flex flex-col justify-center items-center p-4 bg-gray-100 ">
@ -112,19 +110,19 @@ const MemoryGame = () => {
width: `min(100%,${gridSize * 5.5}rem)`, width: `min(100%,${gridSize * 5.5}rem)`,
}} }}
> >
{array.map((array) => ( {array.map((card) => (
<div <div
key={array.id} key={card.id}
onClick={() => handleClick(array.id)} onClick={() => handleClick(card.id)}
className={`aspect-square flex items-center justify-center text-xl transition-all duration-300 font-bold rounded-lg cursor-pointer ${ className={`aspect-square flex items-center justify-center text-xl transition-all duration-300 font-bold rounded-lg cursor-pointer ${
isFlipped(array.id) isFlipped(card.id)
? isSelectedPairs(array.id) ? isSelectedPairs(card.id)
? "bg-green-500 text-white" ? "bg-green-500 text-white"
: "bg-blue-500 text-white" : "bg-blue-500 text-white"
: "bg-gray-300 text-gray-400 " : "bg-gray-300 text-gray-400 "
}`} }`}
> >
{isFlipped(array.id) ? array.number : "?"} {isFlipped(card.id) ? card.number : "?"}
</div> </div>
))} ))}
</div> </div>
@ -136,7 +134,7 @@ const MemoryGame = () => {
{/* Reset Button */} {/* Reset Button */}
<button <button
className="px-5 py-2 bg-green-500 rounded text-white mt-5" className="px-5 py-2 bg-green-500 rounded text-white mt-5"
onClick={initalizeGame} onClick={initializeGame}
> >
Reset Reset
</button> </button>

Loading…
Cancel
Save