-
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.
- Loading branch information
1 parent
2d13ad2
commit ed90123
Showing
20 changed files
with
253 additions
and
78 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
SASS_PATH=./src/styles/ | ||
SASS_PATH=src/styles/ |
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 |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
background-color: transparent; | ||
border: none; | ||
display: inline-flex; | ||
margin-right: 16px; | ||
padding: 0; | ||
} | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
@use "colors" as c; | ||
|
||
.pointList { | ||
display: grid; | ||
grid-template-rows: repeat(12, 1fr); | ||
gap: 8px; | ||
width: 100%; | ||
|
||
& > .pointListItem { | ||
background-image: url("../../img/svg/InactivePoints.svg"); | ||
padding: 8px 24px; | ||
font-size: 14px; | ||
font-weight: 400; | ||
text-align: center; | ||
|
||
&.active { | ||
background-image: url("../../img/svg/ActivePoints.svg"); | ||
color: c.$startButtonColor; | ||
} | ||
|
||
&.earned { | ||
background-image: url("../../img/svg/Earned.svg"); | ||
color: c.$earnedPointsColor; | ||
} | ||
} | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,105 @@ | ||
import { useState, useContext } from "react"; | ||
import { useNavigate } from "react-router-dom"; | ||
import { MobileContext } from "../../Context"; | ||
import styles from "./Game.module.scss"; | ||
import data from "../../questions.json"; | ||
import BurgerMenu from "../../components/BurgerMenu/BurgerMenu"; | ||
import PointMenu from "../../components/PointMenu/PointMenu"; | ||
|
||
const Game = () => { | ||
const isMobile = useContext(MobileContext); | ||
const navigate = useNavigate(); | ||
const [pointsMenu, setPointsMenu] = useState(false); | ||
const [selectedOption, setSelectedOption] = useState(null); | ||
const [disabledOption, setDisabledOption] = useState(false); | ||
const [correctOption, setCorrectOption] = useState(null); | ||
const [wrongOption, setWrongOption] = useState(null); | ||
const [questionId, setQuestionId] = useState(0); | ||
const [points, setPoints] = useState(0); | ||
const { questions } = data; | ||
const { question, options, correct_answer, amount } = questions.find( | ||
(item) => questionId === item.id | ||
); | ||
|
||
const checkAnswer = (answer, amount) => { | ||
if (answer.toLowerCase() === correct_answer.toLowerCase()) { | ||
setCorrectOption(answer); | ||
setTimeout(() => { | ||
if (questionId < questions.length - 1) { | ||
setQuestionId((prevId) => (prevId += 1)); | ||
setPoints(amount); | ||
setDisabledOption(false); | ||
} else { | ||
setPoints(amount); | ||
navigate("/end", { state: { amount } }); | ||
} | ||
}, 750); | ||
} else { | ||
setWrongOption(answer); | ||
setTimeout(() => { | ||
navigate("/end", { state: { amount: points } }); | ||
}, 750); | ||
} | ||
}; | ||
|
||
const getClassList = (item) => { | ||
const classes = [styles.answerListItem]; | ||
|
||
if (selectedOption === item) { | ||
classes.push(styles.selected); | ||
} | ||
if (disabledOption) { | ||
classes.push(styles.disabled); | ||
} | ||
if (correctOption === item) { | ||
classes.push(styles.correct); | ||
} | ||
if (wrongOption === item) { | ||
classes.push(styles.wrong); | ||
} | ||
return classes.join(" "); | ||
}; | ||
|
||
const toggleMobileMenu = () => { | ||
setPointsMenu((prevState) => !prevState); | ||
}; | ||
|
||
return ( | ||
<> | ||
<div className={styles.container}> | ||
{isMobile && ( | ||
<div className={styles.burgerMenu}> | ||
<BurgerMenu isOpen={pointsMenu} onClick={toggleMobileMenu} /> | ||
</div> | ||
)} | ||
<div className={styles.wrapper}> | ||
<p className={styles.question}>{question}</p> | ||
<ol className={styles.answersList}> | ||
{options.map((item) => ( | ||
<li | ||
className={getClassList(item)} | ||
key={item} | ||
onClick={() => { | ||
setSelectedOption(item); | ||
setDisabledOption(true); | ||
setTimeout(() => { | ||
checkAnswer(item, amount); | ||
}, 1000); | ||
}} | ||
> | ||
{item} | ||
</li> | ||
))} | ||
</ol> | ||
</div> | ||
{((isMobile && pointsMenu) || !isMobile) && ( | ||
<div className={styles.sideBar}> | ||
<PointMenu questions={questions} points={points} id={questionId} /> | ||
</div> | ||
)} | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default Game; |
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,76 @@ | ||
@use "colors" as c; | ||
|
||
.container { | ||
height: 100vh; | ||
width: 100vw; | ||
background-color: c.$gameBackgroundColor; | ||
} | ||
|
||
.burgerMenu { | ||
display: flex; | ||
justify-content: end; | ||
padding: 16px 16px 16px 0; | ||
} | ||
|
||
.sideBar { | ||
position: absolute; | ||
top: 56px; | ||
height: calc(100vh - 56px); | ||
width: 100vw; | ||
background-color: inherit; | ||
} | ||
|
||
.wrapper { | ||
display: grid; | ||
grid-template-rows: 1fr 1fr; | ||
align-items: center; | ||
height: calc(100vh - 56px); | ||
padding-bottom: 24px; | ||
} | ||
|
||
.question { | ||
font-size: 18px; | ||
text-align: center; | ||
} | ||
|
||
.answersList { | ||
display: grid; | ||
grid-template-rows: repeat(4, 1fr); | ||
row-gap: 8px; | ||
text-align: left; | ||
width: 100%; | ||
font-weight: 400; | ||
font-size: 14px; | ||
list-style-type: none; | ||
|
||
& > .answerListItem { | ||
counter-increment: list-counter; | ||
padding: 20px 24px; | ||
// background-color: c.$whiteColor; | ||
background-image: url("../../img/svg/Inactive.svg"); | ||
|
||
&.selected { | ||
background-image: url("../../img/svg/Selected.svg"); | ||
} | ||
|
||
&.correct { | ||
background-image: url("../../img/svg/Correct.svg"); | ||
} | ||
|
||
&.wrong { | ||
background-image: url("../../img/svg/Wrong.svg"); | ||
} | ||
|
||
&.disabled { | ||
pointer-events: none; | ||
} | ||
|
||
&::before { | ||
content: counter(list-counter, upper-latin) ""; | ||
margin-left: 24px; | ||
margin-right: 8px; | ||
color: c.$hoverStartButtonColor; | ||
font-weight: 600; | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -13,5 +13,4 @@ img { | |
display: block; | ||
height: auto; | ||
width: 100%; | ||
// height: calc((367px / 900px) * 100vh); | ||
} |
Oops, something went wrong.