Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deliverable v1.1: fixing bugs #357

Merged
merged 7 commits into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions questions/utils/question.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@
{
"property": "P3032",
"template": {
"es": "Cuál es la velocidad máxima de x",
"en": "What is the maximum speed of x",
"fr": "Quelle est la vitesse maximale de x"
"es": "Cuál es la mayor velocidad de x",
"en": "What is the greatest speed of x",
"fr": "Quelle est la vitesse plus grand de x"
},
"category": ["Cars"]
}
Expand Down
15 changes: 0 additions & 15 deletions webapp/src/__tests__/pages/games/WiseMenStackGame.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,21 +116,6 @@ describe('Wise Men Stack Game component', () => {

}, 4500);

it('should render pause & play buttons when answered', async () => {
await waitFor(() => screen.getByText('GAME CONFIGURATION'));
const button = screen.getByTestId('start-button');
fireEvent.click(button);

await waitFor(() => screen.getByText('Which is the capital of Spain?'.toUpperCase()));
const correctAnswer = screen.getByRole('button', { name: 'Madrid' });
fireEvent.click(correctAnswer);

const pauseButton = screen.getByTestId("pause");
expect(pauseButton);
fireEvent.click(pauseButton);
expect(screen.getByTestId("play"));
})

it('should render progress bar', async () => {
await waitFor(() => screen.getByText('GAME CONFIGURATION'));
const button = screen.getByTestId('start-button');
Expand Down
52 changes: 38 additions & 14 deletions webapp/src/pages/games/WiseMenStackGame.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const WiseMenStackGame = () => {
const [timerRunning, setTimerRunning] = React.useState(true); // indicate if the timer is working
const [showConfetti, setShowConfetti] = React.useState(false); //indicates if the confetti must appear
const [questionCountdownKey, ] = React.useState(60); //key to update question timer
const [targetTime, ] = React.useState(60);
const [questionCountdownRunning, setQuestionCountdownRunning] = React.useState(false); //property to start and stop question timer
const [userResponses, setUserResponses] = React.useState([]);
const [language, setCurrentLanguage] = React.useState(i18n.language);
Expand All @@ -64,19 +65,22 @@ const WiseMenStackGame = () => {

// hook to initiating new rounds if the current number of rounds is less than or equal to 3
React.useEffect(() => {
if (totalTimePlayed <= questionCountdownKey) {
if (totalTimePlayed <= targetTime) {
startNewRound();
setQuestionCountdownRunning(true);
} else {
setTimerRunning(false);
setShouldRedirect(true);
setQuestionCountdownRunning(false);
updateStatistics();
updateQuestionsRecord();
setQuestionCountdownRunning(true)
}
// eslint-disable-next-line
}, [round]);

const endGame = () => {
setTimerRunning(false);
setShouldRedirect(true);
setQuestionCountdownRunning(false);
updateStatistics();
updateQuestionsRecord();
// eslint-disable-next-line
}

// stablish if the confetti must show or not
React.useEffect(() => {
if (correctlyAnsweredQuestions > incorrectlyAnsweredQuestions) {
Expand Down Expand Up @@ -108,7 +112,7 @@ const WiseMenStackGame = () => {
setQuestionData(quest.data[0]);
setButtonStates(new Array(2).fill(null));
getPossibleOptions(quest.data[0]);

}).catch(error => {
console.error("Could not get questions", error);
});
Expand Down Expand Up @@ -139,10 +143,29 @@ const WiseMenStackGame = () => {
try {
await axios.put(`${apiEndpoint}/statistics`, {
username:username,
the_callenge_earned_money:0,
the_callenge_correctly_answered_questions:0,
the_callenge_incorrectly_answered_questions:0,
the_callenge_total_time_played:0,
the_callenge_games_played:0,
wise_men_stack_earned_money:totalScore,
wise_men_stack_correctly_answered_questions:correctlyAnsweredQuestions,
wise_men_stack_incorrectly_answered_questions:incorrectlyAnsweredQuestions,
wise_men_stack_games_played:1
wise_men_stack_games_played:1,
warm_question_earned_money: 0,
warm_question_correctly_answered_questions: 0,
warm_question_incorrectly_answered_questions: 0,
warm_question_passed_questions: 0,
warm_question_games_played: 0,
discovering_cities_earned_money: 0,
discovering_cities_correctly_answered_questions: 0,
discovering_cities_incorrectly_answered_questions: 0,
discovering_cities_games_played: 0,
online_earned_money: 0,
online_correctly_answered_questions: 0,
online_incorrectly_answered_questions: 0,
online_total_time_played: 0,
online_games_played: 0,
});
} catch (error) {
console.error("Error:", error);
Expand All @@ -163,6 +186,7 @@ const WiseMenStackGame = () => {

// this function is called when a user selects a response.
const selectResponse = async (index, response) => {
setQuestionCountdownRunning(false);
setAnswered(true);
const newButtonStates = [...buttonStates];

Expand All @@ -173,7 +197,7 @@ const WiseMenStackGame = () => {
const userResponse = {
question: questionData.question,
response: response,
options: questionData.options,
options: possibleAnswers,
correctAnswer: questionData.correctAnswer
};
setUserResponses(prevResponses => [...prevResponses, userResponse]);
Expand Down Expand Up @@ -313,7 +337,7 @@ const WiseMenStackGame = () => {
<CssBaseline />

<Container sx={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }} >
{ answered ?
{ false ?
// Pausa
<IconButton variant="contained" size="large" color="primary" aria-label={ paused ? t("Game.play") : t("Game.pause") }
onClick={() => togglePause()} sx={{ height: 100, width: 100, border: `2px solid ${theme.palette.primary.main}` }}
Expand All @@ -322,8 +346,8 @@ const WiseMenStackGame = () => {
</IconButton>
:
// Cronómetro
<CountdownCircleTimer data-testid="circleTimer" key={questionCountdownKey} isPlaying = {questionCountdownRunning} duration={15} colorsTime={[10, 6, 3, 0]}
colors={[theme.palette.success.main, "#F7B801", "#f50707", theme.palette.error.main]} size={100} onComplete={() => selectResponse(-1, "FAILED")}>
<CountdownCircleTimer data-testid="circleTimer" key={questionCountdownKey} isPlaying = {questionCountdownRunning} duration={targetTime} colorsTime={[10, 6, 3, 0]}
colors={[theme.palette.success.main, "#F7B801", "#f50707", theme.palette.error.main]} size={100} onComplete={() => endGame()}>
{({ remainingTime }) => {
return (
<Box style={{ display: 'flex', alignItems: 'center' }}>
Expand Down